Skip to content

Commit 24157ab

Browse files
switch to node:test
1 parent 03d1f1d commit 24157ab

36 files changed

+1196
-1078
lines changed

lib/internal/modules/esm/loader.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,7 @@ class ESMLoader {
336336
* A list of exports from user-defined loaders (as returned by
337337
* ESMLoader.import()).
338338
*/
339-
async addCustomLoaders(
339+
addCustomLoaders(
340340
customLoaders = [],
341341
) {
342342
for (let i = 0; i < customLoaders.length; i++) {

test/es-module/helper.spawnAsPromised.mjs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import '../common/index.mjs';
12
import cp from 'node:child_process';
23

34

Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1-
import { mustCall } from '../common/index.mjs';
2-
import * as fixtures from '../common/fixtures.mjs';
3-
import assert from 'node:assert';
4-
import path from 'node:path';
5-
import { execPath } from 'node:process';
1+
'use strict';
62

7-
import spawn from './helper.spawnAsPromised.mjs';
3+
const { mustCall } = require('../common');
4+
const fixtures = require('../common/fixtures.js');
5+
const assert = require('node:assert');
6+
const path = require('node:path');
7+
const { execPath } = require('node:process');
8+
const { describe, it } = require('node:test');
89

910

1011
const requiringCjsAsEsm = path.resolve(fixtures.path('/es-modules/cjs-esm.js'));
@@ -13,13 +14,18 @@ const pjson = path.resolve(
1314
fixtures.path('/es-modules/package-type-module/package.json')
1415
);
1516

16-
{
17-
const required = path.resolve(
18-
fixtures.path('/es-modules/package-type-module/cjs.js')
19-
);
20-
const basename = 'cjs.js';
21-
spawn(execPath, [requiringCjsAsEsm])
22-
.then(mustCall(({ code, signal, stderr }) => {
17+
(async () => {
18+
const { default: spawn } = await import('./helper.spawnAsPromised.mjs');
19+
20+
describe('CJS ↔︎ ESM interop warnings', { concurrency: true }, () => {
21+
22+
it(async () => {
23+
const required = path.resolve(
24+
fixtures.path('/es-modules/package-type-module/cjs.js')
25+
);
26+
const basename = 'cjs.js';
27+
const { code, signal, stderr } = await spawn(execPath, [requiringCjsAsEsm]);
28+
2329
assert.ok(
2430
stderr.replaceAll('\r', '').includes(
2531
`Error [ERR_REQUIRE_ESM]: require() of ES Module ${required} from ${requiringCjsAsEsm} not supported.\n`
@@ -37,16 +43,15 @@ const pjson = path.resolve(
3743

3844
assert.strictEqual(code, 1);
3945
assert.strictEqual(signal, null);
40-
}));
41-
}
46+
});
47+
48+
it(async () => {
49+
const required = path.resolve(
50+
fixtures.path('/es-modules/package-type-module/esm.js')
51+
);
52+
const basename = 'esm.js';
53+
const { code, signal, stderr } = await spawn(execPath, [requiringEsm]);
4254

43-
{
44-
const required = path.resolve(
45-
fixtures.path('/es-modules/package-type-module/esm.js')
46-
);
47-
const basename = 'esm.js';
48-
spawn(execPath, [requiringEsm])
49-
.then(mustCall(({ code, signal, stderr }) => {
5055
assert.ok(
5156
stderr.replace(/\r/g, '').includes(
5257
`Error [ERR_REQUIRE_ESM]: require() of ES Module ${required} from ${requiringEsm} not supported.\n`
@@ -61,5 +66,6 @@ const pjson = path.resolve(
6166

6267
assert.strictEqual(code, 1);
6368
assert.strictEqual(signal, null);
64-
}));
65-
}
69+
});
70+
});
71+
})().then(mustCall());
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
'use strict';
2+
3+
const { mustCall } = require('../common');
4+
const fixtures = require('../common/fixtures.js');
5+
const assert = require('node:assert');
6+
const { execPath } = require('node:process');
7+
const { describe, it } = require('node:test');
8+
9+
10+
const entry = fixtures.path('/es-modules/builtin-imports-case.mjs');
11+
12+
(async () => {
13+
const { default: spawn } = await import('./helper.spawnAsPromised.mjs');
14+
15+
describe('ESM: importing builtins & CJS', () => {
16+
it('should work', async () => {
17+
const { code, signal, stdout } = await spawn(execPath, [entry]);
18+
19+
assert.strictEqual(code, 0);
20+
assert.strictEqual(signal, null);
21+
assert.strictEqual(stdout, 'ok\n');
22+
});
23+
});
24+
})().then(mustCall());

test/es-module/test-esm-cjs-builtins.mjs

Lines changed: 0 additions & 15 deletions
This file was deleted.
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
'use strict';
2+
3+
const { mustCall } = require('../common');
4+
const fixtures = require('../common/fixtures.js');
5+
const assert = require('node:assert');
6+
const { execPath } = require('node:process');
7+
const { describe, it } = require('node:test');
8+
9+
10+
(async () => {
11+
const { default: spawn } = await import('./helper.spawnAsPromised.mjs');
12+
13+
describe('ESM: importing CJS', { concurrency: true }, () => {
14+
it('should support valid CJS exports', async () => {
15+
const validEntry = fixtures.path('/es-modules/cjs-exports.mjs');
16+
const { code, signal, stdout } = await spawn(execPath, [validEntry]);
17+
18+
assert.strictEqual(code, 0);
19+
assert.strictEqual(signal, null);
20+
assert.strictEqual(stdout, 'ok\n');
21+
});
22+
23+
it('should eror on invalid CJS exports', async () => {
24+
const invalidEntry = fixtures.path('/es-modules/cjs-exports-invalid.mjs');
25+
const { code, signal, stderr } = await spawn(execPath, [invalidEntry]);
26+
27+
assert.strictEqual(code, 1);
28+
assert.strictEqual(signal, null);
29+
assert.ok(stderr.includes('Warning: To load an ES module'));
30+
assert.ok(stderr.includes('Unexpected token \'export\''));
31+
});
32+
});
33+
})().then(mustCall());

test/es-module/test-esm-cjs-exports.mjs

Lines changed: 0 additions & 24 deletions
This file was deleted.
Lines changed: 68 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
import { mustCall } from '../common/index.mjs';
1+
import '../common/index.mjs';
22
import * as fixtures from '../common/fixtures.mjs';
33
import assert from 'node:assert';
44
import { execPath } from 'node:process';
5+
import { describe, it } from 'node:test';
56

67
import spawn from './helper.spawnAsPromised.mjs';
78

@@ -20,57 +21,69 @@ const mustNotIncludeMessage = {
2021
includeNote: false,
2122
};
2223

23-
for (
24-
const { errorNeedle, filePath, getMessage, includeNote }
25-
of [
26-
{
27-
filePath: fixtures.path('/es-modules/es-note-unexpected-export-1.cjs'),
28-
...mustIncludeMessage,
29-
},
30-
{
31-
filePath: fixtures.path('/es-modules/es-note-unexpected-import-1.cjs'),
32-
...mustIncludeMessage,
33-
},
34-
{
35-
filePath: fixtures.path('/es-modules/es-note-promiserej-import-2.cjs'),
36-
...mustNotIncludeMessage,
37-
},
38-
{
39-
filePath: fixtures.path('/es-modules/es-note-unexpected-import-3.cjs'),
40-
...mustIncludeMessage,
41-
},
42-
{
43-
filePath: fixtures.path('/es-modules/es-note-unexpected-import-4.cjs'),
44-
...mustIncludeMessage,
45-
},
46-
{
47-
filePath: fixtures.path('/es-modules/es-note-unexpected-import-5.cjs'),
48-
...mustNotIncludeMessage,
49-
},
50-
{
51-
filePath: fixtures.path('/es-modules/es-note-error-1.mjs'),
52-
...mustNotIncludeMessage,
53-
errorNeedle: 'Error: some error',
54-
},
55-
{
56-
filePath: fixtures.path('/es-modules/es-note-error-2.mjs'),
57-
...mustNotIncludeMessage,
58-
errorNeedle: 'string',
59-
},
60-
{
61-
filePath: fixtures.path('/es-modules/es-note-error-3.mjs'),
62-
...mustNotIncludeMessage,
63-
errorNeedle: 'null',
64-
},
65-
{
66-
filePath: fixtures.path('/es-modules/es-note-error-4.mjs'),
67-
...mustNotIncludeMessage,
68-
errorNeedle: 'undefined',
69-
},
70-
]
71-
) {
72-
spawn(execPath, [filePath])
73-
.then(mustCall(({ code, stderr }) => {
24+
describe('ESM: ', { concurrently: true }, () => {
25+
for (
26+
const { errorNeedle, filePath, getMessage, includeNote }
27+
of [
28+
{
29+
// name: '',
30+
filePath: fixtures.path('/es-modules/es-note-unexpected-export-1.cjs'),
31+
...mustIncludeMessage,
32+
},
33+
{
34+
// name: '',
35+
filePath: fixtures.path('/es-modules/es-note-unexpected-import-1.cjs'),
36+
...mustIncludeMessage,
37+
},
38+
{
39+
// name: '',
40+
filePath: fixtures.path('/es-modules/es-note-promiserej-import-2.cjs'),
41+
...mustNotIncludeMessage,
42+
},
43+
{
44+
// name: '',
45+
filePath: fixtures.path('/es-modules/es-note-unexpected-import-3.cjs'),
46+
...mustIncludeMessage,
47+
},
48+
{
49+
// name: '',
50+
filePath: fixtures.path('/es-modules/es-note-unexpected-import-4.cjs'),
51+
...mustIncludeMessage,
52+
},
53+
{
54+
// name: '',
55+
filePath: fixtures.path('/es-modules/es-note-unexpected-import-5.cjs'),
56+
...mustNotIncludeMessage,
57+
},
58+
{
59+
// name: '',
60+
filePath: fixtures.path('/es-modules/es-note-error-1.mjs'),
61+
...mustNotIncludeMessage,
62+
errorNeedle: 'Error: some error',
63+
},
64+
{
65+
// name: '',
66+
filePath: fixtures.path('/es-modules/es-note-error-2.mjs'),
67+
...mustNotIncludeMessage,
68+
errorNeedle: 'string',
69+
},
70+
{
71+
// name: '',
72+
filePath: fixtures.path('/es-modules/es-note-error-3.mjs'),
73+
...mustNotIncludeMessage,
74+
errorNeedle: 'null',
75+
},
76+
{
77+
// name: '',
78+
filePath: fixtures.path('/es-modules/es-note-error-4.mjs'),
79+
...mustNotIncludeMessage,
80+
errorNeedle: 'undefined',
81+
},
82+
]
83+
) {
84+
it(`should ${includeNote ? '' : 'NOT'} include note`, async () => {
85+
const { code, stderr } = await spawn(execPath, [filePath]);
86+
7487
assert.strictEqual(code, 1);
7588

7689
if (errorNeedle) stderr.includes(errorNeedle);
@@ -80,5 +93,6 @@ for (
8093
includeNote ? includesNote : !includesNote,
8194
`${filePath} ${getMessage(stderr)}`,
8295
);
83-
}));
84-
}
96+
});
97+
}
98+
});
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
'use strict';
2+
3+
const { mustCall } = require('../common');
4+
const fixtures = require('../common/fixtures.js');
5+
const assert = require('node:assert');
6+
const { execPath } = require('node:process');
7+
const { describe, it } = require('node:test');
8+
9+
10+
(async () => {
11+
const { default: spawn } = await import('./helper.spawnAsPromised.mjs');
12+
13+
describe('ESM: importing CJS', () => {
14+
it('should work', async () => {
15+
const { code, signal, stdout } = await spawn(execPath, [
16+
fixtures.path('/es-modules/cjs.js'),
17+
]);
18+
19+
assert.strictEqual(code, 0);
20+
assert.strictEqual(signal, null);
21+
assert.strictEqual(stdout, 'executed\n');
22+
});
23+
});
24+
})().then(mustCall());

test/es-module/test-esm-cjs-main.mjs

Lines changed: 0 additions & 14 deletions
This file was deleted.

0 commit comments

Comments
 (0)