@@ -124,7 +124,7 @@ t.test('stream body param', t => {
124
124
. then ( json => t . same ( json , { hello : 'world' } ) )
125
125
} )
126
126
127
- t . test ( 'JSON body param' , t => {
127
+ t . test ( 'JSON body param' , async t => {
128
128
tnock ( t , defaultOpts . registry )
129
129
. matchHeader ( 'content-type' , ctype => {
130
130
t . equal ( ctype [ 0 ] , 'application/json' , 'content-type automatically set' )
@@ -143,10 +143,8 @@ t.test('JSON body param', t => {
143
143
body : { hello : 'world' } ,
144
144
gzip : true ,
145
145
}
146
- return fetch ( '/hello' , opts )
147
- . then ( res => {
148
- t . equal ( res . status , 200 , 'request succeeded' )
149
- } )
146
+ const res = await fetch ( '/hello' , opts )
147
+ t . equal ( res . status , 200 , 'request succeeded' )
150
148
} )
151
149
152
150
t . test ( 'gzip + buffer body param' , t => {
@@ -275,43 +273,41 @@ t.test('query string with ?write=true', t => {
275
273
. then ( res => t . strictSame ( res , { write : 'go for it' } ) )
276
274
} )
277
275
278
- t . test ( 'fetch.json.stream()' , t => {
276
+ t . test ( 'fetch.json.stream()' , async t => {
279
277
tnock ( t , defaultOpts . registry ) . get ( '/hello' ) . reply ( 200 , {
280
278
a : 1 ,
281
279
b : 2 ,
282
280
c : 3 ,
283
281
} )
284
- return fetch . json . stream ( '/hello' , '$*' , OPTS ) . collect ( ) . then ( data => {
285
- t . same ( data , [
286
- { key : 'a' , value : 1 } ,
287
- { key : 'b' , value : 2 } ,
288
- { key : 'c' , value : 3 } ,
289
- ] , 'got a streamed JSON body' )
290
- } )
282
+ const data = await fetch . json . stream ( '/hello' , '$*' , OPTS ) . collect ( )
283
+ t . same ( data , [
284
+ { key : 'a' , value : 1 } ,
285
+ { key : 'b' , value : 2 } ,
286
+ { key : 'c' , value : 3 } ,
287
+ ] , 'got a streamed JSON body' )
291
288
} )
292
289
293
- t . test ( 'fetch.json.stream opts.mapJSON' , t => {
290
+ t . test ( 'fetch.json.stream opts.mapJSON' , async t => {
294
291
tnock ( t , defaultOpts . registry ) . get ( '/hello' ) . reply ( 200 , {
295
292
a : 1 ,
296
293
b : 2 ,
297
294
c : 3 ,
298
295
} )
299
- return fetch . json . stream ( '/hello' , '*' , {
296
+ const data = await fetch . json . stream ( '/hello' , '*' , {
300
297
...OPTS ,
301
298
mapJSON ( value , [ key ] ) {
302
299
return [ key , value ]
303
300
} ,
304
- } ) . collect ( ) . then ( data => {
305
- t . same ( data , [
306
- [ 'a' , 1 ] ,
307
- [ 'b' , 2 ] ,
308
- [ 'c' , 3 ] ,
309
- ] , 'data mapped' )
310
- } )
301
+ } ) . collect ( )
302
+ t . same ( data , [
303
+ [ 'a' , 1 ] ,
304
+ [ 'b' , 2 ] ,
305
+ [ 'c' , 3 ] ,
306
+ ] , 'data mapped' )
311
307
} )
312
308
313
- t . test ( 'fetch.json.stream gets fetch error on stream' , t => {
314
- return t . rejects ( fetch . json . stream ( '/hello' , '*' , {
309
+ t . test ( 'fetch.json.stream gets fetch error on stream' , async t => {
310
+ await t . rejects ( fetch . json . stream ( '/hello' , '*' , {
315
311
...OPTS ,
316
312
body : Promise . reject ( new Error ( 'no body for you' ) ) ,
317
313
method : 'POST' ,
@@ -321,28 +317,24 @@ t.test('fetch.json.stream gets fetch error on stream', t => {
321
317
} )
322
318
} )
323
319
324
- t . test ( 'opts.ignoreBody' , t => {
320
+ t . test ( 'opts.ignoreBody' , async t => {
325
321
tnock ( t , defaultOpts . registry )
326
322
. get ( '/hello' )
327
323
. reply ( 200 , { hello : 'world' } )
328
- return fetch ( '/hello' , { ...OPTS , ignoreBody : true } )
329
- . then ( res => {
330
- t . equal ( res . body , null , 'body omitted' )
331
- } )
324
+ const res = await fetch ( '/hello' , { ...OPTS , ignoreBody : true } )
325
+ t . equal ( res . body , null , 'body omitted' )
332
326
} )
333
327
334
- t . test ( 'method configurable' , t => {
328
+ t . test ( 'method configurable' , async t => {
335
329
tnock ( t , defaultOpts . registry )
336
330
. delete ( '/hello' )
337
331
. reply ( 200 )
338
332
const opts = {
339
333
...OPTS ,
340
334
method : 'DELETE' ,
341
335
}
342
- return fetch ( '/hello' , opts )
343
- . then ( res => {
344
- t . equal ( res . status , 200 , 'successfully used DELETE method' )
345
- } )
336
+ const res = await fetch ( '/hello' , opts )
337
+ t . equal ( res . status , 200 , 'successfully used DELETE method' )
346
338
} )
347
339
348
340
t . test ( 'npm-notice header logging' , async t => {
@@ -355,7 +347,7 @@ t.test('npm-notice header logging', async t => {
355
347
let header , msg
356
348
process . on ( 'log' , ( level , ...args ) => {
357
349
if ( level === 'notice' ) {
358
- ; [ header , msg ] = args
350
+ [ header , msg ] = args
359
351
}
360
352
} )
361
353
@@ -463,7 +455,7 @@ t.test('pickRegistry through opts.spec', t => {
463
455
) )
464
456
} )
465
457
466
- t . test ( 'miscellaneous headers' , t => {
458
+ t . test ( 'miscellaneous headers' , async t => {
467
459
tnock ( t , defaultOpts . registry )
468
460
. matchHeader ( 'npm-session' , session =>
469
461
t . strictSame ( session , [ 'foobarbaz' ] , 'session set from options' ) )
@@ -478,30 +470,28 @@ t.test('miscellaneous headers', t => {
478
470
. get ( '/hello' )
479
471
. reply ( 200 , { hello : 'world' } )
480
472
481
- return fetch ( '/hello' , {
473
+ const res = await fetch ( '/hello' , {
482
474
...OPTS ,
483
475
registry : null , // always falls back on falsey registry value
484
476
npmSession : 'foobarbaz' ,
485
477
scope : '@foo' ,
486
478
userAgent : 'agent of use' ,
487
479
npmCommand : 'hello-world' ,
488
480
authType : 'auth' ,
489
- } ) . then ( res => {
490
- t . equal ( res . status , 200 , 'got successful response' )
491
481
} )
482
+ t . equal ( res . status , 200 , 'got successful response' )
492
483
} )
493
484
494
- t . test ( 'miscellaneous headers not being set if not present in options' , t => {
485
+ t . test ( 'miscellaneous headers not being set if not present in options' , async t => {
495
486
tnock ( t , defaultOpts . registry )
496
487
. matchHeader ( 'npm-auth-type' , authType =>
497
488
t . strictSame ( authType , undefined , 'auth-type not set from options' ) )
498
489
. get ( '/hello' )
499
490
. reply ( 200 , { hello : 'world' } )
500
491
501
- return fetch ( '/hello' , {
492
+ const res = await fetch ( '/hello' , {
502
493
...OPTS ,
503
494
authType : undefined ,
504
- } ) . then ( res => {
505
- t . equal ( res . status , 200 , 'got successful response' )
506
495
} )
496
+ t . equal ( res . status , 200 , 'got successful response' )
507
497
} )
0 commit comments