11'use strict' ;
22
3- const { mustCall } = require ( '../common' ) ;
3+ const { spawnPromisified } = require ( '../common' ) ;
44const fixtures = require ( '../common/fixtures.js' ) ;
55const assert = require ( 'node:assert' ) ;
66const path = require ( 'node:path' ) ;
@@ -14,58 +14,55 @@ const pjson = path.resolve(
1414 fixtures . path ( '/es-modules/package-type-module/package.json' )
1515) ;
1616
17- ( async ( ) => {
18- const { default : spawn } = await import ( './helper.spawnAsPromised.mjs' ) ;
1917
20- describe ( 'CJS ↔︎ ESM interop warnings' , { concurrency : true } , ( ) => {
18+ describe ( 'CJS ↔︎ ESM interop warnings' , { concurrency : true } , ( ) => {
2119
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 ] ) ;
2826
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+ ) ;
4341
44- assert . strictEqual ( code , 1 ) ;
45- assert . strictEqual ( signal , null ) ;
46- } ) ;
42+ assert . strictEqual ( code , 1 ) ;
43+ assert . strictEqual ( signal , null ) ;
44+ } ) ;
4745
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 ] ) ;
5452
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+ ) ;
6664
67- assert . strictEqual ( code , 1 ) ;
68- assert . strictEqual ( signal , null ) ;
69- } ) ;
65+ assert . strictEqual ( code , 1 ) ;
66+ assert . strictEqual ( signal , null ) ;
7067 } ) ;
71- } ) ( ) . then ( mustCall ( ) ) ;
68+ } ) ;
0 commit comments