test(import): add legacy import compatibility coverage

This commit is contained in:
Zimeng Xiong
2026-02-06 14:54:02 -08:00
parent 94694deb91
commit 01fda32bcd
5 changed files with 520 additions and 35 deletions
+17 -2
View File
@@ -1,11 +1,26 @@
const { parentPort, workerData } = require('worker_threads');
const Database = require('better-sqlite3');
if (!parentPort) throw new Error("Must be run in a worker thread");
const openReadonlyDb = (filePath) => {
try {
const { DatabaseSync } = require("node:sqlite");
const db = new DatabaseSync(filePath, {
readOnly: true,
enableForeignKeyConstraints: false,
});
return { kind: "node:sqlite", db };
} catch (_err) {
// Fall back to better-sqlite3 on Node versions that don't have node:sqlite.
const Database = require("better-sqlite3");
const db = new Database(filePath, { readonly: true, fileMustExist: true });
return { kind: "better-sqlite3", db };
}
};
try {
const { filePath } = workerData;
const db = new Database(filePath, { readonly: true, fileMustExist: true });
const { db } = openReadonlyDb(filePath);
// This is the CPU-heavy operation
const result = db.prepare("PRAGMA integrity_check;").get();