Skip to content

Commit 7b4a2b1

Browse files
switch to node:test
1 parent 728fad4 commit 7b4a2b1

File tree

1 file changed

+49
-48
lines changed

1 file changed

+49
-48
lines changed
Lines changed: 49 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
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 path from 'node:path';
55
import { execPath } from 'node:process';
6+
import { describe, it } from 'node:test';
67

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

@@ -13,53 +14,53 @@ 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 }) => {
23-
assert.ok(
24-
stderr.replaceAll('\r', '').includes(
25-
`Error [ERR_REQUIRE_ESM]: require() of ES Module ${required} from ${requiringCjsAsEsm} not supported.\n`
26-
)
27-
);
28-
assert.ok(
29-
stderr.replaceAll('\r', '').includes(
30-
`Instead rename ${basename} to end in .cjs, change the requiring ` +
31-
'code to use dynamic import() which is available in all CommonJS ' +
32-
`modules, or change "type": "module" to "type": "commonjs" in ${pjson} to ` +
33-
'treat all .js files as CommonJS (using .mjs for all ES modules ' +
34-
'instead).\n'
35-
)
36-
);
17+
describe('CJS ↔︎ ESM interop warnings', { concurrency: 2 }, () => {
18+
it(async () => {
19+
const required = path.resolve(
20+
fixtures.path('/es-modules/package-type-module/cjs.js')
21+
);
22+
const basename = 'cjs.js';
23+
const { code, signal, stderr } = await spawn(execPath, [requiringCjsAsEsm])
3724

38-
assert.strictEqual(code, 1);
39-
assert.strictEqual(signal, null);
40-
}));
41-
}
25+
assert.ok(
26+
stderr.replaceAll('\r', '').includes(
27+
`Error [ERR_REQUIRE_ESM]: require() of ES Module ${required} from ${requiringCjsAsEsm} not supported.\n`
28+
)
29+
);
30+
assert.ok(
31+
stderr.replaceAll('\r', '').includes(
32+
`Instead rename ${basename} to end in .cjs, change the requiring ` +
33+
'code to use dynamic import() which is available in all CommonJS ' +
34+
`modules, or change "type": "module" to "type": "commonjs" in ${pjson} to ` +
35+
'treat all .js files as CommonJS (using .mjs for all ES modules ' +
36+
'instead).\n'
37+
)
38+
);
4239

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 }) => {
50-
assert.ok(
51-
stderr.replace(/\r/g, '').includes(
52-
`Error [ERR_REQUIRE_ESM]: require() of ES Module ${required} from ${requiringEsm} not supported.\n`
53-
)
54-
);
55-
assert.ok(
56-
stderr.replace(/\r/g, '').includes(
57-
`Instead change the require of ${basename} in ${requiringEsm} to` +
58-
' a dynamic import() which is available in all CommonJS modules.\n'
59-
)
60-
);
40+
assert.strictEqual(code, 1);
41+
assert.strictEqual(signal, null);
42+
});
6143

62-
assert.strictEqual(code, 1);
63-
assert.strictEqual(signal, null);
64-
}));
65-
}
44+
it(async () => {
45+
const required = path.resolve(
46+
fixtures.path('/es-modules/package-type-module/esm.js')
47+
);
48+
const basename = 'esm.js';
49+
const { code, signal, stderr } = await spawn(execPath, [requiringEsm])
50+
51+
assert.ok(
52+
stderr.replace(/\r/g, '').includes(
53+
`Error [ERR_REQUIRE_ESM]: require() of ES Module ${required} from ${requiringEsm} not supported.\n`
54+
)
55+
);
56+
assert.ok(
57+
stderr.replace(/\r/g, '').includes(
58+
`Instead change the require of ${basename} in ${requiringEsm} to` +
59+
' a dynamic import() which is available in all CommonJS modules.\n'
60+
)
61+
);
62+
63+
assert.strictEqual(code, 1);
64+
assert.strictEqual(signal, null);
65+
});
66+
});

0 commit comments

Comments
 (0)