Skip to content

Commit

Permalink
Merge pull request #1919 from patricklx/improve-audit
Browse files Browse the repository at this point in the history
improve audit tests
  • Loading branch information
ef4 committed May 16, 2024
2 parents 51043f4 + d842782 commit 3beedad
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 6 deletions.
5 changes: 4 additions & 1 deletion packages/compat/src/http-audit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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 };
}
Expand Down
25 changes: 21 additions & 4 deletions test-packages/support/audit-assertions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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) {
Expand All @@ -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();
},
Expand Down
2 changes: 1 addition & 1 deletion tests/scenarios/helpers/command-watcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 :(
Expand Down

0 comments on commit 3beedad

Please sign in to comment.