Skip to content
This repository was archived by the owner on Jun 24, 2025. It is now read-only.

Commit 64f99ba

Browse files
committed
integration-test: Allow for in-memory database
1 parent 1542eb1 commit 64f99ba

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,8 @@
4545
"prepare-dist": "rimraf ./dist && tsc && tsx ./bin/copy-dist.ts",
4646
"update-build-info": "tsx bin/update-build-info.ts",
4747
"errors": "tsc --watch --noEmit",
48-
"integration-edit-db": "cross-env TRILIUM_INTEGRATION_TEST=edit TRILIUM_PORT=8081 TRILIUM_DATA_DIR=./integration-tests/db nodemon src/www.ts"
48+
"integration-edit-db": "cross-env TRILIUM_INTEGRATION_TEST=edit TRILIUM_PORT=8081 TRILIUM_DATA_DIR=./integration-tests/db nodemon src/www.ts",
49+
"integration-mem-db": "cross-env TRILIUM_INTEGRATION_TEST=memory TRILIUM_PORT=8082 TRILIUM_DATA_DIR=./integration-tests/db nodemon src/www.ts"
4950
},
5051
"dependencies": {
5152
"@braintree/sanitize-url": "^7.1.0",

src/services/sql.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,18 @@ import ws from "./ws.js";
1414
import becca_loader from "../becca/becca_loader.js";
1515
import entity_changes from "./entity_changes.js";
1616

17-
const dbConnection: DatabaseType = new Database(dataDir.DOCUMENT_PATH);
17+
function buildDatabase(path: string) {
18+
if (process.env.TRILIUM_INTEGRATION_TEST === "memory") {
19+
// This allows a database that is read normally but is kept in memory and discards all modifications.
20+
const dbBuffer = fs.readFileSync(path);
21+
return new Database(dbBuffer);
22+
}
23+
24+
return new Database(dataDir.DOCUMENT_PATH);
25+
}
26+
27+
const dbConnection: DatabaseType = buildDatabase(dataDir.DOCUMENT_PATH);
28+
1829
if (!process.env.TRILIUM_INTEGRATION_TEST) {
1930
dbConnection.pragma('journal_mode = WAL');
2031
}

0 commit comments

Comments
 (0)