Skip to content

Commit b90af12

Browse files
committed
Add a few tests
1 parent 9bdcd2b commit b90af12

File tree

2 files changed

+27
-12
lines changed

2 files changed

+27
-12
lines changed

test/QueueTest.js

+24-10
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
const test = require("ava");
2-
const fs = require("fs");
32
const Cache = require("../");
43
const RemoteAssetCache = require("../src/RemoteAssetCache");
54

@@ -46,16 +45,16 @@ test("Double Fetch async function (dry run)", async (t) => {
4645
return Promise.resolve(expected);
4746
};
4847

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+
});
5756

58-
// Make sure we only fetch once!
57+
// two distinct fetches
5958
t.not(ac1, ac2);
6059

6160
let result1 = await ac1;
@@ -65,3 +64,18 @@ let ac2 = Cache(fetch, {
6564
t.deepEqual(result1, expected);
6665
t.deepEqual(result2, expected);
6766
});
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+
});

test/RemoteAssetCacheTest.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -343,7 +343,7 @@ test("type: parsed-xml", async (t) => {
343343
t.is(xml.children.length, 1)
344344
});
345345

346-
test("raw: true, cache miss", async (t) => {
346+
test("returnType: response, cache miss", async (t) => {
347347
let feedUrl = "https://www.11ty.dev/blog/feed.xml";
348348
let ac = new RemoteAssetCache(feedUrl, ".cache", {
349349
type: "xml",
@@ -365,7 +365,7 @@ test("raw: true, cache miss", async (t) => {
365365
});
366366

367367

368-
test("raw: true, cache hit", async (t) => {
368+
test("returnType: response, cache hit", async (t) => {
369369
let feedUrl = "https://www.11ty.dev/blog/feed.xml";
370370
let ac = new RemoteAssetCache(feedUrl, ".cache", {
371371
type: "xml",
@@ -384,3 +384,4 @@ test("raw: true, cache hit", async (t) => {
384384

385385
t.is(response.cache, "hit");
386386
});
387+

0 commit comments

Comments
 (0)