-
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: disallow CJS <-> ESM edges in a cycle from require(esm)
- Loading branch information
1 parent
dc62194
commit 971affd
Showing
5 changed files
with
74 additions
and
0 deletions.
There are no files selected for viewing
70 changes: 70 additions & 0 deletions
70
test/es-module/test-require-module-cycle-esm-esm-cjs-esm-esm.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,70 @@ | ||
'use strict'; | ||
|
||
require('../common'); | ||
const { spawnSyncAndAssert } = require('../common/child_process'); | ||
const fixtures = require('../common/fixtures'); | ||
|
||
// a.mjs -> b.mjs -> c.cjs -> z.mjs -> a.mjs | ||
{ | ||
spawnSyncAndAssert( | ||
process.execPath, | ||
[ | ||
'--experimental-require-module', | ||
fixtures.path('es-modules/esm-esm-cjs-esm-esm-cycle/a.mjs'), | ||
], | ||
{ | ||
signal: null, | ||
status: 1, | ||
stderr: /Cannot import Module \.\/a\.mjs in a cycle\. \(from .*z\.mjs\)/, | ||
} | ||
); | ||
} | ||
|
||
// b.mjs -> c.cjs -> z.mjs -> a.mjs -> b.mjs | ||
{ | ||
spawnSyncAndAssert( | ||
process.execPath, | ||
[ | ||
'--experimental-require-module', | ||
fixtures.path('es-modules/esm-esm-cjs-esm-esm-cycle/b.mjs'), | ||
], | ||
{ | ||
signal: null, | ||
status: 1, | ||
stderr: /Cannot import Module \.\/b\.mjs in a cycle\. \(from .*a\.mjs\)/, | ||
} | ||
); | ||
} | ||
|
||
// c.cjs -> z.mjs -> a.mjs -> b.mjs -> c.cjs | ||
{ | ||
spawnSyncAndAssert( | ||
process.execPath, | ||
[ | ||
'--experimental-require-module', | ||
fixtures.path('es-modules/esm-esm-cjs-esm-esm-cycle/c.cjs'), | ||
], | ||
{ | ||
signal: null, | ||
status: 1, | ||
stderr: /Cannot import CommonJS Module \.\/c\.cjs in a cycle\. \(from .*b\.mjs\)/, | ||
} | ||
); | ||
} | ||
|
||
|
||
// z.mjs -> a.mjs -> b.mjs -> c.cjs -> z.mjs | ||
{ | ||
spawnSyncAndAssert( | ||
process.execPath, | ||
[ | ||
'--experimental-require-module', | ||
fixtures.path('es-modules/esm-esm-cjs-esm-esm-cycle/z.mjs'), | ||
], | ||
{ | ||
signal: null, | ||
status: 1, | ||
stderr: /Cannot require\(\) ES Module .*z\.mjs in a cycle\. \(from .*c\.cjs\)/, | ||
} | ||
); | ||
} |
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 @@ | ||
import './b.mjs' |
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 @@ | ||
import './c.cjs' |
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 @@ | ||
require('./z.mjs') |
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 @@ | ||
import './a.mjs' |