Skip to content

Commit a656ab1

Browse files
authored
test: add self-import test case for dynamic import (#20389)
1 parent 8056413 commit a656ab1

File tree

4 files changed

+75
-0
lines changed

4 files changed

+75
-0
lines changed
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
it("should allow to import itself", async () => {
2+
// Dynamic import with self-import (e.g., import(import.meta.url)) does not create duplicate ChunkGroups
3+
// because the module is already in parent chunks, so it enters the skip logic at buildChunkGraph.js:734-738
4+
// (isOrdinalSetInMask check returns true).
5+
const module = await import(import.meta.url);
6+
expect(module).toBeDefined();
7+
});
8+
9+
it("should allow to import itself with new URL", async (done) => {
10+
import(new URL(import.meta.url)).catch(e => {
11+
// import with new URL will create a ContextModule with critical flag
12+
// ContextModule will throw MODULE_NOT_FOUND
13+
expect(e.code).toBe("MODULE_NOT_FOUND");
14+
done();
15+
});
16+
});
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
"use strict";
2+
3+
module.exports = {
4+
findBundle(i) {
5+
switch (i) {
6+
case 0:
7+
return [`bundle${i}.js`];
8+
case 1:
9+
return [`runtime.bundle${i}.js`, `main.bundle${i}.js`];
10+
case 2:
11+
return [`bundle${i}.mjs`];
12+
case 3:
13+
return [`runtime.bundle${i}.mjs`, `main.bundle${i}.mjs`];
14+
}
15+
}
16+
};
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
"use strict";
2+
3+
module.exports = [
4+
/Critical dependency: the request of a dependency is an expression/,
5+
/Critical dependency: the request of a dependency is an expression/,
6+
/Critical dependency: the request of a dependency is an expression/,
7+
/Critical dependency: the request of a dependency is an expression/
8+
];
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
"use strict";
2+
3+
/** @type {import("../../../../").Configuration[]} */
4+
module.exports = [
5+
{
6+
target: "web"
7+
},
8+
{
9+
output: {
10+
filename: "[name].bundle1.js"
11+
},
12+
target: "web",
13+
optimization: {
14+
runtimeChunk: "single"
15+
}
16+
},
17+
{
18+
target: "web",
19+
experiments: {
20+
outputModule: true
21+
}
22+
},
23+
{
24+
target: "web",
25+
output: {
26+
filename: "[name].bundle3.mjs"
27+
},
28+
optimization: {
29+
runtimeChunk: "single"
30+
},
31+
experiments: {
32+
outputModule: true
33+
}
34+
}
35+
];

0 commit comments

Comments
 (0)