@@ -10,8 +10,8 @@ describe('Loader hooks', { concurrency: true }, () => {
10
10
const { code, signal, stdout, stderr } = await spawnPromisified ( execPath , [
11
11
'--no-warnings' ,
12
12
'--experimental-loader' ,
13
- fixtures . fileURL ( '/ es-module-loaders/hooks-input.mjs' ) ,
14
- fixtures . path ( '/ es-modules/json-modules.mjs' ) ,
13
+ fixtures . fileURL ( 'es-module-loaders/hooks-input.mjs' ) ,
14
+ fixtures . path ( 'es-modules/json-modules.mjs' ) ,
15
15
] ) ;
16
16
17
17
assert . strictEqual ( stderr , '' ) ;
@@ -23,6 +23,8 @@ describe('Loader hooks', { concurrency: true }, () => {
23
23
assert . match ( lines [ 1 ] , / { " s o u r c e " : { " t y p e " : " B u f f e r " , " d a t a " : \[ .* \] } , " f o r m a t " : " m o d u l e " , " s h o r t C i r c u i t " : t r u e } / ) ;
24
24
assert . match ( lines [ 2 ] , / { " u r l " : " f i l e : \/ \/ \/ .* \/ e x p e r i m e n t a l \. j s o n " , " f o r m a t " : " t e s t " , " s h o r t C i r c u i t " : t r u e } / ) ;
25
25
assert . match ( lines [ 3 ] , / { " s o u r c e " : { " t y p e " : " B u f f e r " , " d a t a " : \[ .* \] } , " f o r m a t " : " j s o n " , " s h o r t C i r c u i t " : t r u e } / ) ;
26
+ assert . strictEqual ( lines [ 4 ] , '' ) ;
27
+ assert . strictEqual ( lines . length , 5 ) ;
26
28
} ) ;
27
29
28
30
it ( 'are called with all expected arguments using register function' , async ( ) => {
@@ -32,8 +34,8 @@ describe('Loader hooks', { concurrency: true }, () => {
32
34
'--input-type=module' ,
33
35
'--eval' ,
34
36
"import { register } from 'node:module';" +
35
- `register(${ JSON . stringify ( fixtures . fileURL ( '/ es-module-loaders/hooks-input.mjs' ) ) } );` +
36
- `await import(${ JSON . stringify ( fixtures . fileURL ( '/ es-modules/json-modules.mjs' ) ) } );` ,
37
+ `register(${ JSON . stringify ( fixtures . fileURL ( 'es-module-loaders/hooks-input.mjs' ) ) } );` +
38
+ `await import(${ JSON . stringify ( fixtures . fileURL ( 'es-modules/json-modules.mjs' ) ) } );` ,
37
39
] ) ;
38
40
39
41
assert . strictEqual ( stderr , '' ) ;
@@ -45,6 +47,8 @@ describe('Loader hooks', { concurrency: true }, () => {
45
47
assert . match ( lines [ 1 ] , / { " s o u r c e " : { " t y p e " : " B u f f e r " , " d a t a " : \[ .* \] } , " f o r m a t " : " m o d u l e " , " s h o r t C i r c u i t " : t r u e } / ) ;
46
48
assert . match ( lines [ 2 ] , / { " u r l " : " f i l e : \/ \/ \/ .* \/ e x p e r i m e n t a l \. j s o n " , " f o r m a t " : " t e s t " , " s h o r t C i r c u i t " : t r u e } / ) ;
47
49
assert . match ( lines [ 3 ] , / { " s o u r c e " : { " t y p e " : " B u f f e r " , " d a t a " : \[ .* \] } , " f o r m a t " : " j s o n " , " s h o r t C i r c u i t " : t r u e } / ) ;
50
+ assert . strictEqual ( lines [ 4 ] , '' ) ;
51
+ assert . strictEqual ( lines . length , 5 ) ;
48
52
} ) ;
49
53
50
54
describe ( 'should handle never-settling hooks in ESM files' , { concurrency : true } , ( ) => {
@@ -392,7 +396,6 @@ describe('Loader hooks', { concurrency: true }, () => {
392
396
393
397
it ( 'should handle symbol' , async ( ) => {
394
398
const { code, signal, stdout } = await spawnPromisified ( execPath , [
395
- '--no-warnings' ,
396
399
'--experimental-loader' ,
397
400
'data:text/javascript,throw Symbol("symbol descriptor")' ,
398
401
fixtures . path ( 'empty.js' ) ,
@@ -564,19 +567,14 @@ describe('Loader hooks', { concurrency: true }, () => {
564
567
const { code, signal, stdout, stderr } = await spawnPromisified ( execPath , [
565
568
'--no-warnings' ,
566
569
'--experimental-loader' ,
567
- fixtures . fileURL ( '/ es-module-loaders/hooks-initialize.mjs' ) ,
570
+ fixtures . fileURL ( 'es-module-loaders/hooks-initialize.mjs' ) ,
568
571
'--input-type=module' ,
569
572
'--eval' ,
570
573
'import os from "node:os";' ,
571
574
] ) ;
572
575
573
- const lines = stdout . trim ( ) . split ( '\n' ) ;
574
-
575
- assert . strictEqual ( lines . length , 1 ) ;
576
- assert . strictEqual ( lines [ 0 ] , 'hooks initialize 1' ) ;
577
-
578
576
assert . strictEqual ( stderr , '' ) ;
579
-
577
+ assert . deepStrictEqual ( stdout . split ( '\n' ) , [ 'hooks initialize 1' , '' ] ) ;
580
578
assert . strictEqual ( code , 0 ) ;
581
579
assert . strictEqual ( signal , null ) ;
582
580
} ) ;
@@ -607,7 +605,10 @@ describe('Loader hooks', { concurrency: true }, () => {
607
605
] ) ;
608
606
609
607
assert . strictEqual ( stderr , '' ) ;
610
- assert . deepStrictEqual ( stdout . split ( '\n' ) , [ 'register ok' , 'message initialize' , 'message resolve node:os' , '' ] ) ;
608
+ assert . deepStrictEqual ( stdout . split ( '\n' ) , [ 'register ok' ,
609
+ 'message initialize' ,
610
+ 'message resolve node:os' ,
611
+ '' ] ) ;
611
612
612
613
assert . strictEqual ( code , 0 ) ;
613
614
assert . strictEqual ( signal , null ) ;
@@ -645,18 +646,14 @@ describe('Loader hooks', { concurrency: true }, () => {
645
646
const { code, signal, stdout, stderr } = await spawnPromisified ( execPath , [
646
647
'--no-warnings' ,
647
648
'--require' ,
648
- fixtures . path ( '/ es-module-loaders/register-loader.cjs' ) ,
649
+ fixtures . path ( 'es-module-loaders/register-loader.cjs' ) ,
649
650
'--input-type=module' ,
650
651
'--eval' ,
651
652
'import "node:os";' ,
652
653
] ) ;
653
654
654
- const lines = stdout . split ( '\n' ) ;
655
-
656
- assert . strictEqual ( lines [ 0 ] , 'resolve passthru' ) ;
657
-
658
655
assert . strictEqual ( stderr , '' ) ;
659
-
656
+ assert . deepStrictEqual ( stdout . split ( '\n' ) , [ 'resolve passthru' , 'resolve passthru' , '' ] ) ;
660
657
assert . strictEqual ( code , 0 ) ;
661
658
assert . strictEqual ( signal , null ) ;
662
659
} ) ;
@@ -665,20 +662,16 @@ describe('Loader hooks', { concurrency: true }, () => {
665
662
const { code, signal, stdout, stderr } = await spawnPromisified ( execPath , [
666
663
'--no-warnings' ,
667
664
'--import' ,
668
- fixtures . fileURL ( '/ es-module-loaders/register-loader.mjs' ) ,
665
+ fixtures . fileURL ( 'es-module-loaders/register-loader.mjs' ) ,
669
666
'--input-type=module' ,
670
667
'--eval' ,
671
668
`
672
669
import 'node:os';
673
670
` ,
674
671
] ) ;
675
672
676
- const lines = stdout . split ( '\n' ) ;
677
-
678
- assert . strictEqual ( lines [ 0 ] , 'resolve passthru' ) ;
679
-
680
673
assert . strictEqual ( stderr , '' ) ;
681
-
674
+ assert . deepStrictEqual ( stdout . split ( '\n' ) , [ 'resolve passthru' , '' ] ) ;
682
675
assert . strictEqual ( code , 0 ) ;
683
676
assert . strictEqual ( signal , null ) ;
684
677
} ) ;
@@ -691,24 +684,22 @@ describe('Loader hooks', { concurrency: true }, () => {
691
684
`
692
685
import {register} from 'node:module';
693
686
console.log('result', register(
694
- ${ JSON . stringify ( fixtures . fileURL ( '/ es-module-loaders/hooks-initialize.mjs' ) ) }
687
+ ${ JSON . stringify ( fixtures . fileURL ( 'es-module-loaders/hooks-initialize.mjs' ) ) }
695
688
));
696
689
console.log('result', register(
697
- ${ JSON . stringify ( fixtures . fileURL ( '/ es-module-loaders/hooks-initialize.mjs' ) ) }
690
+ ${ JSON . stringify ( fixtures . fileURL ( 'es-module-loaders/hooks-initialize.mjs' ) ) }
698
691
));
699
692
700
693
await import('node:os');
701
694
` ,
702
695
] ) ;
703
696
704
- const lines = stdout . split ( '\n' ) ;
705
-
706
- assert . strictEqual ( lines [ 0 ] , 'result 1' ) ;
707
- assert . strictEqual ( lines [ 1 ] , 'result 2' ) ;
708
- assert . strictEqual ( lines [ 2 ] , 'hooks initialize 1' ) ;
709
- assert . strictEqual ( lines [ 3 ] , 'hooks initialize 2' ) ;
710
-
711
697
assert . strictEqual ( stderr , '' ) ;
698
+ assert . deepStrictEqual ( stdout . split ( '\n' ) , [ 'result 1' ,
699
+ 'result 2' ,
700
+ 'hooks initialize 1' ,
701
+ 'hooks initialize 2' ,
702
+ '' ] ) ;
712
703
assert . strictEqual ( code , 0 ) ;
713
704
assert . strictEqual ( signal , null ) ;
714
705
} ) ;
0 commit comments