@@ -101,6 +101,7 @@ describe('--experimental-detect-module', { concurrency: true }, () => {
101101 ] ) {
102102 it ( testName , async ( ) => {
103103 const { stdout, stderr, code, signal } = await spawnPromisified ( process . execPath , [
104+ '--no-warnings' ,
104105 '--experimental-detect-module' ,
105106 entryPath ,
106107 ] ) ;
@@ -142,6 +143,7 @@ describe('--experimental-detect-module', { concurrency: true }, () => {
142143 ] ) {
143144 it ( testName , async ( ) => {
144145 const { stdout, stderr, code, signal } = await spawnPromisified ( process . execPath , [
146+ '--no-warnings' ,
145147 '--experimental-detect-module' ,
146148 entryPath ,
147149 ] ) ;
@@ -291,6 +293,7 @@ describe('--experimental-detect-module', { concurrency: true }, () => {
291293
292294 it ( 'permits declaration of CommonJS module variables' , async ( ) => {
293295 const { stdout, stderr, code, signal } = await spawnPromisified ( process . execPath , [
296+ '--no-warnings' ,
294297 '--experimental-detect-module' ,
295298 fixtures . path ( 'es-modules/package-without-type/commonjs-wrapper-variables.js' ) ,
296299 ] ) ;
@@ -327,6 +330,48 @@ describe('--experimental-detect-module', { concurrency: true }, () => {
327330 strictEqual ( signal , null ) ;
328331 } ) ;
329332 } ) ;
333+
334+ describe ( 'warn about typeless packages for .js files with ESM syntax' , { concurrency : true } , ( ) => {
335+ for ( const { testName, entryPath } of [
336+ {
337+ testName : 'warns for ESM syntax in a .js entry point in a typeless package' ,
338+ entryPath : fixtures . path ( 'es-modules/package-without-type/module.js' ) ,
339+ } ,
340+ {
341+ testName : 'warns for ESM syntax in a .js file imported by a CommonJS entry point in a typeless package' ,
342+ entryPath : fixtures . path ( 'es-modules/package-without-type/imports-esm.js' ) ,
343+ } ,
344+ {
345+ testName : 'warns for ESM syntax in a .js file imported by an ESM entry point in a typeless package' ,
346+ entryPath : fixtures . path ( 'es-modules/package-without-type/imports-esm.mjs' ) ,
347+ } ,
348+ ] ) {
349+ it ( testName , async ( ) => {
350+ const { stdout, stderr, code, signal } = await spawnPromisified ( process . execPath , [
351+ '--experimental-detect-module' ,
352+ entryPath ,
353+ ] ) ;
354+
355+ match ( stderr , / M O D U L E _ T Y P E L E S S _ P A C K A G E _ J S O N / ) ;
356+ strictEqual ( stdout , 'executed\n' ) ;
357+ strictEqual ( code , 0 ) ;
358+ strictEqual ( signal , null ) ;
359+ } ) ;
360+ }
361+
362+ it ( 'warns only once for a package.json that affects multiple files' , async ( ) => {
363+ const { stdout, stderr, code, signal } = await spawnPromisified ( process . execPath , [
364+ '--experimental-detect-module' ,
365+ fixtures . path ( 'es-modules/package-without-type/detected-as-esm.js' ) ,
366+ ] ) ;
367+
368+ match ( stderr , / M O D U L E _ T Y P E L E S S _ P A C K A G E _ J S O N / ) ;
369+ strictEqual ( stderr . match ( / M O D U L E _ T Y P E L E S S _ P A C K A G E _ J S O N / g) . length , 1 ) ;
370+ strictEqual ( stdout , 'executed\nexecuted\n' ) ;
371+ strictEqual ( code , 0 ) ;
372+ strictEqual ( signal , null ) ;
373+ } ) ;
374+ } ) ;
330375} ) ;
331376
332377// Validate temporarily disabling `--abort-on-uncaught-exception`
0 commit comments