Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ yarn.lock
# Dist
dist
packages/website/site/docs/*.md
packages/cacheable-request/test/testdb.sqlite
packages/flat-cache/.cache
packages/file-entry-cache/.cache
packages/file-entry-cache/test/test-logger-file.txt
Expand Down
4 changes: 1 addition & 3 deletions packages/cacheable-request/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"test:ci": "biome check --error-on-warnings && vitest run --coverage",
"prepublishOnly": "pnpm build",
"build": "rimraf ./dist && tsc --project tsconfig.build.json",
"clean": "rimraf node_modules ./coverage ./test/testdb.sqlite ./dist"
"clean": "rimraf node_modules ./coverage ./dist"
},
"files": [
"dist",
Expand Down Expand Up @@ -52,14 +52,12 @@
"responselike": "^4.0.2"
},
"devDependencies": {
"@keyv/sqlite": "^4.0.8",
"@types/express": "^5.0.6",
"@types/responselike": "^1.0.3",
"body-parser": "^2.2.2",
"delay": "^7.0.0",
"express": "^5.2.1",
"pify": "^6.1.0",
"sqlite3": "^6.0.1",
"tsup": "^8.5.1",
"typescript": "^5.9.3"
}
Expand Down
20 changes: 17 additions & 3 deletions packages/cacheable-request/test/cacheable-request-instance.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
import EventEmitter from "node:events";
import { request } from "node:http";
import stream from "node:stream";
import { KeyvSqlite } from "@keyv/sqlite";
import getStream from "get-stream";
import { Keyv } from "keyv";
import { afterAll, beforeAll, expect, test } from "vitest";
Expand All @@ -24,6 +23,21 @@ beforeAll(async () => {
afterAll(async () => {
await s.close();
});
// A Keyv-compatible store that cannot open its backing database: every
// operation rejects with a SQLITE_CANTOPEN-style error, mirroring an adapter
// such as @keyv/sqlite pointed at an unwritable path. This exercises the
// cache-connection error and automaticFailover code paths without depending
// on a native database driver.
const createUnopenableStore = () => {
const fail = async () => {
const error = Object.assign(
new Error("SQLITE_CANTOPEN: unable to open database file"),
{ code: "SQLITE_CANTOPEN" },
);
throw error;
};
return { get: fail, set: fail, delete: fail, clear: fail };
};
Comment thread
jaredwray marked this conversation as resolved.
test("cacheableRequest is a class", () => {
const cacheableRequest = new CacheableRequest(request);
expect(typeof cacheableRequest).toBe("object");
Expand Down Expand Up @@ -121,7 +135,7 @@ test("cacheableRequest emits response event for cached responses", () => {
test("cacheableRequest emits CacheError if cache adapter connection errors", () => {
const cacheableRequest = new CacheableRequest(
request,
new KeyvSqlite("sqlite://non/existent/database.sqlite"),
createUnopenableStore(),
).request();
cacheableRequest(parseWithWhatwg(s.url))
.on("error", (error: any) => {
Expand Down Expand Up @@ -298,7 +312,7 @@ test("cacheableRequest does not cache response if request is aborted after recei
test("cacheableRequest makes request even if initial DB connection fails (when opts.automaticFailover is enabled)", async () => {
const cacheableRequest = new CacheableRequest(
request,
new KeyvSqlite("sqlite://non/existent/database.sqlite"),
createUnopenableStore(),
).request();
const options: any = parseWithWhatwg(s.url);
options.automaticFailover = true;
Expand Down
Loading
Loading