1
1
const test = require ( "ava" ) ;
2
- const fs = require ( "fs" ) ;
3
2
const Cache = require ( "../" ) ;
4
3
const RemoteAssetCache = require ( "../src/RemoteAssetCache" ) ;
5
4
@@ -46,16 +45,16 @@ test("Double Fetch async function (dry run)", async (t) => {
46
45
return Promise . resolve ( expected ) ;
47
46
} ;
48
47
49
- let ac1 = Cache ( fetch , {
50
- dryRun : true ,
51
- requestId : "fetch-1" ,
52
- } ) ;
53
- let ac2 = Cache ( fetch , {
54
- dryRun : true ,
55
- requestId : "fetch-2" ,
56
- } ) ;
48
+ let ac1 = Cache ( fetch , {
49
+ dryRun : true ,
50
+ requestId : "fetch-1" ,
51
+ } ) ;
52
+ let ac2 = Cache ( fetch , {
53
+ dryRun : true ,
54
+ requestId : "fetch-2" ,
55
+ } ) ;
57
56
58
- // Make sure we only fetch once!
57
+ // two distinct fetches
59
58
t . not ( ac1 , ac2 ) ;
60
59
61
60
let result1 = await ac1 ;
@@ -65,3 +64,18 @@ let ac2 = Cache(fetch, {
65
64
t . deepEqual ( result1 , expected ) ;
66
65
t . deepEqual ( result2 , expected ) ;
67
66
} ) ;
67
+
68
+ test ( "Double Fetch 404 errors should only fetch once" , async ( t ) => {
69
+ let ac1 = Cache ( "https://httpstat.us/404" , {
70
+ dryRun : true ,
71
+ } ) ;
72
+ let ac2 = Cache ( "https://httpstat.us/404" , {
73
+ dryRun : true ,
74
+ } ) ;
75
+
76
+ // Make sure we only fetch once!
77
+ t . is ( ac1 , ac2 ) ;
78
+
79
+ await t . throwsAsync ( async ( ) => await ac1 ) ;
80
+ await t . throwsAsync ( async ( ) => await ac2 ) ;
81
+ } ) ;
0 commit comments