@@ -419,143 +419,6 @@ describe('Loader hooks', { concurrency: true }, () => {
419
419
} ) ;
420
420
} ) ;
421
421
422
- describe ( 'globalPreload' , ( ) => {
423
- it ( 'should emit deprecation warning' , async ( ) => {
424
- const { stderr } = await spawnPromisified ( execPath , [
425
- '--experimental-loader' ,
426
- 'data:text/javascript,export function globalPreload(){}' ,
427
- '--experimental-loader' ,
428
- 'data:text/javascript,export function globalPreload(){return""}' ,
429
- fixtures . path ( 'empty.js' ) ,
430
- ] ) ;
431
-
432
- assert . strictEqual ( stderr . match ( / ` g l o b a l P r e l o a d ` i s a n e x p e r i m e n t a l f e a t u r e / g) . length , 1 ) ;
433
- } ) ;
434
-
435
- it ( 'should not emit deprecation warning when initialize is supplied' , async ( ) => {
436
- const { stderr } = await spawnPromisified ( execPath , [
437
- '--experimental-loader' ,
438
- 'data:text/javascript,export function globalPreload(){}export function initialize(){}' ,
439
- fixtures . path ( 'empty.js' ) ,
440
- ] ) ;
441
-
442
- assert . doesNotMatch ( stderr , / ` g l o b a l P r e l o a d ` i s a n e x p e r i m e n t a l f e a t u r e / ) ;
443
- } ) ;
444
-
445
- it ( 'should handle globalPreload returning undefined' , async ( ) => {
446
- const { code, signal, stdout, stderr } = await spawnPromisified ( execPath , [
447
- '--no-warnings' ,
448
- '--experimental-loader' ,
449
- 'data:text/javascript,export function globalPreload(){}' ,
450
- fixtures . path ( 'empty.js' ) ,
451
- ] ) ;
452
-
453
- assert . strictEqual ( stderr , '' ) ;
454
- assert . strictEqual ( stdout , '' ) ;
455
- assert . strictEqual ( code , 0 ) ;
456
- assert . strictEqual ( signal , null ) ;
457
- } ) ;
458
-
459
- it ( 'should handle loading node:test' , async ( ) => {
460
- const { code, signal, stdout, stderr } = await spawnPromisified ( execPath , [
461
- '--no-warnings' ,
462
- '--experimental-loader' ,
463
- 'data:text/javascript,export function globalPreload(){return `getBuiltin("node:test")()`}' ,
464
- fixtures . path ( 'empty.js' ) ,
465
- ] ) ;
466
-
467
- assert . strictEqual ( stderr , '' ) ;
468
- assert . match ( stdout , / \n # p a s s 1 \r ? \n / ) ;
469
- assert . strictEqual ( code , 0 ) ;
470
- assert . strictEqual ( signal , null ) ;
471
- } ) ;
472
-
473
- it ( 'should handle loading node:os with node: prefix' , async ( ) => {
474
- const { code, signal, stdout, stderr } = await spawnPromisified ( execPath , [
475
- '--no-warnings' ,
476
- '--experimental-loader' ,
477
- 'data:text/javascript,export function globalPreload(){return `console.log(getBuiltin("node:os").arch())`}' ,
478
- fixtures . path ( 'empty.js' ) ,
479
- ] ) ;
480
-
481
- assert . strictEqual ( stderr , '' ) ;
482
- assert . strictEqual ( stdout . trim ( ) , os . arch ( ) ) ;
483
- assert . strictEqual ( code , 0 ) ;
484
- assert . strictEqual ( signal , null ) ;
485
- } ) ;
486
-
487
- // `os` is used here because it's simple and not mocked (the builtin module otherwise doesn't matter).
488
- it ( 'should handle loading builtin module without node: prefix' , async ( ) => {
489
- const { code, signal, stdout, stderr } = await spawnPromisified ( execPath , [
490
- '--no-warnings' ,
491
- '--experimental-loader' ,
492
- 'data:text/javascript,export function globalPreload(){return `console.log(getBuiltin("os").arch())`}' ,
493
- fixtures . path ( 'empty.js' ) ,
494
- ] ) ;
495
-
496
- assert . strictEqual ( stderr , '' ) ;
497
- assert . strictEqual ( stdout . trim ( ) , os . arch ( ) ) ;
498
- assert . strictEqual ( code , 0 ) ;
499
- assert . strictEqual ( signal , null ) ;
500
- } ) ;
501
-
502
- it ( 'should throw when loading node:test without node: prefix' , async ( ) => {
503
- const { code, signal, stdout, stderr } = await spawnPromisified ( execPath , [
504
- '--no-warnings' ,
505
- '--experimental-loader' ,
506
- 'data:text/javascript,export function globalPreload(){return `getBuiltin("test")()`}' ,
507
- fixtures . path ( 'empty.js' ) ,
508
- ] ) ;
509
-
510
- assert . match ( stderr , / E R R _ U N K N O W N _ B U I L T I N _ M O D U L E / ) ;
511
- assert . strictEqual ( stdout , '' ) ;
512
- assert . strictEqual ( code , 1 ) ;
513
- assert . strictEqual ( signal , null ) ;
514
- } ) ;
515
-
516
- it ( 'should register globals set from globalPreload' , async ( ) => {
517
- const { code, signal, stdout, stderr } = await spawnPromisified ( execPath , [
518
- '--no-warnings' ,
519
- '--experimental-loader' ,
520
- 'data:text/javascript,export function globalPreload(){return "this.myGlobal=4"}' ,
521
- '--print' , 'myGlobal' ,
522
- ] ) ;
523
-
524
- assert . strictEqual ( stderr , '' ) ;
525
- assert . strictEqual ( stdout . trim ( ) , '4' ) ;
526
- assert . strictEqual ( code , 0 ) ;
527
- assert . strictEqual ( signal , null ) ;
528
- } ) ;
529
-
530
- it ( 'should log console.log calls returned from globalPreload' , async ( ) => {
531
- const { code, signal, stdout, stderr } = await spawnPromisified ( execPath , [
532
- '--no-warnings' ,
533
- '--experimental-loader' ,
534
- 'data:text/javascript,export function globalPreload(){return `console.log("Hello from globalPreload")`}' ,
535
- fixtures . path ( 'empty.js' ) ,
536
- ] ) ;
537
-
538
- assert . strictEqual ( stderr , '' ) ;
539
- assert . strictEqual ( stdout . trim ( ) , 'Hello from globalPreload' ) ;
540
- assert . strictEqual ( code , 0 ) ;
541
- assert . strictEqual ( signal , null ) ;
542
- } ) ;
543
-
544
- it ( 'should crash if globalPreload returns code that throws' , async ( ) => {
545
- const { code, signal, stdout, stderr } = await spawnPromisified ( execPath , [
546
- '--no-warnings' ,
547
- '--experimental-loader' ,
548
- 'data:text/javascript,export function globalPreload(){return `throw new Error("error from globalPreload")`}' ,
549
- fixtures . path ( 'empty.js' ) ,
550
- ] ) ;
551
-
552
- assert . match ( stderr , / e r r o r f r o m g l o b a l P r e l o a d / ) ;
553
- assert . strictEqual ( stdout , '' ) ;
554
- assert . strictEqual ( code , 1 ) ;
555
- assert . strictEqual ( signal , null ) ;
556
- } ) ;
557
- } ) ;
558
-
559
422
it ( 'should be fine to call `process.removeAllListeners("beforeExit")` from the main thread' , async ( ) => {
560
423
const { code, signal, stdout, stderr } = await spawnPromisified ( execPath , [
561
424
'--no-warnings' ,
@@ -625,7 +488,7 @@ describe('Loader hooks', { concurrency: true }, () => {
625
488
assert . strictEqual ( signal , null ) ;
626
489
} ) ;
627
490
628
- it ( 'should have `register` work with cjs' , async ( ) => {
491
+ it ( 'should `register` from cjs' , async ( ) => {
629
492
const { code, signal, stdout, stderr } = await spawnPromisified ( execPath , [
630
493
'--no-warnings' ,
631
494
'--input-type=commonjs' ,
0 commit comments