1
1
// @ts -check
2
+
2
3
import path from "path"
3
4
import zlib from "zlib"
4
5
import os from "os"
@@ -347,8 +348,6 @@ describe(`fetch-remote-file`, () => {
347
348
jest . runAllTimers ( )
348
349
await requests [ 0 ]
349
350
350
- jest . useRealTimers ( )
351
-
352
351
// we still expect 2 fetches because cache can't save fast enough
353
352
expect ( gotStream ) . toBeCalledTimes ( 2 )
354
353
expect ( fsMove ) . toBeCalledTimes ( 1 )
@@ -408,20 +407,12 @@ describe(`fetch-remote-file`, () => {
408
407
jest . runAllTimers ( )
409
408
await requests [ 0 ]
410
409
411
- jest . useRealTimers ( )
412
-
413
410
// we still expect 4 fetches because cache can't save fast enough
414
411
expect ( gotStream ) . toBeCalledTimes ( 4 )
415
412
expect ( fsMove ) . toBeCalledTimes ( 2 )
416
413
} )
417
414
418
415
it ( `doesn't keep lock when file download failed` , async ( ) => {
419
- jest . setTimeout ( 7000 )
420
-
421
- // we don't want to wait for polling to finish
422
- jest . useFakeTimers ( )
423
- jest . runAllTimers ( )
424
-
425
416
const cacheInternals = new Map ( )
426
417
const workerCache = {
427
418
get ( key ) {
@@ -443,17 +434,13 @@ describe(`fetch-remote-file`, () => {
443
434
} )
444
435
) . rejects . toThrow ( )
445
436
446
- jest . runAllTimers ( )
447
-
448
437
await expect (
449
438
fetchRemoteFileInstanceTwo ( {
450
439
url : `http://external.com/500.jpg` ,
451
440
cache : workerCache ,
452
441
} )
453
442
) . rejects . toThrow ( )
454
443
455
- jest . useRealTimers ( )
456
-
457
444
expect ( gotStream ) . toBeCalledTimes ( 3 )
458
445
expect ( fsMove ) . toBeCalledTimes ( 0 )
459
446
} )
@@ -468,8 +455,6 @@ describe(`fetch-remote-file`, () => {
468
455
} )
469
456
470
457
it ( `fails when 500 is triggered` , async ( ) => {
471
- jest . setTimeout ( 7000 )
472
-
473
458
await expect (
474
459
fetchRemoteFile ( {
475
460
url : `http://external.com/500.jpg` ,
@@ -529,13 +514,13 @@ Fetch details:
529
514
} )
530
515
531
516
it ( `Retries when server returns 503 error till server returns 200` , async ( ) => {
532
- jest . setTimeout ( 7000 )
533
-
534
- const filePath = await fetchRemoteFile ( {
517
+ const fetchRemoteFileInstance = fetchRemoteFile ( {
535
518
url : `http://external.com/503-twice.svg` ,
536
519
cache,
537
520
} )
538
521
522
+ const filePath = await fetchRemoteFileInstance
523
+
539
524
expect ( path . basename ( filePath ) ) . toBe ( `503-twice.svg` )
540
525
expect ( getFileSize ( filePath ) ) . resolves . toBe (
541
526
await getFileSize ( path . join ( __dirname , `./fixtures/gatsby-logo.svg` ) )
@@ -544,8 +529,6 @@ Fetch details:
544
529
} )
545
530
546
531
it ( `Stops retry when maximum attempts is reached` , async ( ) => {
547
- jest . setTimeout ( 7000 )
548
-
549
532
await expect (
550
533
fetchRemoteFile ( {
551
534
url : `http://external.com/503-forever.svg` ,
@@ -579,9 +562,7 @@ Fetch details:
579
562
expect ( gotStream ) . toBeCalledTimes ( 3 )
580
563
} )
581
564
// @todo retry on network errors
582
- it . skip ( `Retries on network errors` , async ( ) => {
583
- jest . setTimeout ( 7000 )
584
-
565
+ it ( `Retries on network errors` , async ( ) => {
585
566
await expect (
586
567
fetchRemoteFile ( {
587
568
url : `http://external.com/network-error.svg` ,
0 commit comments