diff --git a/packages/compat/src/http-audit.ts b/packages/compat/src/http-audit.ts index a16d25452..062503c54 100644 --- a/packages/compat/src/http-audit.ts +++ b/packages/compat/src/http-audit.ts @@ -21,6 +21,9 @@ export async function httpAudit( let response = await (options.fetch ?? globalThis.fetch)(id); let content = await response.text(); let type: ContentType; + if (response.status !== 200) { + throw new Error(`oops status code ${response.status} - ${response.statusText} for ${id}: ${content}`); + } switch (response.headers.get('content-type')) { case 'text/javascript': type = 'javascript'; @@ -29,7 +32,7 @@ export async function httpAudit( type = 'html'; break; default: - throw new Error(`oops content type ${response.headers.get('content-type')}`); + throw new Error(`oops content type ${response.headers.get('content-type')} for ${id}`); } return { content, type }; } diff --git a/test-packages/support/audit-assertions.ts b/test-packages/support/audit-assertions.ts index f79fb825d..cb7d1268c 100644 --- a/test-packages/support/audit-assertions.ts +++ b/test-packages/support/audit-assertions.ts @@ -9,6 +9,8 @@ import { distance } from 'fastest-levenshtein'; import { sortBy } from 'lodash'; import { getRewrittenLocation } from './rewritten-path'; +export { Import }; + /* The audit tool in @embroider/compat can be used directly to tell you about potential problems in an app that is trying to adopt embroider. But we also @@ -19,17 +21,16 @@ export function setupAuditTest(hooks: NestedHooks, opts: () => AuditBuildOptions let result: { modules: { [file: string]: Module }; findings: Finding[] }; let expectAudit: ExpectAuditResults; - hooks.before(async () => { + async function visit() { let o = opts(); if ('appURL' in o) { result = await httpAudit(o); } else { result = await Audit.run(o); } - }); + } - hooks.beforeEach(assert => { - installAuditAssertions(assert); + function prepareResult(assert: Assert) { let o = opts(); let pathRewriter: (p: string) => string; if ('appURL' in o) { @@ -38,15 +39,31 @@ export function setupAuditTest(hooks: NestedHooks, opts: () => AuditBuildOptions pathRewriter = p => getRewrittenLocation(o.app, p); } expectAudit = new ExpectAuditResults(result, assert, pathRewriter); + } + + hooks.before(async () => { + await visit(); + }); + + hooks.beforeEach(assert => { + installAuditAssertions(assert); + prepareResult(assert); }); return { + async rerun() { + await visit(); + prepareResult(expectAudit.assert); + }, module(name: string) { return expectAudit.module(name); }, get findings() { return expectAudit.findings; }, + get modules() { + return expectAudit.result.modules; + }, hasNoFindings() { return expectAudit.hasNoProblems(); }, diff --git a/tests/scenarios/helpers/command-watcher.ts b/tests/scenarios/helpers/command-watcher.ts index 5cb778f95..ca9d145eb 100644 --- a/tests/scenarios/helpers/command-watcher.ts +++ b/tests/scenarios/helpers/command-watcher.ts @@ -108,7 +108,7 @@ export default class CommandWatcher { return; } - this.process.kill(); + this.process.kill('SIGINT'); // on windows the subprocess won't close if you don't end all the sockets // we don't just end stdout because when you register a listener for stdout it auto registers stdin and stderr... for some reason :(