-
Notifications
You must be signed in to change notification settings - Fork 29.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
33165b5
commit 8566dea
Showing
1 changed file
with
28 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
// Flags: --experimental-require-module | ||
'use strict'; | ||
const common = require('../common'); | ||
const assert = require('assert'); | ||
|
||
// This test demonstrates interop between CJS and CJS represented as ESM | ||
// under the `__cjsModule` pattern. | ||
(async () => { | ||
// dep.js and index.js are CJS modules. | ||
// dep exports 'cjs', while index reexports dep: | ||
assert.strictEqual(require('../fixtures/cjsesm/dep.js'), 'cjs'); | ||
assert.strictEqual(require('../fixtures/cjsesm/index.js'), 'cjs'); | ||
|
||
// Now we have ESM conversions of these dependencies, using __cjsModule, | ||
// that behave equivalently under require(esm) despite the custom string import: | ||
assert.strictEqual(require('../fixtures/cjsesm/dep.mjs'), 'cjs'); | ||
assert.strictEqual(require('../fixtures/cjsesm/index.mjs'), 'cjs'); | ||
|
||
// Furthermore, if `index.mjs` imports from `dep.mjs` directly, the reexport | ||
// still works: | ||
assert.strictEqual(require('../fixtures/cjsesm/index-importing-depmjs.mjs'), 'cjs'); | ||
|
||
// Finally, the ESM representations under these conversions all match equivalently: | ||
const esmCjsImport = await import('../fixtures/cjsesm/index.js'); | ||
|
||
assert.deepStrictEqual(await import('../fixtures/cjsesm/index.mjs'), esmCjsImport); | ||
assert.deepStrictEqual(await import('../fixtures/cjsesm/index-importing-depmjs.mjs'), esmCjsImport); | ||
})().then(common.mustCall()); |