@@ -4,11 +4,10 @@ import { spawn } from 'node:child_process';
4
4
import { describe , it } from 'node:test' ;
5
5
import { strictEqual , match } from 'node:assert' ;
6
6
7
- describe ( '--experimental-detect-module ' , { concurrency : true } , ( ) => {
8
- describe ( 'string input' , { concurrency : true } , ( ) => {
7
+ describe ( 'Module syntax detection ' , { concurrency : ! process . env . TEST_PARALLEL } , ( ) => {
8
+ describe ( 'string input' , { concurrency : ! process . env . TEST_PARALLEL } , ( ) => {
9
9
it ( 'permits ESM syntax in --eval input without requiring --input-type=module' , async ( ) => {
10
10
const { stdout, stderr, code, signal } = await spawnPromisified ( process . execPath , [
11
- '--experimental-detect-module' ,
12
11
'--eval' ,
13
12
'import { version } from "node:process"; console.log(version);' ,
14
13
] ) ;
@@ -22,17 +21,14 @@ describe('--experimental-detect-module', { concurrency: true }, () => {
22
21
// ESM is unsupported for --print via --input-type=module
23
22
24
23
it ( 'permits ESM syntax in STDIN input without requiring --input-type=module' , async ( ) => {
25
- const child = spawn ( process . execPath , [
26
- '--experimental-detect-module' ,
27
- ] ) ;
24
+ const child = spawn ( process . execPath , [ ] ) ;
28
25
child . stdin . end ( 'console.log(typeof import.meta.resolve)' ) ;
29
26
30
27
match ( ( await child . stdout . toArray ( ) ) . toString ( ) , / ^ f u n c t i o n \r ? \n $ / ) ;
31
28
} ) ;
32
29
33
30
it ( 'should be overridden by --input-type' , async ( ) => {
34
31
const { code, signal, stdout, stderr } = await spawnPromisified ( process . execPath , [
35
- '--experimental-detect-module' ,
36
32
'--input-type=commonjs' ,
37
33
'--eval' ,
38
34
'import.meta.url' ,
@@ -46,7 +42,6 @@ describe('--experimental-detect-module', { concurrency: true }, () => {
46
42
47
43
it ( 'should not switch to module if code is parsable as script' , async ( ) => {
48
44
const { code, signal, stdout, stderr } = await spawnPromisified ( process . execPath , [
49
- '--experimental-detect-module' ,
50
45
'--eval' ,
51
46
'let __filename,__dirname,require,module,exports;this.a' ,
52
47
] ) ;
@@ -59,7 +54,6 @@ describe('--experimental-detect-module', { concurrency: true }, () => {
59
54
60
55
it ( 'should be overridden by --experimental-default-type' , async ( ) => {
61
56
const { code, signal, stdout, stderr } = await spawnPromisified ( process . execPath , [
62
- '--experimental-detect-module' ,
63
57
'--experimental-default-type=commonjs' ,
64
58
'--eval' ,
65
59
'import.meta.url' ,
@@ -73,7 +67,6 @@ describe('--experimental-detect-module', { concurrency: true }, () => {
73
67
74
68
it ( 'does not trigger detection via source code `eval()`' , async ( ) => {
75
69
const { code, signal, stdout, stderr } = await spawnPromisified ( process . execPath , [
76
- '--experimental-detect-module' ,
77
70
'--eval' ,
78
71
'eval("import \'nonexistent\';");' ,
79
72
] ) ;
@@ -115,7 +108,6 @@ describe('--experimental-detect-module', { concurrency: true }, () => {
115
108
it ( testName , async ( ) => {
116
109
const { stdout, stderr, code, signal } = await spawnPromisified ( process . execPath , [
117
110
'--no-warnings' ,
118
- '--experimental-detect-module' ,
119
111
entryPath ,
120
112
] ) ;
121
113
@@ -157,7 +149,6 @@ describe('--experimental-detect-module', { concurrency: true }, () => {
157
149
it ( testName , async ( ) => {
158
150
const { stdout, stderr, code, signal } = await spawnPromisified ( process . execPath , [
159
151
'--no-warnings' ,
160
- '--experimental-detect-module' ,
161
152
entryPath ,
162
153
] ) ;
163
154
@@ -171,7 +162,6 @@ describe('--experimental-detect-module', { concurrency: true }, () => {
171
162
it ( 'should not hint wrong format in resolve hook' , async ( ) => {
172
163
let writeSync ;
173
164
const { stdout, stderr, code, signal } = await spawnPromisified ( process . execPath , [
174
- '--experimental-detect-module' ,
175
165
'--no-warnings' ,
176
166
'--loader' ,
177
167
`data:text/javascript,import { writeSync } from "node:fs"; export ${ encodeURIComponent (
@@ -209,7 +199,6 @@ describe('--experimental-detect-module', { concurrency: true }, () => {
209
199
] ) {
210
200
it ( testName , async ( ) => {
211
201
const { stdout, stderr, code, signal } = await spawnPromisified ( process . execPath , [
212
- '--experimental-detect-module' ,
213
202
entryPath ,
214
203
] ) ;
215
204
@@ -238,7 +227,6 @@ describe('--experimental-detect-module', { concurrency: true }, () => {
238
227
] ) {
239
228
it ( testName , async ( ) => {
240
229
const { stdout, stderr, code, signal } = await spawnPromisified ( process . execPath , [
241
- '--experimental-detect-module' ,
242
230
entryPath ,
243
231
] ) ;
244
232
@@ -254,7 +242,6 @@ describe('--experimental-detect-module', { concurrency: true }, () => {
254
242
describe ( 'syntax that errors in CommonJS but works in ESM' , { concurrency : true } , ( ) => {
255
243
it ( 'permits top-level `await`' , async ( ) => {
256
244
const { stdout, stderr, code, signal } = await spawnPromisified ( process . execPath , [
257
- '--experimental-detect-module' ,
258
245
'--eval' ,
259
246
'await Promise.resolve(); console.log("executed");' ,
260
247
] ) ;
@@ -267,7 +254,6 @@ describe('--experimental-detect-module', { concurrency: true }, () => {
267
254
268
255
it ( 'permits top-level `await` above import/export syntax' , async ( ) => {
269
256
const { stdout, stderr, code, signal } = await spawnPromisified ( process . execPath , [
270
- '--experimental-detect-module' ,
271
257
'--eval' ,
272
258
'await Promise.resolve(); import "node:os"; console.log("executed");' ,
273
259
] ) ;
@@ -280,7 +266,6 @@ describe('--experimental-detect-module', { concurrency: true }, () => {
280
266
281
267
it ( 'still throws on `await` in an ordinary sync function' , async ( ) => {
282
268
const { stdout, stderr, code, signal } = await spawnPromisified ( process . execPath , [
283
- '--experimental-detect-module' ,
284
269
'--eval' ,
285
270
'function fn() { await Promise.resolve(); } fn();' ,
286
271
] ) ;
@@ -293,7 +278,6 @@ describe('--experimental-detect-module', { concurrency: true }, () => {
293
278
294
279
it ( 'throws on undefined `require` when top-level `await` triggers ESM parsing' , async ( ) => {
295
280
const { stdout, stderr, code, signal } = await spawnPromisified ( process . execPath , [
296
- '--experimental-detect-module' ,
297
281
'--eval' ,
298
282
'const fs = require("node:fs"); await Promise.resolve();' ,
299
283
] ) ;
@@ -307,7 +291,6 @@ describe('--experimental-detect-module', { concurrency: true }, () => {
307
291
it ( 'permits declaration of CommonJS module variables' , async ( ) => {
308
292
const { stdout, stderr, code, signal } = await spawnPromisified ( process . execPath , [
309
293
'--no-warnings' ,
310
- '--experimental-detect-module' ,
311
294
fixtures . path ( 'es-modules/package-without-type/commonjs-wrapper-variables.js' ) ,
312
295
] ) ;
313
296
@@ -319,7 +302,6 @@ describe('--experimental-detect-module', { concurrency: true }, () => {
319
302
320
303
it ( 'permits declaration of CommonJS module variables above import/export' , async ( ) => {
321
304
const { stdout, stderr, code, signal } = await spawnPromisified ( process . execPath , [
322
- '--experimental-detect-module' ,
323
305
'--eval' ,
324
306
'const module = 3; import "node:os"; console.log("executed");' ,
325
307
] ) ;
@@ -332,7 +314,6 @@ describe('--experimental-detect-module', { concurrency: true }, () => {
332
314
333
315
it ( 'still throws on double `const` declaration not at the top level' , async ( ) => {
334
316
const { stdout, stderr, code, signal } = await spawnPromisified ( process . execPath , [
335
- '--experimental-detect-module' ,
336
317
'--eval' ,
337
318
'function fn() { const require = 1; const require = 2; } fn();' ,
338
319
] ) ;
@@ -361,7 +342,6 @@ describe('--experimental-detect-module', { concurrency: true }, () => {
361
342
] ) {
362
343
it ( testName , async ( ) => {
363
344
const { stdout, stderr, code, signal } = await spawnPromisified ( process . execPath , [
364
- '--experimental-detect-module' ,
365
345
entryPath ,
366
346
] ) ;
367
347
@@ -374,7 +354,6 @@ describe('--experimental-detect-module', { concurrency: true }, () => {
374
354
375
355
it ( 'warns only once for a package.json that affects multiple files' , async ( ) => {
376
356
const { stdout, stderr, code, signal } = await spawnPromisified ( process . execPath , [
377
- '--experimental-detect-module' ,
378
357
fixtures . path ( 'es-modules/package-without-type/detected-as-esm.js' ) ,
379
358
] ) ;
380
359
@@ -384,6 +363,18 @@ describe('--experimental-detect-module', { concurrency: true }, () => {
384
363
strictEqual ( code , 0 ) ;
385
364
strictEqual ( signal , null ) ;
386
365
} ) ;
366
+
367
+ it ( 'can be disabled via --no-experimental-detect-module' , async ( ) => {
368
+ const { stdout, stderr, code, signal } = await spawnPromisified ( process . execPath , [
369
+ '--no-experimental-detect-module' ,
370
+ fixtures . path ( 'es-modules/package-without-type/module.js' ) ,
371
+ ] ) ;
372
+
373
+ match ( stderr , / S y n t a x E r r o r : U n e x p e c t e d t o k e n ' e x p o r t ' / ) ;
374
+ strictEqual ( stdout , '' ) ;
375
+ strictEqual ( code , 1 ) ;
376
+ strictEqual ( signal , null ) ;
377
+ } ) ;
387
378
} ) ;
388
379
} ) ;
389
380
@@ -410,7 +401,6 @@ describe('Wrapping a `require` of an ES module while using `--abort-on-uncaught-
410
401
describe ( 'when working with Worker threads' , ( ) => {
411
402
it ( 'should support sloppy scripts that declare CJS "global-like" variables' , async ( ) => {
412
403
const { code, signal, stdout, stderr } = await spawnPromisified ( process . execPath , [
413
- '--experimental-detect-module' ,
414
404
'--eval' ,
415
405
'new worker_threads.Worker("let __filename,__dirname,require,module,exports;this.a",{eval:true})' ,
416
406
] ) ;
0 commit comments