@@ -35,4 +35,40 @@ describe('off-thread hooks', { concurrency: true }, () => {
3535 strictEqual ( code , 0 ) ;
3636 strictEqual ( signal , null ) ;
3737 } ) ;
38+
39+ it ( 'propagates the exit code from worker thread import exiting from resolve hook' , async ( ) => {
40+ const { code, signal, stdout, stderr } = await spawnPromisified ( execPath , [
41+ '--no-warnings' ,
42+ '--import' ,
43+ `data:text/javascript,${ encodeURIComponent ( `
44+ import { register } from 'node:module';
45+ register(${ JSON . stringify ( fixtures . fileURL ( 'es-module-loaders/hooks-exit-worker.mjs' ) ) } );
46+ ` ) } `,
47+ fixtures . path ( 'es-module-loaders/worker-log-fail-worker-resolve.mjs' ) ,
48+ ] ) ;
49+
50+ strictEqual ( stderr , '' ) ;
51+ strictEqual ( stdout . split ( '\n' ) . filter ( ( line ) => line . startsWith ( 'resolve process-exit-module-resolve' ) ) . length , 1 ) ;
52+ strictEqual ( code , 42 ) ;
53+ strictEqual ( signal , null ) ;
54+ } ) ;
55+
56+ it ( 'propagates the exit code from worker thread import exiting from load hook' , async ( ) => {
57+ const { code, signal, stdout, stderr } = await spawnPromisified ( execPath , [
58+ '--no-warnings' ,
59+ '--import' ,
60+ `data:text/javascript,${ encodeURIComponent ( `
61+ import { register } from 'node:module';
62+ register(${ JSON . stringify ( fixtures . fileURL ( 'es-module-loaders/hooks-exit-worker.mjs' ) ) } );
63+ ` ) } `,
64+ fixtures . path ( 'es-module-loaders/worker-log-fail-worker-load.mjs' ) ,
65+ ] ) ;
66+
67+ strictEqual ( stderr , '' ) ;
68+ strictEqual ( stdout . split ( '\n' ) . filter ( ( line ) => line . startsWith ( 'resolve process-exit-module-load' ) ) . length , 1 ) ;
69+ strictEqual ( stdout . split ( '\n' ) . filter ( ( line ) => line . startsWith ( 'load process-exit-on-load:///' ) ) . length , 1 ) ;
70+ strictEqual ( code , 43 ) ;
71+ strictEqual ( signal , null ) ;
72+ } ) ;
73+
3874} ) ;
0 commit comments