@@ -143,4 +143,52 @@ describe('Loader hooks', { concurrency: true }, () => {
143143 assert . strictEqual ( code , 0 ) ;
144144 assert . strictEqual ( signal , null ) ;
145145 } ) ;
146+
147+ it ( 'should be fine to call `process.exit` from a custom async hook' , async ( ) => {
148+ const { code, signal, stdout, stderr } = await spawnPromisified ( execPath , [
149+ '--no-warnings' ,
150+ '--experimental-import-meta-resolve' ,
151+ '--experimental-loader' ,
152+ 'data:text/javascript,export function load(a,b,next){if(a==="data:exit")process.exit(42);return next(a,b)}' ,
153+ '--input-type=module' ,
154+ '--eval' ,
155+ 'import "data:exit"' ,
156+ ] ) ;
157+
158+ assert . strictEqual ( stderr , '' ) ;
159+ assert . strictEqual ( stdout , '' ) ;
160+ assert . strictEqual ( code , 42 ) ;
161+ assert . strictEqual ( signal , null ) ;
162+ } ) ;
163+
164+ it ( 'should be fine to call `process.exit` from a custom sync hook' , async ( ) => {
165+ const { code, signal, stdout, stderr } = await spawnPromisified ( execPath , [
166+ '--no-warnings' ,
167+ '--experimental-import-meta-resolve' ,
168+ '--experimental-loader' ,
169+ 'data:text/javascript,export function resolve(a,b,next){if(a==="exit:")process.exit(42);return next(a,b)}' ,
170+ '--input-type=module' ,
171+ '--eval' ,
172+ 'import "data:text/javascript,import.meta.resolve(%22exit:%22)"' ,
173+ ] ) ;
174+
175+ assert . strictEqual ( stderr , '' ) ;
176+ assert . strictEqual ( stdout , '' ) ;
177+ assert . strictEqual ( code , 42 ) ;
178+ assert . strictEqual ( signal , null ) ;
179+ } ) ;
180+
181+ it ( 'should be fine to call `process.exit` from the loader thread top-level' , async ( ) => {
182+ const { code, signal, stdout, stderr } = await spawnPromisified ( execPath , [
183+ '--no-warnings' ,
184+ '--experimental-loader' ,
185+ 'data:text/javascript,process.exit(42)' ,
186+ fixtures . path ( 'empty.js' ) ,
187+ ] ) ;
188+
189+ assert . strictEqual ( stderr , '' ) ;
190+ assert . strictEqual ( stdout , '' ) ;
191+ assert . strictEqual ( code , 42 ) ;
192+ assert . strictEqual ( signal , null ) ;
193+ } ) ;
146194} ) ;
0 commit comments