integration-test: Allow for in-memory database

This commit is contained in:
Elian Doran 2024-08-09 21:51:10 +03:00
parent 1542eb14b3
commit 64f99ba637
No known key found for this signature in database
2 changed files with 14 additions and 2 deletions

View File

@ -45,7 +45,8 @@
"prepare-dist": "rimraf ./dist && tsc && tsx ./bin/copy-dist.ts",
"update-build-info": "tsx bin/update-build-info.ts",
"errors": "tsc --watch --noEmit",
"integration-edit-db": "cross-env TRILIUM_INTEGRATION_TEST=edit TRILIUM_PORT=8081 TRILIUM_DATA_DIR=./integration-tests/db nodemon src/www.ts"
"integration-edit-db": "cross-env TRILIUM_INTEGRATION_TEST=edit TRILIUM_PORT=8081 TRILIUM_DATA_DIR=./integration-tests/db nodemon src/www.ts",
"integration-mem-db": "cross-env TRILIUM_INTEGRATION_TEST=memory TRILIUM_PORT=8082 TRILIUM_DATA_DIR=./integration-tests/db nodemon src/www.ts"
},
"dependencies": {
"@braintree/sanitize-url": "^7.1.0",

View File

@ -14,7 +14,18 @@ import ws from "./ws.js";
import becca_loader from "../becca/becca_loader.js";
import entity_changes from "./entity_changes.js";
const dbConnection: DatabaseType = new Database(dataDir.DOCUMENT_PATH);
function buildDatabase(path: string) {
if (process.env.TRILIUM_INTEGRATION_TEST === "memory") {
// This allows a database that is read normally but is kept in memory and discards all modifications.
const dbBuffer = fs.readFileSync(path);
return new Database(dbBuffer);
}
return new Database(dataDir.DOCUMENT_PATH);
}
const dbConnection: DatabaseType = buildDatabase(dataDir.DOCUMENT_PATH);
if (!process.env.TRILIUM_INTEGRATION_TEST) {
dbConnection.pragma('journal_mode = WAL');
}