Skip to content

Commit

Permalink
test: asserts all reports have been yielded at the end of tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jean-michelet committed Apr 12, 2024
1 parent 83b4db4 commit 5a3772a
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions test/EntryFilesAnalyser.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ describe("EntryFilesAnalyser", () => {
await assertReport(generator, deepEntryUrl, true);
await assertReport(generator, new URL("deps/dep3.js", FIXTURE_URL), true);

await assertAllReportsYielded(generator);

// Check that shared dependencies are not analyzed several times
const calls = AstAnalyser.prototype.analyseFile.mock.calls;
assert.strictEqual(calls.length, 6);
Expand All @@ -46,6 +48,9 @@ describe("EntryFilesAnalyser", () => {
assert.strictEqual(invalidDepReport.value.warnings[0].kind, "parsing-error");

await assertReport(generator, new URL("deps/dep1.js", FIXTURE_URL), true);
await assertReport(generator, new URL("shared.js", FIXTURE_URL), true);

await assertAllReportsYielded(generator);
});

it("should extends default extensions", async() => {
Expand All @@ -62,7 +67,7 @@ describe("EntryFilesAnalyser", () => {
await assertReport(generator, new URL("deps/default.node", FIXTURE_URL), true);
await assertReport(generator, new URL("deps/default.jsx", FIXTURE_URL), true);

assert.strictEqual((await generator.next()).value, undefined);
await assertAllReportsYielded(generator);
});

it("should override default extensions", async() => {
Expand All @@ -75,12 +80,16 @@ describe("EntryFilesAnalyser", () => {
await assertReport(generator, entryUrl, true);
await assertReport(generator, new URL("deps/default.jsx", FIXTURE_URL), true);

assert.strictEqual((await generator.next()).value, undefined);
await assertAllReportsYielded(generator);
});

async function assertReport(generator, expectedUrl, expectedOk) {
const report = await generator.next();
assert.strictEqual(report.value.url, expectedUrl.pathname);
assert.strictEqual(report.value.ok, expectedOk);
}

async function assertAllReportsYielded(generator) {
assert.strictEqual((await generator.next()).value, undefined);
}
});

0 comments on commit 5a3772a

Please sign in to comment.