dont error if ejectFromCache is called when the response is already not cached

This commit is contained in:
Randall Schmidt 2020-11-27 23:31:39 -05:00
parent 558d63fd40
commit 8e1b57382a
2 changed files with 16 additions and 2 deletions

@ -25,8 +25,14 @@ class Response {
return this.bodyBuffer;
}
ejectFromCache() {
return fs.promises.unlink(this.cacheFilePath);
async ejectFromCache() {
try {
await fs.promises.unlink(this.cacheFilePath);
} catch (err) {
if (err.code !== 'ENOENT') {
throw err;
}
}
}
}

@ -96,6 +96,14 @@ describe('Cache tests', function() {
res = await fetch(TWO_HUNDRED_URL);
assert.strictEqual(res.fromCache, true);
});
it('Does not error if rejecting from cache twice', async function() {
res = await fetch(TWO_HUNDRED_URL);
assert.strictEqual(res.fromCache, false);
await res.ejectFromCache();
await res.ejectFromCache();
});
}).timeout(10000);
describe('Data tests', function() {