-
Notifications
You must be signed in to change notification settings - Fork 30.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fixup! module: allow ESM that failed to be required to be re-imported
- Loading branch information
1 parent
bbd4cb4
commit b0c551c
Showing
5 changed files
with
87 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
test/es-module/test-require-module-retry-import-errored.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
// This tests that after failing to require an ESM that contains TLA, | ||
// retrying with import() still works, and produces consistent results. | ||
'use strict'; | ||
const common = require('../common'); | ||
const assert = require('assert'); | ||
|
||
const { exportedReject } = require('../fixtures/es-modules/tla/export-promise.mjs'); | ||
|
||
assert.throws(() => { | ||
require('../fixtures/es-modules/tla/await-export-promise.mjs'); | ||
}, { | ||
code: 'ERR_REQUIRE_ASYNC_MODULE' | ||
}); | ||
|
||
const interval = setInterval(() => {}, 1000); // Keep the test running, because await alone doesn't. | ||
const err = new Error('rejected'); | ||
|
||
const p1 = import('../fixtures/es-modules/tla/await-export-promise.mjs') | ||
.then(common.mustNotCall(), common.mustCall((e) => { | ||
assert.strictEqual(e, err); | ||
})); | ||
|
||
const p2 = import('../fixtures/es-modules/tla/await-export-promise.mjs') | ||
.then(common.mustNotCall(), common.mustCall((e) => { | ||
assert.strictEqual(e, err); | ||
})); | ||
|
||
const p3 = import('../fixtures/es-modules/tla/await-export-promise.mjs') | ||
.then(common.mustNotCall(), common.mustCall((e) => { | ||
assert.strictEqual(e, err); | ||
})); | ||
|
||
exportedReject(err); | ||
|
||
Promise.all([p1, p2, p3]).then(common.mustCall(() => { clearInterval(interval); })); |
32 changes: 32 additions & 0 deletions
32
test/es-module/test-require-module-retry-import-evaluating.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
// This tests that after failing to require an ESM that contains TLA, | ||
// retrying with import() still works, and produces consistent results. | ||
'use strict'; | ||
const common = require('../common'); | ||
const assert = require('assert'); | ||
|
||
const { exportedResolve } = require('../fixtures/es-modules/tla/export-promise.mjs'); | ||
|
||
assert.throws(() => { | ||
require('../fixtures/es-modules/tla/await-export-promise.mjs'); | ||
}, { | ||
code: 'ERR_REQUIRE_ASYNC_MODULE' | ||
}); | ||
|
||
const interval = setInterval(() => {}, 1000); // Keep the test running, because await alone doesn't. | ||
const value = { hello: 'world' }; | ||
|
||
const p1 = import('../fixtures/es-modules/tla/await-export-promise.mjs').then(common.mustCall((ns) => { | ||
assert.strictEqual(ns.default, value); | ||
}), common.mustNotCall()); | ||
|
||
const p2 = import('../fixtures/es-modules/tla/await-export-promise.mjs').then(common.mustCall((ns) => { | ||
assert.strictEqual(ns.default, value); | ||
}), common.mustNotCall()); | ||
|
||
const p3 = import('../fixtures/es-modules/tla/await-export-promise.mjs').then(common.mustCall((ns) => { | ||
assert.strictEqual(ns.default, value); | ||
}), common.mustNotCall()); | ||
|
||
exportedResolve(value); | ||
|
||
Promise.all([p1, p2, p3]).then(common.mustCall(() => { clearInterval(interval); })); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import promise from './export-promise.mjs'; | ||
let result; | ||
result = await promise; | ||
export default result; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
let exportedResolve; | ||
let exportedReject; | ||
const promise = new Promise((resolve, reject) => { | ||
exportedResolve = resolve; | ||
exportedReject = reject; | ||
}); | ||
export default promise; | ||
export { exportedResolve, exportedReject }; |