1
1
'use strict' ;
2
2
3
- const { mustCall } = require ( '../common' ) ;
3
+ const { spawnPromisified } = require ( '../common' ) ;
4
4
const fixtures = require ( '../common/fixtures.js' ) ;
5
5
const assert = require ( 'node:assert' ) ;
6
6
const path = require ( 'node:path' ) ;
@@ -14,58 +14,55 @@ const pjson = path.resolve(
14
14
fixtures . path ( '/es-modules/package-type-module/package.json' )
15
15
) ;
16
16
17
- ( async ( ) => {
18
- const { default : spawn } = await import ( './helper.spawnAsPromised.mjs' ) ;
19
17
20
- describe ( 'CJS ↔︎ ESM interop warnings' , { concurrency : true } , ( ) => {
18
+ describe ( 'CJS ↔︎ ESM interop warnings' , { concurrency : true } , ( ) => {
21
19
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 ] ) ;
20
+ it ( async ( ) => {
21
+ const required = path . resolve (
22
+ fixtures . path ( '/es-modules/package-type-module/cjs.js' )
23
+ ) ;
24
+ const basename = 'cjs.js' ;
25
+ const { code, signal, stderr } = await spawnPromisified ( execPath , [ requiringCjsAsEsm ] ) ;
28
26
29
- assert . ok (
30
- stderr . replaceAll ( '\r' , '' ) . includes (
31
- `Error [ERR_REQUIRE_ESM]: require() of ES Module ${ required } from ${ requiringCjsAsEsm } not supported.\n`
32
- )
33
- ) ;
34
- assert . ok (
35
- stderr . replaceAll ( '\r' , '' ) . includes (
36
- `Instead rename ${ basename } to end in .cjs, change the requiring ` +
37
- 'code to use dynamic import() which is available in all CommonJS ' +
38
- `modules, or change "type": "module" to "type": "commonjs" in ${ pjson } to ` +
39
- 'treat all .js files as CommonJS (using .mjs for all ES modules ' +
40
- 'instead).\n'
41
- )
42
- ) ;
27
+ assert . ok (
28
+ stderr . replaceAll ( '\r' , '' ) . includes (
29
+ `Error [ERR_REQUIRE_ESM]: require() of ES Module ${ required } from ${ requiringCjsAsEsm } not supported.\n`
30
+ )
31
+ ) ;
32
+ assert . ok (
33
+ stderr . replaceAll ( '\r' , '' ) . includes (
34
+ `Instead rename ${ basename } to end in .cjs, change the requiring ` +
35
+ 'code to use dynamic import() which is available in all CommonJS ' +
36
+ `modules, or change "type": "module" to "type": "commonjs" in ${ pjson } to ` +
37
+ 'treat all .js files as CommonJS (using .mjs for all ES modules ' +
38
+ 'instead).\n'
39
+ )
40
+ ) ;
43
41
44
- assert . strictEqual ( code , 1 ) ;
45
- assert . strictEqual ( signal , null ) ;
46
- } ) ;
42
+ assert . strictEqual ( code , 1 ) ;
43
+ assert . strictEqual ( signal , null ) ;
44
+ } ) ;
47
45
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 ] ) ;
46
+ it ( async ( ) => {
47
+ const required = path . resolve (
48
+ fixtures . path ( '/es-modules/package-type-module/esm.js' )
49
+ ) ;
50
+ const basename = 'esm.js' ;
51
+ const { code, signal, stderr } = await spawnPromisified ( execPath , [ requiringEsm ] ) ;
54
52
55
- assert . ok (
56
- stderr . replace ( / \r / g, '' ) . includes (
57
- `Error [ERR_REQUIRE_ESM]: require() of ES Module ${ required } from ${ requiringEsm } not supported.\n`
58
- )
59
- ) ;
60
- assert . ok (
61
- stderr . replace ( / \r / g, '' ) . includes (
62
- `Instead change the require of ${ basename } in ${ requiringEsm } to` +
63
- ' a dynamic import() which is available in all CommonJS modules.\n'
64
- )
65
- ) ;
53
+ assert . ok (
54
+ stderr . replace ( / \r / g, '' ) . includes (
55
+ `Error [ERR_REQUIRE_ESM]: require() of ES Module ${ required } from ${ requiringEsm } not supported.\n`
56
+ )
57
+ ) ;
58
+ assert . ok (
59
+ stderr . replace ( / \r / g, '' ) . includes (
60
+ `Instead change the require of ${ basename } in ${ requiringEsm } to` +
61
+ ' a dynamic import() which is available in all CommonJS modules.\n'
62
+ )
63
+ ) ;
66
64
67
- assert . strictEqual ( code , 1 ) ;
68
- assert . strictEqual ( signal , null ) ;
69
- } ) ;
65
+ assert . strictEqual ( code , 1 ) ;
66
+ assert . strictEqual ( signal , null ) ;
70
67
} ) ;
71
- } ) ( ) . then ( mustCall ( ) ) ;
68
+ } ) ;
0 commit comments