diff --git a/test/es-module/test-esm-package-scope.mjs b/test/es-module/test-esm-package-scope.mjs new file mode 100644 index 0000000000..47b608cd0a --- /dev/null +++ b/test/es-module/test-esm-package-scope.mjs @@ -0,0 +1,11 @@ +// Flags: --experimental-modules +/* eslint-disable node-core/required-modules */ + +import '../common/index.mjs'; +import assert from 'assert'; + +import legacyLoader from '../fixtures/esm-package-scope/legacy-loader/index.mjs'; +import newLoader from '../fixtures/esm-package-scope/new-loader/index.js'; + +assert.strictEqual(legacyLoader, 'legacy-loader'); +assert.strictEqual(newLoader, 'new-loader'); diff --git a/test/fixtures/esm-package-scope/legacy-loader/a.js b/test/fixtures/esm-package-scope/legacy-loader/a.js new file mode 100644 index 0000000000..2e7700bc63 --- /dev/null +++ b/test/fixtures/esm-package-scope/legacy-loader/a.js @@ -0,0 +1 @@ +module.exports = 'a'; diff --git a/test/fixtures/esm-package-scope/legacy-loader/b.mjs b/test/fixtures/esm-package-scope/legacy-loader/b.mjs new file mode 100644 index 0000000000..137b8ce642 --- /dev/null +++ b/test/fixtures/esm-package-scope/legacy-loader/b.mjs @@ -0,0 +1 @@ +export const b = 'b'; diff --git a/test/fixtures/esm-package-scope/legacy-loader/c.cjs b/test/fixtures/esm-package-scope/legacy-loader/c.cjs new file mode 100644 index 0000000000..2d5312952f --- /dev/null +++ b/test/fixtures/esm-package-scope/legacy-loader/c.cjs @@ -0,0 +1,5 @@ +module.exports = { + one: 1, + two: 2, + three: 3 +}; diff --git a/test/fixtures/esm-package-scope/legacy-loader/index.mjs b/test/fixtures/esm-package-scope/legacy-loader/index.mjs new file mode 100644 index 0000000000..1c78c389a2 --- /dev/null +++ b/test/fixtures/esm-package-scope/legacy-loader/index.mjs @@ -0,0 +1,21 @@ +// js file that is common.js +import a from './a.js'; +// ESM with named export +import {b} from './b.mjs'; +// import 'c.cjs'; +import cjs from './c.cjs'; +// proves cross boundary fun bits +import jsAsEsm from '../new-loader/a.js'; + +// named export from core +import {strictEqual, deepStrictEqual} from 'assert'; + +strictEqual(a, jsAsEsm); +strictEqual(b, 'b'); +deepStrictEqual(cjs, { + one: 1, + two: 2, + three: 3 +}); + +export default 'legacy-loader'; diff --git a/test/fixtures/esm-package-scope/legacy-loader/package.json b/test/fixtures/esm-package-scope/legacy-loader/package.json new file mode 100644 index 0000000000..215a962248 --- /dev/null +++ b/test/fixtures/esm-package-scope/legacy-loader/package.json @@ -0,0 +1,13 @@ +{ + "name": "legacy-loader", + "version": "1.0.0", + "description": "", + "main": "index.js", + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + }, + "keywords": [], + "author": "Myles Borins ", + "license": "Apache-2.0", + "type": "commonjs" +} diff --git a/test/fixtures/esm-package-scope/new-loader/a.js b/test/fixtures/esm-package-scope/new-loader/a.js new file mode 100644 index 0000000000..90bd54cd7f --- /dev/null +++ b/test/fixtures/esm-package-scope/new-loader/a.js @@ -0,0 +1 @@ +export default 'a' diff --git a/test/fixtures/esm-package-scope/new-loader/b.mjs b/test/fixtures/esm-package-scope/new-loader/b.mjs new file mode 100644 index 0000000000..137b8ce642 --- /dev/null +++ b/test/fixtures/esm-package-scope/new-loader/b.mjs @@ -0,0 +1 @@ +export const b = 'b'; diff --git a/test/fixtures/esm-package-scope/new-loader/c.cjs b/test/fixtures/esm-package-scope/new-loader/c.cjs new file mode 100644 index 0000000000..2d5312952f --- /dev/null +++ b/test/fixtures/esm-package-scope/new-loader/c.cjs @@ -0,0 +1,5 @@ +module.exports = { + one: 1, + two: 2, + three: 3 +}; diff --git a/test/fixtures/esm-package-scope/new-loader/index.js b/test/fixtures/esm-package-scope/new-loader/index.js new file mode 100644 index 0000000000..98c536cc34 --- /dev/null +++ b/test/fixtures/esm-package-scope/new-loader/index.js @@ -0,0 +1,21 @@ +// ESM with only default +import a from './a.js'; +// ESM with named export +import {b} from './b.mjs'; +// import 'c.cjs'; +import cjs from './c.cjs'; +// import across boundaries +import jsAsCjs from '../legacy-loader/a.js' + +// named export from core +import {strictEqual, deepStrictEqual} from 'assert'; + +strictEqual(a, jsAsCjs); +strictEqual(b, 'b'); +deepStrictEqual(cjs, { + one: 1, + two: 2, + three: 3 +}); + +export default 'new-loader'; diff --git a/test/fixtures/esm-package-scope/new-loader/package.json b/test/fixtures/esm-package-scope/new-loader/package.json new file mode 100644 index 0000000000..1f2c704322 --- /dev/null +++ b/test/fixtures/esm-package-scope/new-loader/package.json @@ -0,0 +1,13 @@ +{ + "name": "new-loader", + "version": "1.0.0", + "description": "", + "main": "index.js", + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + }, + "keywords": [], + "author": "Myles Borins ", + "license": "Apache-2.0", + "type": "module" +}