@@ -744,32 +744,41 @@ describe('Loader hooks', { concurrency: !process.env.TEST_PARALLEL }, () => {
744744 assert . strictEqual ( signal , null ) ;
745745 } ) ;
746746
747- it ( 'should use ESM loader to respond to require.resolve calls when opting in' , async ( ) => {
748- const readFile = async ( ) => { } ;
749- const fileURLToPath = ( ) => { } ;
750- const { code, signal, stdout, stderr } = await spawnPromisified ( execPath , [
751- '--no-warnings' ,
752- '--experimental-loader' ,
753- `data:text/javascript,import{readFile}from"node:fs/promises";import{fileURLToPath}from"node:url";export ${
754- async function load ( u , c , n ) {
755- const r = await n ( u , c ) ;
756- if ( u . endsWith ( '/common/index.js' ) ) {
757- r . source = '"use strict";module.exports=require("node:module").createRequire(' +
758- `${ JSON . stringify ( u ) } )(${ JSON . stringify ( fileURLToPath ( u ) ) } );\n` ;
759- } else if ( c . format === 'commonjs' ) {
760- r . source = await readFile ( new URL ( u ) ) ;
761- }
762- return r ;
763- } } `,
764- '--experimental-loader' ,
765- fixtures . fileURL ( 'es-module-loaders/loader-resolve-passthru.mjs' ) ,
766- fixtures . path ( 'require-resolve.js' ) ,
767- ] ) ;
768747
769- assert . strictEqual ( stderr , '' ) ;
770- assert . strictEqual ( stdout , 'resolve passthru\n' . repeat ( 10 ) ) ;
771- assert . strictEqual ( code , 0 ) ;
772- assert . strictEqual ( signal , null ) ;
748+ describe ( 'should use ESM loader to respond to require.resolve calls when opting in' , ( ) => {
749+ for ( const { testConfigName, additionalOptions } of [
750+ { testConfigName : 'without --experimental-detect-module' , additionalOptions : [ ] } ,
751+ { testConfigName : 'with --experimental-detect-module' , additionalOptions : [ '--experimental-detect-module' ] } ,
752+ ] ) {
753+ it ( testConfigName , async ( ) => {
754+ const readFile = async ( ) => { } ;
755+ const fileURLToPath = ( ) => { } ;
756+ const { code, signal, stdout, stderr } = await spawnPromisified ( execPath , [
757+ ...additionalOptions ,
758+ '--no-warnings' ,
759+ '--experimental-loader' ,
760+ `data:text/javascript,import{readFile}from"node:fs/promises";import{fileURLToPath}from"node:url";export ${
761+ async function load ( u , c , n ) {
762+ const r = await n ( u , c ) ;
763+ if ( u . endsWith ( '/common/index.js' ) ) {
764+ r . source = '"use strict";module.exports=require("node:module").createRequire(' +
765+ `${ JSON . stringify ( u ) } )(${ JSON . stringify ( fileURLToPath ( u ) ) } );\n` ;
766+ } else if ( c . format === 'commonjs' ) {
767+ r . source = await readFile ( new URL ( u ) ) ;
768+ }
769+ return r ;
770+ } } `,
771+ '--experimental-loader' ,
772+ fixtures . fileURL ( 'es-module-loaders/loader-resolve-passthru.mjs' ) ,
773+ fixtures . path ( 'require-resolve.js' ) ,
774+ ] ) ;
775+
776+ assert . strictEqual ( stderr , '' ) ;
777+ assert . strictEqual ( stdout , 'resolve passthru\n' . repeat ( 10 ) ) ;
778+ assert . strictEqual ( code , 0 ) ;
779+ assert . strictEqual ( signal , null ) ;
780+ } ) ;
781+ }
773782 } ) ;
774783
775784 it ( 'should support source maps in commonjs translator' , async ( ) => {
0 commit comments