@@ -168,7 +168,7 @@ describe('--experimental-detect-module', { concurrency: !process.env.TEST_PARALL
168168 } ) ;
169169 }
170170
171- it ( 'should not hint wrong format in resolve hook' , async ( ) => {
171+ it ( 'should hint format correctly for the resolve hook for extensionless modules ' , async ( ) => {
172172 let writeSync ;
173173 const { stdout, stderr, code, signal } = await spawnPromisified ( process . execPath , [
174174 '--experimental-detect-module' ,
@@ -185,7 +185,7 @@ describe('--experimental-detect-module', { concurrency: !process.env.TEST_PARALL
185185 ] ) ;
186186
187187 strictEqual ( stderr , '' ) ;
188- strictEqual ( stdout , 'null \nexecuted\n' ) ;
188+ strictEqual ( stdout , 'module \nexecuted\n' ) ;
189189 strictEqual ( code , 0 ) ;
190190 strictEqual ( signal , null ) ;
191191
@@ -385,6 +385,65 @@ describe('--experimental-detect-module', { concurrency: !process.env.TEST_PARALL
385385 strictEqual ( signal , null ) ;
386386 } ) ;
387387 } ) ;
388+
389+ describe ( 'should work with module customization hooks' , { concurrency : true } , ( ) => {
390+ it ( 'should not break basic hooks functionality of substituting a module' , async ( ) => {
391+ const { code, signal, stdout, stderr } = await spawnPromisified ( process . execPath , [
392+ '--experimental-detect-module' ,
393+ '--import' ,
394+ fixtures . fileURL ( 'es-module-loaders/builtin-named-exports.mjs' ) ,
395+ fixtures . path ( 'es-modules/require-esm-throws-with-loaders.js' ) ,
396+ ] ) ;
397+
398+ strictEqual ( stderr , '' ) ;
399+ strictEqual ( stdout , '' ) ;
400+ strictEqual ( code , 0 ) ;
401+ strictEqual ( signal , null ) ;
402+ } ) ;
403+
404+ it ( 'should detect the syntax of the source as returned by a custom load hook' , async ( ) => {
405+ const { code, signal, stdout, stderr } = await spawnPromisified ( process . execPath , [
406+ '--no-warnings' ,
407+ '--experimental-detect-module' ,
408+ '--import' ,
409+ `data:text/javascript,${ encodeURIComponent (
410+ 'import { register } from "node:module";' +
411+ 'import { pathToFileURL } from "node:url";' +
412+ 'register("./transpile-esm-to-cjs.mjs", pathToFileURL("./"));'
413+ ) } `,
414+ fixtures . path ( 'es-modules/package-without-type/module.js' ) ,
415+ ] , { cwd : fixtures . fileURL ( 'es-module-loaders/' ) } ) ;
416+
417+ strictEqual ( stderr , '' ) ;
418+ strictEqual ( stdout , `
419+ Resolved format: module
420+ Loaded original format: module
421+ executed
422+ Evaluated format: commonjs
423+ ` . replace ( / ^ \s + / gm, '' ) ) ;
424+ strictEqual ( code , 0 ) ;
425+ strictEqual ( signal , null ) ;
426+ } ) ;
427+
428+ it ( 'should throw the usual error for a missing file' , async ( ) => {
429+ const { code, signal, stdout, stderr } = await spawnPromisified ( process . execPath , [
430+ '--no-warnings' ,
431+ '--experimental-detect-module' ,
432+ '--import' ,
433+ `data:text/javascript,${ encodeURIComponent (
434+ 'import { register } from "node:module";' +
435+ 'import { pathToFileURL } from "node:url";' +
436+ 'register("./transpile-esm-to-cjs.mjs", pathToFileURL("./"));'
437+ ) } `,
438+ fixtures . path ( 'es-modules/package-without-type/imports-nonexistent.js' ) ,
439+ ] , { cwd : fixtures . fileURL ( 'es-module-loaders/' ) } ) ;
440+
441+ match ( stderr , / E R R _ M O D U L E _ N O T _ F O U N D .+ d o e s - n o t - e x i s t \. j s / ) ;
442+ strictEqual ( stdout , 'Resolved format: module\nLoaded original format: module\n' ) ;
443+ strictEqual ( code , 1 ) ;
444+ strictEqual ( signal , null ) ;
445+ } ) ;
446+ } ) ;
388447} ) ;
389448
390449// Validate temporarily disabling `--abort-on-uncaught-exception`
0 commit comments