-
Notifications
You must be signed in to change notification settings - Fork 30.3k
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 f414613
Showing
5 changed files
with
75 additions
and
0 deletions.
There are no files selected for viewing
71 changes: 71 additions & 0 deletions
71
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,71 @@ | ||
'use strict'; | ||
|
||
require('../common'); | ||
const { spawnSyncAndAssert } = require('../common/child_process'); | ||
const fixtures = require('../common/fixtures'); | ||
const assert = require('assert'); | ||
|
||
// 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' |