Skip to content

Commit 22c5f82

Browse files
committed
test: should wait until async startup chunk dependencies ended
1 parent f9ec681 commit 22c5f82

File tree

1 file changed

+20
-0
lines changed
  • packages/rspack-test-tools/src/runner/node

1 file changed

+20
-0
lines changed

packages/rspack-test-tools/src/runner/node/index.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,9 @@ export class NodeRunner implements ITestRunner {
9292
? file
9393
: `./${file}`
9494
);
95+
if (this.globalContext!.WAITING.length) {
96+
return Promise.all(this.globalContext!.WAITING).then(() => res);
97+
}
9598
if (typeof res === "object" && "then" in res) {
9699
return res;
97100
}
@@ -162,6 +165,7 @@ export class NodeRunner implements ITestRunner {
162165
console.clear();
163166
}
164167
},
168+
WAITING: [],
165169
setTimeout: ((
166170
cb: (...args: any[]) => void,
167171
ms: number | undefined,
@@ -185,6 +189,7 @@ export class NodeRunner implements ITestRunner {
185189
});
186190
return m;
187191
},
192+
WAITING: this.globalContext!.WAITING,
188193
process,
189194
URL,
190195
Blob,
@@ -396,6 +401,21 @@ export class NodeRunner implements ITestRunner {
396401
currentModuleScope.__STATS_I__ = statsIndex;
397402
}
398403
}
404+
if (file.content.includes("webpack/runtime/startup_chunk_dependencies")) {
405+
currentModuleScope.__AFTER_CHUNK_LOADED__ = (next: () => void) => {
406+
let done;
407+
const task = new Promise(resolve => (done = resolve));
408+
currentModuleScope.WAITING.push(task);
409+
return () => {
410+
next();
411+
done!();
412+
};
413+
};
414+
file.content = file.content.replace(
415+
"var next = __webpack_require__.x",
416+
"var next = __AFTER_CHUNK_LOADED__(__webpack_require__.x)"
417+
);
418+
}
399419
const args = Object.keys(currentModuleScope);
400420
const argValues = args.map(arg => currentModuleScope[arg]);
401421
const code = `(function(${args.join(", ")}) {

0 commit comments

Comments
 (0)