@@ -195,4 +195,52 @@ describe('Loader hooks', { concurrency: true }, () => {
195
195
assert . strictEqual ( code , 0 ) ;
196
196
assert . strictEqual ( signal , null ) ;
197
197
} ) ;
198
+
199
+ it ( 'should be fine to call `process.exit` from a custom async hook' , async ( ) => {
200
+ const { code, signal, stdout, stderr } = await spawnPromisified ( execPath , [
201
+ '--no-warnings' ,
202
+ '--experimental-import-meta-resolve' ,
203
+ '--experimental-loader' ,
204
+ 'data:text/javascript,export function load(a,b,next){if(a==="data:exit")process.exit(42);return next(a,b)}' ,
205
+ '--input-type=module' ,
206
+ '--eval' ,
207
+ 'import "data:exit"' ,
208
+ ] ) ;
209
+
210
+ assert . strictEqual ( stderr , '' ) ;
211
+ assert . strictEqual ( stdout , '' ) ;
212
+ assert . strictEqual ( code , 42 ) ;
213
+ assert . strictEqual ( signal , null ) ;
214
+ } ) ;
215
+
216
+ it ( 'should be fine to call `process.exit` from a custom sync hook' , async ( ) => {
217
+ const { code, signal, stdout, stderr } = await spawnPromisified ( execPath , [
218
+ '--no-warnings' ,
219
+ '--experimental-import-meta-resolve' ,
220
+ '--experimental-loader' ,
221
+ 'data:text/javascript,export function resolve(a,b,next){if(a==="exit:")process.exit(42);return next(a,b)}' ,
222
+ '--input-type=module' ,
223
+ '--eval' ,
224
+ 'import "data:text/javascript,import.meta.resolve(%22exit:%22)"' ,
225
+ ] ) ;
226
+
227
+ assert . strictEqual ( stderr , '' ) ;
228
+ assert . strictEqual ( stdout , '' ) ;
229
+ assert . strictEqual ( code , 42 ) ;
230
+ assert . strictEqual ( signal , null ) ;
231
+ } ) ;
232
+
233
+ it ( 'should be fine to call `process.exit` from the loader thread top-level' , async ( ) => {
234
+ const { code, signal, stdout, stderr } = await spawnPromisified ( execPath , [
235
+ '--no-warnings' ,
236
+ '--experimental-loader' ,
237
+ 'data:text/javascript,process.exit(42)' ,
238
+ fixtures . path ( 'empty.js' ) ,
239
+ ] ) ;
240
+
241
+ assert . strictEqual ( stderr , '' ) ;
242
+ assert . strictEqual ( stdout , '' ) ;
243
+ assert . strictEqual ( code , 42 ) ;
244
+ assert . strictEqual ( signal , null ) ;
245
+ } ) ;
198
246
} ) ;
0 commit comments