@@ -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' ) ,
@@ -576,19 +579,14 @@ describe('Loader hooks', { concurrency: true }, () => {
576
579
const { code, signal, stdout, stderr } = await spawnPromisified ( execPath , [
577
580
'--no-warnings' ,
578
581
'--experimental-loader' ,
579
- fixtures . fileURL ( '/ es-module-loaders/hooks-initialize.mjs' ) ,
582
+ fixtures . fileURL ( 'es-module-loaders/hooks-initialize.mjs' ) ,
580
583
'--input-type=module' ,
581
584
'--eval' ,
582
585
'import os from "node:os";' ,
583
586
] ) ;
584
587
585
- const lines = stdout . trim ( ) . split ( '\n' ) ;
586
-
587
- assert . strictEqual ( lines . length , 1 ) ;
588
- assert . strictEqual ( lines [ 0 ] , 'hooks initialize 1' ) ;
589
-
590
588
assert . strictEqual ( stderr , '' ) ;
591
-
589
+ assert . deepStrictEqual ( stdout . split ( '\n' ) , [ 'hooks initialize 1' , '' ] ) ;
592
590
assert . strictEqual ( code , 0 ) ;
593
591
assert . strictEqual ( signal , null ) ;
594
592
} ) ;
@@ -619,7 +617,10 @@ describe('Loader hooks', { concurrency: true }, () => {
619
617
] ) ;
620
618
621
619
assert . strictEqual ( stderr , '' ) ;
622
- assert . deepStrictEqual ( stdout . split ( '\n' ) , [ 'register ok' , 'message initialize' , 'message resolve node:os' , '' ] ) ;
620
+ assert . deepStrictEqual ( stdout . split ( '\n' ) , [ 'register ok' ,
621
+ 'message initialize' ,
622
+ 'message resolve node:os' ,
623
+ '' ] ) ;
623
624
624
625
assert . strictEqual ( code , 0 ) ;
625
626
assert . strictEqual ( signal , null ) ;
@@ -657,18 +658,14 @@ describe('Loader hooks', { concurrency: true }, () => {
657
658
const { code, signal, stdout, stderr } = await spawnPromisified ( execPath , [
658
659
'--no-warnings' ,
659
660
'--require' ,
660
- fixtures . path ( '/ es-module-loaders/register-loader.cjs' ) ,
661
+ fixtures . path ( 'es-module-loaders/register-loader.cjs' ) ,
661
662
'--input-type=module' ,
662
663
'--eval' ,
663
664
'import "node:os";' ,
664
665
] ) ;
665
666
666
- const lines = stdout . split ( '\n' ) ;
667
-
668
- assert . strictEqual ( lines [ 0 ] , 'resolve passthru' ) ;
669
-
670
667
assert . strictEqual ( stderr , '' ) ;
671
-
668
+ assert . deepStrictEqual ( stdout . split ( '\n' ) , [ 'resolve passthru' , 'resolve passthru' , '' ] ) ;
672
669
assert . strictEqual ( code , 0 ) ;
673
670
assert . strictEqual ( signal , null ) ;
674
671
} ) ;
@@ -677,20 +674,16 @@ describe('Loader hooks', { concurrency: true }, () => {
677
674
const { code, signal, stdout, stderr } = await spawnPromisified ( execPath , [
678
675
'--no-warnings' ,
679
676
'--import' ,
680
- fixtures . fileURL ( '/ es-module-loaders/register-loader.mjs' ) ,
677
+ fixtures . fileURL ( 'es-module-loaders/register-loader.mjs' ) ,
681
678
'--input-type=module' ,
682
679
'--eval' ,
683
680
`
684
681
import 'node:os';
685
682
` ,
686
683
] ) ;
687
684
688
- const lines = stdout . split ( '\n' ) ;
689
-
690
- assert . strictEqual ( lines [ 0 ] , 'resolve passthru' ) ;
691
-
692
685
assert . strictEqual ( stderr , '' ) ;
693
-
686
+ assert . deepStrictEqual ( stdout . split ( '\n' ) , [ 'resolve passthru' , '' ] ) ;
694
687
assert . strictEqual ( code , 0 ) ;
695
688
assert . strictEqual ( signal , null ) ;
696
689
} ) ;
@@ -703,24 +696,22 @@ describe('Loader hooks', { concurrency: true }, () => {
703
696
`
704
697
import {register} from 'node:module';
705
698
console.log('result', register(
706
- ${ JSON . stringify ( fixtures . fileURL ( '/ es-module-loaders/hooks-initialize.mjs' ) ) }
699
+ ${ JSON . stringify ( fixtures . fileURL ( 'es-module-loaders/hooks-initialize.mjs' ) ) }
707
700
));
708
701
console.log('result', register(
709
- ${ JSON . stringify ( fixtures . fileURL ( '/ es-module-loaders/hooks-initialize.mjs' ) ) }
702
+ ${ JSON . stringify ( fixtures . fileURL ( 'es-module-loaders/hooks-initialize.mjs' ) ) }
710
703
));
711
704
712
705
await import('node:os');
713
706
` ,
714
707
] ) ;
715
708
716
- const lines = stdout . split ( '\n' ) ;
717
-
718
- assert . strictEqual ( lines [ 0 ] , 'result 1' ) ;
719
- assert . strictEqual ( lines [ 1 ] , 'result 2' ) ;
720
- assert . strictEqual ( lines [ 2 ] , 'hooks initialize 1' ) ;
721
- assert . strictEqual ( lines [ 3 ] , 'hooks initialize 2' ) ;
722
-
723
709
assert . strictEqual ( stderr , '' ) ;
710
+ assert . deepStrictEqual ( stdout . split ( '\n' ) , [ 'result 1' ,
711
+ 'result 2' ,
712
+ 'hooks initialize 1' ,
713
+ 'hooks initialize 2' ,
714
+ '' ] ) ;
724
715
assert . strictEqual ( code , 0 ) ;
725
716
assert . strictEqual ( signal , null ) ;
726
717
} ) ;
0 commit comments