@@ -25,8 +25,8 @@ const commonArgs = [
25
25
) ;
26
26
27
27
assert . strictEqual ( stderr , '' ) ;
28
- assert . strictEqual ( status , 0 ) ;
29
28
assert . match ( stdout , / n u m b e r / ) ; // node:fs is an object
29
+ assert . strictEqual ( status , 0 ) ;
30
30
}
31
31
32
32
{ // Verify loaded source is properly different when only load changes something
@@ -47,8 +47,8 @@ const commonArgs = [
47
47
assert . strictEqual ( stderr , '' ) ;
48
48
assert . match ( stdout , / l o a d p a s s t h r u / ) ;
49
49
assert . match ( stdout , / r e s o l v e p a s s t h r u / ) ;
50
- assert . strictEqual ( status , 0 ) ;
51
50
assert . match ( stdout , / f o o / ) ;
51
+ assert . strictEqual ( status , 0 ) ;
52
52
}
53
53
54
54
{ // Verify multiple changes from hooks result in proper output
@@ -70,8 +70,8 @@ const commonArgs = [
70
70
71
71
assert . strictEqual ( stderr , '' ) ;
72
72
assert . match ( stdout , / r e s o l v e 4 2 / ) ; // It did go thru resolve-42
73
- assert . strictEqual ( status , 0 ) ;
74
73
assert . match ( stdout , / f o o / ) ; // LIFO, so resolve-foo won
74
+ assert . strictEqual ( status , 0 ) ;
75
75
}
76
76
77
77
{ // Verify modifying context within resolve chain is respected
@@ -117,8 +117,52 @@ const commonArgs = [
117
117
118
118
assert . strictEqual ( stderr , '' ) ;
119
119
assert . match ( stdout , / r e s o l v e f o o / ) ; // It did go thru resolve-foo
120
- assert . strictEqual ( status , 0 ) ;
121
120
assert . match ( stdout , / 4 2 / ) ; // LIFO, so resolve-42 won
121
+ assert . strictEqual ( status , 0 ) ;
122
+ }
123
+
124
+ { // Verify multiple calls to next within same loader receive correct "next" fn
125
+ const { status, stderr, stdout } = spawnSync (
126
+ process . execPath ,
127
+ [
128
+ '--loader' ,
129
+ fixtures . fileURL ( 'es-module-loaders' , 'loader-resolve-shortcircuit.mjs' ) ,
130
+ '--loader' ,
131
+ fixtures . fileURL ( 'es-module-loaders' , 'loader-resolve-foo.mjs' ) ,
132
+ '--loader' ,
133
+ fixtures . fileURL ( 'es-module-loaders' , 'loader-resolve-multiple-next-calls.mjs' ) ,
134
+ '--loader' ,
135
+ fixtures . fileURL ( 'es-module-loaders' , 'loader-load-foo-or-42.mjs' ) ,
136
+ ...commonArgs ,
137
+ ] ,
138
+ { encoding : 'utf8' } ,
139
+ ) ;
140
+
141
+ const countFoos = stdout . match ( / r e s o l v e f o o / g) ?. length ;
142
+
143
+ assert . strictEqual ( stderr , '' ) ;
144
+ assert . strictEqual ( countFoos , 2 ) ;
145
+ assert . strictEqual ( status , 0 ) ;
146
+ }
147
+
148
+ { // Verify next<HookName> function's `name` is correct
149
+ const { status, stderr, stdout } = spawnSync (
150
+ process . execPath ,
151
+ [
152
+ '--loader' ,
153
+ fixtures . fileURL ( 'es-module-loaders' , 'loader-resolve-shortcircuit.mjs' ) ,
154
+ '--loader' ,
155
+ fixtures . fileURL ( 'es-module-loaders' , 'loader-resolve-42.mjs' ) ,
156
+ '--loader' ,
157
+ fixtures . fileURL ( 'es-module-loaders' , 'loader-load-foo-or-42.mjs' ) ,
158
+ ...commonArgs ,
159
+ ] ,
160
+ { encoding : 'utf8' } ,
161
+ ) ;
162
+
163
+ assert . strictEqual ( stderr , '' ) ;
164
+ assert . match ( stdout , / n e x t < H o o k N a m e > : n e x t R e s o l v e / ) ;
165
+ assert . strictEqual ( status , 0 ) ;
122
166
}
123
167
124
168
{ // Verify error thrown for incomplete resolve chain, citing errant loader & hook
@@ -137,10 +181,10 @@ const commonArgs = [
137
181
) ;
138
182
139
183
assert . match ( stdout , / r e s o l v e p a s s t h r u / ) ;
140
- assert . strictEqual ( status , 1 ) ;
141
184
assert . match ( stderr , / E R R _ L O A D E R _ C H A I N _ I N C O M P L E T E / ) ;
142
185
assert . match ( stderr , / l o a d e r - r e s o l v e - i n c o m p l e t e \. m j s / ) ;
143
- assert . match ( stderr , / " r e s o l v e " / ) ;
186
+ assert . match ( stderr , / ' r e s o l v e ' / ) ;
187
+ assert . strictEqual ( status , 1 ) ;
144
188
}
145
189
146
190
{ // Verify error NOT thrown when nested resolve hook signaled a short circuit
@@ -201,10 +245,10 @@ const commonArgs = [
201
245
) ;
202
246
203
247
assert . doesNotMatch ( stdout , / r e s o l v e p a s s t h r u / ) ;
204
- assert . strictEqual ( status , 1 ) ;
205
248
assert . match ( stderr , / E R R _ L O A D E R _ C H A I N _ I N C O M P L E T E / ) ;
206
249
assert . match ( stderr , / l o a d e r - r e s o l v e - i n c o m p l e t e \. m j s / ) ;
207
- assert . match ( stderr , / " r e s o l v e " / ) ;
250
+ assert . match ( stderr , / ' r e s o l v e ' / ) ;
251
+ assert . strictEqual ( status , 1 ) ;
208
252
}
209
253
210
254
{ // Verify error thrown for incomplete load chain, citing errant loader & hook
@@ -223,10 +267,10 @@ const commonArgs = [
223
267
) ;
224
268
225
269
assert . match ( stdout , / l o a d p a s s t h r u / ) ;
226
- assert . strictEqual ( status , 1 ) ;
227
270
assert . match ( stderr , / E R R _ L O A D E R _ C H A I N _ I N C O M P L E T E / ) ;
228
271
assert . match ( stderr , / l o a d e r - l o a d - i n c o m p l e t e \. m j s / ) ;
229
- assert . match ( stderr , / " l o a d " / ) ;
272
+ assert . match ( stderr , / ' l o a d ' / ) ;
273
+ assert . strictEqual ( status , 1 ) ;
230
274
}
231
275
232
276
{ // Verify chain does break and throws appropriately
@@ -245,13 +289,13 @@ const commonArgs = [
245
289
) ;
246
290
247
291
assert . doesNotMatch ( stdout , / l o a d p a s s t h r u / ) ;
248
- assert . strictEqual ( status , 1 ) ;
249
292
assert . match ( stderr , / E R R _ L O A D E R _ C H A I N _ I N C O M P L E T E / ) ;
250
293
assert . match ( stderr , / l o a d e r - l o a d - i n c o m p l e t e \. m j s / ) ;
251
- assert . match ( stderr , / " l o a d " / ) ;
294
+ assert . match ( stderr , / ' l o a d ' / ) ;
295
+ assert . strictEqual ( status , 1 ) ;
252
296
}
253
297
254
- { // Verify error thrown when invalid `specifier` argument passed to `resolve…next `
298
+ { // Verify error thrown when invalid `specifier` argument passed to `nextResolve `
255
299
const { status, stderr } = spawnSync (
256
300
process . execPath ,
257
301
[
@@ -267,11 +311,10 @@ const commonArgs = [
267
311
assert . strictEqual ( status , 1 ) ;
268
312
assert . match ( stderr , / E R R _ I N V A L I D _ A R G _ T Y P E / ) ;
269
313
assert . match ( stderr , / l o a d e r - r e s o l v e - b a d - n e x t - s p e c i f i e r \. m j s / ) ;
270
- assert . match ( stderr , / " r e s o l v e " / ) ;
271
- assert . match ( stderr , / n e x t R e s o l v e \( s p e c i f i e r \) / ) ;
314
+ assert . match ( stderr , / ' r e s o l v e ' h o o k ' s n e x t R e s o l v e \( \) s p e c i f i e r / ) ;
272
315
}
273
316
274
- { // Verify error thrown when invalid `context` argument passed to `resolve…next `
317
+ { // Verify error thrown when invalid `context` argument passed to `nextResolve `
275
318
const { status, stderr } = spawnSync (
276
319
process . execPath ,
277
320
[
@@ -284,14 +327,13 @@ const commonArgs = [
284
327
{ encoding : 'utf8' } ,
285
328
) ;
286
329
287
- assert . strictEqual ( status , 1 ) ;
288
330
assert . match ( stderr , / E R R _ I N V A L I D _ A R G _ T Y P E / ) ;
289
331
assert . match ( stderr , / l o a d e r - r e s o l v e - b a d - n e x t - c o n t e x t \. m j s / ) ;
290
- assert . match ( stderr , / " r e s o l v e " / ) ;
291
- assert . match ( stderr , / n e x t R e s o l v e \( , c o n t e x t \) / ) ;
332
+ assert . match ( stderr , / ' r e s o l v e ' h o o k ' s n e x t R e s o l v e \( \) c o n t e x t / ) ;
333
+ assert . strictEqual ( status , 1 ) ;
292
334
}
293
335
294
- { // Verify error thrown when invalid `url` argument passed to `load…next `
336
+ { // Verify error thrown when invalid `url` argument passed to `nextLoad `
295
337
const { status, stderr } = spawnSync (
296
338
process . execPath ,
297
339
[
@@ -304,14 +346,13 @@ const commonArgs = [
304
346
{ encoding : 'utf8' } ,
305
347
) ;
306
348
307
- assert . strictEqual ( status , 1 ) ;
308
349
assert . match ( stderr , / E R R _ I N V A L I D _ A R G _ T Y P E / ) ;
309
350
assert . match ( stderr , / l o a d e r - l o a d - b a d - n e x t - u r l \. m j s / ) ;
310
- assert . match ( stderr , / " l o a d " / ) ;
311
- assert . match ( stderr , / n e x t L o a d \( u r l \) / ) ;
351
+ assert . match ( stderr , / ' l o a d ' h o o k ' s n e x t L o a d \( \) u r l / ) ;
352
+ assert . strictEqual ( status , 1 ) ;
312
353
}
313
354
314
- { // Verify error thrown when invalid `url` argument passed to `load…next `
355
+ { // Verify error thrown when invalid `url` argument passed to `nextLoad `
315
356
const { status, stderr } = spawnSync (
316
357
process . execPath ,
317
358
[
@@ -324,14 +365,13 @@ const commonArgs = [
324
365
{ encoding : 'utf8' } ,
325
366
) ;
326
367
327
- assert . strictEqual ( status , 1 ) ;
328
368
assert . match ( stderr , / E R R _ I N V A L I D _ A R G _ V A L U E / ) ;
329
369
assert . match ( stderr , / l o a d e r - l o a d - i m p e r s o n a t i n g - n e x t - u r l \. m j s / ) ;
330
- assert . match ( stderr , / " l o a d " / ) ;
331
- assert . match ( stderr , / n e x t L o a d \( u r l \) / ) ;
370
+ assert . match ( stderr , / ' l o a d ' h o o k ' s n e x t L o a d \( \) u r l / ) ;
371
+ assert . strictEqual ( status , 1 ) ;
332
372
}
333
373
334
- { // Verify error thrown when invalid `context` argument passed to `load…next `
374
+ { // Verify error thrown when invalid `context` argument passed to `nextLoad `
335
375
const { status, stderr } = spawnSync (
336
376
process . execPath ,
337
377
[
@@ -344,9 +384,8 @@ const commonArgs = [
344
384
{ encoding : 'utf8' } ,
345
385
) ;
346
386
347
- assert . strictEqual ( status , 1 ) ;
348
387
assert . match ( stderr , / E R R _ I N V A L I D _ A R G _ T Y P E / ) ;
349
388
assert . match ( stderr , / l o a d e r - l o a d - b a d - n e x t - c o n t e x t \. m j s / ) ;
350
- assert . match ( stderr , / " l o a d " / ) ;
351
- assert . match ( stderr , / n e x t L o a d \( , c o n t e x t \) / ) ;
389
+ assert . match ( stderr , / ' l o a d ' h o o k ' s n e x t L o a d \( \) c o n t e x t / ) ;
390
+ assert . strictEqual ( status , 1 ) ;
352
391
}
0 commit comments