dont error if ejectFromCache is called when the response is already not cached
This commit is contained in:
parent
558d63fd40
commit
8e1b57382a
@ -25,8 +25,14 @@ class Response {
|
|||||||
return this.bodyBuffer;
|
return this.bodyBuffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
ejectFromCache() {
|
async ejectFromCache() {
|
||||||
return fs.promises.unlink(this.cacheFilePath);
|
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);
|
res = await fetch(TWO_HUNDRED_URL);
|
||||||
assert.strictEqual(res.fromCache, true);
|
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);
|
}).timeout(10000);
|
||||||
|
|
||||||
describe('Data tests', function() {
|
describe('Data tests', function() {
|
||||||
|
Reference in New Issue
Block a user