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