@@ -737,6 +737,39 @@ describe('Loader hooks', { concurrency: true }, () => {
737
737
assert . strictEqual ( signal , null ) ;
738
738
} ) ;
739
739
740
+ it ( 'should support source maps in commonjs translator' , async ( ) => {
741
+ const readFile = async ( ) => { } ;
742
+ const hook = `
743
+ import { readFile } from 'node:fs/promises';
744
+ export ${
745
+ async function load ( url , context , nextLoad ) {
746
+ const resolved = await nextLoad ( url , context ) ;
747
+ if ( context . format === 'commonjs' ) {
748
+ resolved . source = await readFile ( new URL ( url ) ) ;
749
+ }
750
+ return resolved ;
751
+ }
752
+ } `;
753
+
754
+ const { code, signal, stdout, stderr } = await spawnPromisified ( execPath , [
755
+ '--no-warnings' ,
756
+ '--enable-source-maps' ,
757
+ '--import' ,
758
+ `data:text/javascript,${ encodeURIComponent ( `
759
+ import{ register } from "node:module";
760
+ register(${
761
+ JSON . stringify ( 'data:text/javascript,' + encodeURIComponent ( hook ) )
762
+ } );
763
+ ` ) } `,
764
+ fixtures . path ( 'source-map/throw-on-require.js' ) ,
765
+ ] ) ;
766
+
767
+ assert . strictEqual ( stdout , '' ) ;
768
+ assert . match ( stderr , / t h r o w - o n - r e q u i r e \. t s : 9 : 9 / ) ;
769
+ assert . strictEqual ( code , 1 ) ;
770
+ assert . strictEqual ( signal , null ) ;
771
+ } ) ;
772
+
740
773
it ( 'should handle mixed of opt-in modules and non-opt-in ones' , async ( ) => {
741
774
const { code, signal, stdout, stderr } = await spawnPromisified ( execPath , [
742
775
'--no-warnings' ,
0 commit comments