Skip to content

Commit c39c373

Browse files
test: read the chunk names inside the loader's map
A name matched anywhere in the chunk let a test pass while the map itself was missing the entry the loader indexes, so scope both checks to the map region and name the deferred context's sync candidate alongside its async one.
1 parent f7c40dd commit c39c373

2 files changed

Lines changed: 9 additions & 4 deletions

File tree

‎test/configCases/analyzable/circular-chunk-hashes-repaired/index.js‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,14 @@ it("should name a mutually importing pair from one place", () => {
2828
expect(read("b_js").match(CHUNK_REFERENCE)).toBe(null);
2929

3030
const bundle = read("bundle0");
31+
const start = bundle.indexOf(`${"chunkImports"} = {`);
32+
33+
expect(start).not.toBe(-1);
34+
// Read inside the map, so a name cannot be matched from anywhere else in the chunk.
35+
const region = bundle.slice(start, bundle.indexOf("};", start));
3136

32-
expect(bundle).toContain(`${"chunkImports"} = {`);
3337
for (const prefix of ["a_js", "b_js", "c_js"]) {
34-
expect(bundle).toContain(`"./${emitted(prefix)}"`);
38+
expect(region).toContain(`"./${emitted(prefix)}"`);
3539
}
3640
});
3741

‎test/configCases/analyzable/context-module/defer-entry.js‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,9 @@ it("should keep the loaders ahead of the deferred slot", () => {
2222

2323
expect(region.split("import(")).toHaveLength(3);
2424
expect(bundle).toContain(`return ${"__webpack_require__"}.e(ids[1][0])`);
25-
// An async candidate defers nothing, so its trailing slot is written out empty.
26-
expect(bundle).toContain(`import("./${__NAME__}-defer_async_js.mjs")`);
25+
// Both candidates are named, whether or not the deferred slot behind them is empty.
26+
expect(region).toContain(`import("./${__NAME__}-defer_async_js.mjs")`);
27+
expect(region).toContain(`import("./${__NAME__}-defer_sync_js.mjs")`);
2728
expect(bundle).toContain("], null]");
2829
expect(bundle).toContain(`${"__webpack_require__"}.e =`);
2930
});

0 commit comments

Comments
 (0)