-
Notifications
You must be signed in to change notification settings - Fork 30.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
module: improve error message from asynchronicity in require(esm)
- Improve the error message that shows up when there is a race from doing require(esm) and import(esm) at the same time. - Improve error message of ERR_REQUIRE_ASYNC_MODULE by showing parent and target file names, if available. Drive-by: split the require(tla) tests since we are modifying the tests already. PR-URL: #57126 Refs: https://github.com/fisker/prettier-issue-17139 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Antoine du Hamel <[email protected]> Reviewed-By: Chengzhong Wu <[email protected]>
- Loading branch information
1 parent
90a4de0
commit ad3c572
Showing
13 changed files
with
189 additions
and
78 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
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
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
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
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
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
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,26 @@ | ||
'use strict'; | ||
|
||
// Tests that require(esm) with top-level-await throws before execution starts | ||
// if --experimental-print-required-tla is not enabled. | ||
|
||
const common = require('../common'); | ||
const assert = require('assert'); | ||
const { spawnSyncAndExit } = require('../common/child_process'); | ||
const fixtures = require('../common/fixtures'); | ||
|
||
{ | ||
spawnSyncAndExit(process.execPath, [ | ||
fixtures.path('es-modules/tla/require-execution.js'), | ||
], { | ||
signal: null, | ||
status: 1, | ||
stderr(output) { | ||
assert.doesNotMatch(output, /I am executed/); | ||
common.expectRequiredTLAError(output); | ||
assert.match(output, /From .*require-execution\.js/); | ||
assert.match(output, /Requiring .*execution\.mjs/); | ||
return true; | ||
}, | ||
stdout: '' | ||
}); | ||
} |
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,15 @@ | ||
'use strict'; | ||
|
||
// Tests that require(esm) throws for top-level-await in inner graphs. | ||
|
||
const common = require('../common'); | ||
const assert = require('assert'); | ||
|
||
assert.throws(() => { | ||
require('../fixtures/es-modules/tla/parent.mjs'); | ||
}, (err) => { | ||
common.expectRequiredTLAError(err); | ||
assert.match(err.message, /From .*test-require-module-tla-nested\.js/); | ||
assert.match(err.message, /Requiring .*parent\.mjs/); | ||
return true; | ||
}); |
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,29 @@ | ||
'use strict'; | ||
|
||
// Tests that require(esm) with top-level-await throws after execution | ||
// if --experimental-print-required-tla is enabled. | ||
|
||
const common = require('../common'); | ||
const assert = require('assert'); | ||
const { spawnSyncAndExit } = require('../common/child_process'); | ||
const fixtures = require('../common/fixtures'); | ||
|
||
{ | ||
spawnSyncAndExit(process.execPath, [ | ||
'--experimental-print-required-tla', | ||
fixtures.path('es-modules/tla/require-execution.js'), | ||
], { | ||
signal: null, | ||
status: 1, | ||
stderr(output) { | ||
assert.match(output, /I am executed/); | ||
common.expectRequiredTLAError(output); | ||
assert.match(output, /Error: unexpected top-level await at.*execution\.mjs:3/); | ||
assert.match(output, /await Promise\.resolve\('hi'\)/); | ||
assert.match(output, /From .*require-execution\.js/); | ||
assert.match(output, /Requiring .*execution\.mjs/); | ||
return true; | ||
}, | ||
stdout: '' | ||
}); | ||
} |
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,15 @@ | ||
'use strict'; | ||
|
||
// Tests that require(esm) throws for rejected top-level await. | ||
|
||
const common = require('../common'); | ||
const assert = require('assert'); | ||
|
||
assert.throws(() => { | ||
require('../fixtures/es-modules/tla/rejected.mjs'); | ||
}, (err) => { | ||
common.expectRequiredTLAError(err); | ||
assert.match(err.message, /From .*test-require-module-tla-rejected\.js/); | ||
assert.match(err.message, /Requiring .*rejected\.mjs/); | ||
return true; | ||
}); |
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,15 @@ | ||
'use strict'; | ||
|
||
// Tests that require(esm) throws for resolved top-level-await. | ||
|
||
const common = require('../common'); | ||
const assert = require('assert'); | ||
|
||
assert.throws(() => { | ||
require('../fixtures/es-modules/tla/resolved.mjs'); | ||
}, (err) => { | ||
common.expectRequiredTLAError(err); | ||
assert.match(err.message, /From .*test-require-module-tla-resolved\.js/); | ||
assert.match(err.message, /Requiring .*resolved\.mjs/); | ||
return true; | ||
}); |
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,15 @@ | ||
'use strict'; | ||
|
||
// Tests that require(esm) throws for unresolved top-level-await. | ||
|
||
const common = require('../common'); | ||
const assert = require('assert'); | ||
|
||
assert.throws(() => { | ||
require('../fixtures/es-modules/tla/unresolved.mjs'); | ||
}, (err) => { | ||
common.expectRequiredTLAError(err); | ||
assert.match(err.message, /From .*test-require-module-tla-unresolved\.js/); | ||
assert.match(err.message, /Requiring .*unresolved\.mjs/); | ||
return true; | ||
}); |
This file was deleted.
Oops, something went wrong.