Skip to content

Commit ef244ef

Browse files
test: cover a deferred member of an errored async cycle
Reaching a cycle member through a deferred namespace after a peer has already failed is a different path from importing a fulfilled one: the deferred import gathers the component's async dependencies, so both it and the namespace access must report the recorded error. Before the fix this handed back the member's exports instead.
1 parent 4969b7a commit ef244ef

6 files changed

Lines changed: 50 additions & 0 deletions

File tree

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import "./c.js";
2+
await Promise.resolve(0);
3+
export const a = "a";
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import "./a.js";
2+
await Promise.resolve(0);
3+
throw new Error("async error in B");
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import "./b.js";
2+
await Promise.resolve(0);
3+
export const c = "c";
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import defer * as ns from "./c.js";
2+
3+
export const readC = () => ns.c;
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
it("should throw the cycle's evaluation error from a deferred member reached afterwards", async () => {
2+
// The component records one `[[EvaluationError]]`, so reaching C through a
3+
// deferred namespace after B failed must report it instead of C's exports.
4+
let errorFromB = null;
5+
try {
6+
await import("./b.js");
7+
} catch (err) {
8+
errorFromB = err;
9+
}
10+
expect(errorFromB).toBeInstanceOf(Error);
11+
expect(errorFromB.message).toBe("async error in B");
12+
13+
// Deferring an async module still gathers its async dependencies, so both
14+
// the import and the namespace access can carry the component's error.
15+
let errorFromDeferred = null;
16+
try {
17+
const { readC } = await import("./deferred.js");
18+
readC();
19+
} catch (err) {
20+
errorFromDeferred = err;
21+
}
22+
expect(errorFromDeferred).toBe(errorFromB);
23+
});
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
"use strict";
2+
3+
/** @type {import("../../../../").Configuration} */
4+
module.exports = {
5+
mode: "development",
6+
devtool: false,
7+
target: "node",
8+
output: {
9+
strictModuleErrorHandling: true
10+
},
11+
experiments: {
12+
topLevelAwait: true,
13+
deferImport: true
14+
}
15+
};

0 commit comments

Comments
 (0)