Skip to content

Commit

Permalink
lint fix
Browse files Browse the repository at this point in the history
  • Loading branch information
guybedford committed Jul 28, 2024
1 parent 33165b5 commit 8566dea
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions test/es-module/test-require-import-interop.js
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());

0 comments on commit 8566dea

Please sign in to comment.