-
-
Notifications
You must be signed in to change notification settings - Fork 33.9k
esm: improve performance & tidy tests #43784
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
03d1f1d
esm: tidy tests
JakobJingleheimer 24157ab
switch to node:test
JakobJingleheimer a53214b
move `spawnAsPromised` to test/common as `spawnPromisified`
JakobJingleheimer e9fcef0
tidy shouldIncludeNote
JakobJingleheimer 41980ee
replaceAll regex → string
JakobJingleheimer d7a2541
REPL done()
JakobJingleheimer 3d02b2f
`spawnAsync` → `spawn`
JakobJingleheimer aa67d37
`concurrently` → `concurrency`
JakobJingleheimer d9c320f
strings to regexes
JakobJingleheimer 120cc6a
fileURLs
JakobJingleheimer 5e4db68
explicitly disable `concurrency` for `test-esm-loader-http-imports.mjs`
JakobJingleheimer 0fcb833
Merge branch 'esm/tidy-esm-tests' of github.com:JakobJingleheimer/nod…
JakobJingleheimer a5897d5
.
JakobJingleheimer 11c0019
windows path BS
JakobJingleheimer 64bf333
remove superfluous characters from err match
JakobJingleheimer File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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 |
|---|---|---|
| @@ -1,64 +1,68 @@ | ||
| 'use strict'; | ||
|
|
||
| const common = require('../common'); | ||
| const fixtures = require('../common/fixtures'); | ||
| const { spawn } = require('child_process'); | ||
| const assert = require('assert'); | ||
| const path = require('path'); | ||
| const { spawnPromisified } = require('../common'); | ||
| const fixtures = require('../common/fixtures.js'); | ||
| const assert = require('node:assert'); | ||
| const path = require('node:path'); | ||
| const { execPath } = require('node:process'); | ||
| const { describe, it } = require('node:test'); | ||
|
|
||
|
|
||
| const requiringCjsAsEsm = path.resolve(fixtures.path('/es-modules/cjs-esm.js')); | ||
| const requiringEsm = path.resolve(fixtures.path('/es-modules/cjs-esm-esm.js')); | ||
| const pjson = path.resolve( | ||
| fixtures.path('/es-modules/package-type-module/package.json') | ||
| ); | ||
|
|
||
| { | ||
| const required = path.resolve( | ||
| fixtures.path('/es-modules/package-type-module/cjs.js') | ||
| ); | ||
| const basename = 'cjs.js'; | ||
| const child = spawn(process.execPath, [requiringCjsAsEsm]); | ||
| let stderr = ''; | ||
| child.stderr.setEncoding('utf8'); | ||
| child.stderr.on('data', (data) => { | ||
| stderr += data; | ||
| }); | ||
| child.on('close', common.mustCall((code, signal) => { | ||
|
|
||
| describe('CJS ↔︎ ESM interop warnings', { concurrency: true }, () => { | ||
|
|
||
| it(async () => { | ||
| const required = path.resolve( | ||
| fixtures.path('/es-modules/package-type-module/cjs.js') | ||
| ); | ||
| const basename = 'cjs.js'; | ||
| const { code, signal, stderr } = await spawnPromisified(execPath, [requiringCjsAsEsm]); | ||
|
|
||
| assert.ok( | ||
| stderr.replaceAll('\r', '').includes( | ||
| `Error [ERR_REQUIRE_ESM]: require() of ES Module ${required} from ${requiringCjsAsEsm} not supported.\n` | ||
| ) | ||
| ); | ||
| assert.ok( | ||
| stderr.replaceAll('\r', '').includes( | ||
| `Instead rename ${basename} to end in .cjs, change the requiring ` + | ||
| 'code to use dynamic import() which is available in all CommonJS ' + | ||
| `modules, or change "type": "module" to "type": "commonjs" in ${pjson} to ` + | ||
| 'treat all .js files as CommonJS (using .mjs for all ES modules ' + | ||
| 'instead).\n' | ||
| ) | ||
| ); | ||
|
|
||
| assert.strictEqual(code, 1); | ||
| assert.strictEqual(signal, null); | ||
| }); | ||
|
|
||
| assert.ok(stderr.replaceAll('\r', '').includes( | ||
| `Error [ERR_REQUIRE_ESM]: require() of ES Module ${required} from ${ | ||
| requiringCjsAsEsm} not supported.\n`)); | ||
| assert.ok(stderr.replaceAll('\r', '').includes( | ||
| `Instead rename ${basename} to end in .cjs, change the requiring ` + | ||
| 'code to use dynamic import() which is available in all CommonJS ' + | ||
| `modules, or change "type": "module" to "type": "commonjs" in ${pjson} to ` + | ||
| 'treat all .js files as CommonJS (using .mjs for all ES modules ' + | ||
| 'instead).\n')); | ||
| })); | ||
| } | ||
| it(async () => { | ||
| const required = path.resolve( | ||
| fixtures.path('/es-modules/package-type-module/esm.js') | ||
| ); | ||
| const basename = 'esm.js'; | ||
| const { code, signal, stderr } = await spawnPromisified(execPath, [requiringEsm]); | ||
|
|
||
| assert.ok( | ||
| stderr.replace(/\r/g, '').includes( | ||
| `Error [ERR_REQUIRE_ESM]: require() of ES Module ${required} from ${requiringEsm} not supported.\n` | ||
| ) | ||
| ); | ||
| assert.ok( | ||
| stderr.replace(/\r/g, '').includes( | ||
| `Instead change the require of ${basename} in ${requiringEsm} to` + | ||
| ' a dynamic import() which is available in all CommonJS modules.\n' | ||
| ) | ||
| ); | ||
|
|
||
| { | ||
| const required = path.resolve( | ||
| fixtures.path('/es-modules/package-type-module/esm.js') | ||
| ); | ||
| const basename = 'esm.js'; | ||
| const child = spawn(process.execPath, [requiringEsm]); | ||
| let stderr = ''; | ||
| child.stderr.setEncoding('utf8'); | ||
| child.stderr.on('data', (data) => { | ||
| stderr += data; | ||
| }); | ||
| child.on('close', common.mustCall((code, signal) => { | ||
| assert.strictEqual(code, 1); | ||
| assert.strictEqual(signal, null); | ||
|
|
||
| assert.ok(stderr.replace(/\r/g, '').includes( | ||
| `Error [ERR_REQUIRE_ESM]: require() of ES Module ${required} from ${ | ||
| requiringEsm} not supported.\n`)); | ||
| assert.ok(stderr.replace(/\r/g, '').includes( | ||
| `Instead change the require of ${basename} in ${requiringEsm} to` + | ||
| ' a dynamic import() which is available in all CommonJS modules.\n')); | ||
| })); | ||
| } | ||
| }); | ||
| }); |
This file contains hidden or 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 |
|---|---|---|
| @@ -1,21 +1,20 @@ | ||
| 'use strict'; | ||
|
|
||
| const common = require('../common'); | ||
| const fixtures = require('../common/fixtures'); | ||
| const { spawn } = require('child_process'); | ||
| const assert = require('assert'); | ||
| const { spawnPromisified } = require('../common'); | ||
| const fixtures = require('../common/fixtures.js'); | ||
| const assert = require('node:assert'); | ||
| const { execPath } = require('node:process'); | ||
| const { describe, it } = require('node:test'); | ||
|
|
||
|
|
||
| const entry = fixtures.path('/es-modules/builtin-imports-case.mjs'); | ||
|
|
||
| const child = spawn(process.execPath, [entry]); | ||
| child.stderr.setEncoding('utf8'); | ||
| let stdout = ''; | ||
| child.stdout.setEncoding('utf8'); | ||
| child.stdout.on('data', (data) => { | ||
| stdout += data; | ||
| describe('ESM: importing builtins & CJS', () => { | ||
| it('should work', async () => { | ||
| const { code, signal, stdout } = await spawnPromisified(execPath, [entry]); | ||
|
|
||
| assert.strictEqual(code, 0); | ||
| assert.strictEqual(signal, null); | ||
| assert.strictEqual(stdout, 'ok\n'); | ||
| }); | ||
| }); | ||
| child.on('close', common.mustCall((code, signal) => { | ||
| assert.strictEqual(code, 0); | ||
| assert.strictEqual(signal, null); | ||
| assert.strictEqual(stdout, 'ok\n'); | ||
| })); |
This file contains hidden or 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 |
|---|---|---|
| @@ -1,35 +1,29 @@ | ||
| 'use strict'; | ||
|
|
||
| const common = require('../common'); | ||
| const fixtures = require('../common/fixtures'); | ||
| const { spawn } = require('child_process'); | ||
| const assert = require('assert'); | ||
| const { spawnPromisified } = require('../common'); | ||
| const fixtures = require('../common/fixtures.js'); | ||
| const assert = require('node:assert'); | ||
| const { execPath } = require('node:process'); | ||
| const { describe, it } = require('node:test'); | ||
|
|
||
| const entry = fixtures.path('/es-modules/cjs-exports.mjs'); | ||
|
|
||
| let child = spawn(process.execPath, [entry]); | ||
| child.stderr.setEncoding('utf8'); | ||
| let stdout = ''; | ||
| child.stdout.setEncoding('utf8'); | ||
| child.stdout.on('data', (data) => { | ||
| stdout += data; | ||
| }); | ||
| child.on('close', common.mustCall((code, signal) => { | ||
| assert.strictEqual(code, 0); | ||
| assert.strictEqual(signal, null); | ||
| assert.strictEqual(stdout, 'ok\n'); | ||
| })); | ||
| describe('ESM: importing CJS', { concurrency: true }, () => { | ||
| it('should support valid CJS exports', async () => { | ||
| const validEntry = fixtures.path('/es-modules/cjs-exports.mjs'); | ||
| const { code, signal, stdout } = await spawnPromisified(execPath, [validEntry]); | ||
|
|
||
| assert.strictEqual(code, 0); | ||
| assert.strictEqual(signal, null); | ||
| assert.strictEqual(stdout, 'ok\n'); | ||
| }); | ||
|
|
||
| it('should eror on invalid CJS exports', async () => { | ||
| const invalidEntry = fixtures.path('/es-modules/cjs-exports-invalid.mjs'); | ||
| const { code, signal, stderr } = await spawnPromisified(execPath, [invalidEntry]); | ||
|
|
||
| const entryInvalid = fixtures.path('/es-modules/cjs-exports-invalid.mjs'); | ||
| child = spawn(process.execPath, [entryInvalid]); | ||
| let stderr = ''; | ||
| child.stderr.setEncoding('utf8'); | ||
| child.stderr.on('data', (data) => { | ||
| stderr += data; | ||
| assert.strictEqual(code, 1); | ||
| assert.strictEqual(signal, null); | ||
| assert.ok(stderr.includes('Warning: To load an ES module')); | ||
| assert.ok(stderr.includes('Unexpected token \'export\'')); | ||
| }); | ||
| }); | ||
| child.on('close', common.mustCall((code, signal) => { | ||
| assert.strictEqual(code, 1); | ||
| assert.strictEqual(signal, null); | ||
| assert.ok(stderr.includes('Warning: To load an ES module')); | ||
| assert.ok(stderr.includes('Unexpected token \'export\'')); | ||
| })); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.