Skip to content

Build your personal knowledge base with Trilium Notes

test(server): attach edit-integration-db directly to the tracked fixture

Elian Doran6a027f1dcab3
diff --git a/apps/server/package.json b/apps/server/package.json
index 0293da3835..a34a09ca1c 100644
--- a/apps/server/package.json
+++ b/apps/server/package.json
@@ -9,7 +9,7 @@
"dev-alt": "cross-env NODE_ENV=development TRILIUM_ENV=dev TRILIUM_DATA_DIR=data2 TRILIUM_RESOURCE_DIR=src tsx watch --ignore '../client/node_modules/.vite-temp' ./src/main.ts",
"start-no-dir": "cross-env NODE_ENV=development TRILIUM_ENV=dev TRILIUM_RESOURCE_DIR=src tsx watch --ignore '../client/node_modules/.vite-temp' ./src/main.ts",
"profile": "cross-env NODE_ENV=development TRILIUM_ENV=dev TRILIUM_DATA_DIR=data TRILIUM_RESOURCE_DIR=src TRILIUM_PROFILE=1 node --import tsx ./src/main.ts",
- "edit-integration-db": "cross-env NODE_ENV=development TRILIUM_PORT=8086 TRILIUM_ENV=dev TRILIUM_DATA_DIR=spec/db TRILIUM_INTEGRATION_TEST=edit TRILIUM_RESOURCE_DIR=src tsx watch --ignore '../client/node_modules/.vite-temp' ./src/main.ts",
+ "edit-integration-db": "cross-env NODE_ENV=development TRILIUM_PORT=8086 TRILIUM_ENV=dev TRILIUM_DATA_DIR=spec/db TRILIUM_DOCUMENT_PATH=../../packages/trilium-core/src/test/fixtures/document.db TRILIUM_INTEGRATION_TEST=edit TRILIUM_RESOURCE_DIR=src tsx watch --ignore '../client/node_modules/.vite-temp' ./src/main.ts",
"build": "tsx scripts/build.ts",
"package": "pnpm build && bash scripts/build-server.sh",
"test": "vitest",
diff --git a/apps/server/src/sql_provider.ts b/apps/server/src/sql_provider.ts
index 13427dd9bb..b47631d0bd 100644
--- a/apps/server/src/sql_provider.ts
+++ b/apps/server/src/sql_provider.ts
@@ -23,7 +23,14 @@ export default class BetterSqlite3Provider implements DatabaseProvider {
...dbOpts,
readonly: isReadOnly
});
- this.dbConnection.pragma("journal_mode = WAL");
+
+ // The `edit-integration-db` tool (TRILIUM_INTEGRATION_TEST=edit) attaches
+ // directly to the git-tracked fixture DB. Keep it in the rollback journal
+ // mode so it stays a single committable file: WAL is persisted in the DB
+ // header and would spawn -wal/-shm sidecars, making the fixture harder to
+ // track (see docs Testing/Test database.md).
+ const journalMode = process.env.TRILIUM_INTEGRATION_TEST ? "DELETE" : "WAL";
+ this.dbConnection.pragma(`journal_mode = ${journalMode}`);
}
loadFromMemory() {
diff --git a/docs/Developer Guide/Developer Guide/Testing/Test database.md b/docs/Developer Guide/Developer Guide/Testing/Test database.md
index 3062e611d9..a11b48f2ed 100644
--- a/docs/Developer Guide/Developer Guide/Testing/Test database.md
+++ b/docs/Developer Guide/Developer Guide/Testing/Test database.md
@@ -1,34 +1,32 @@
# Test database
-The integration tests do not use the same database as `npm run start-server`. Instead, the database is located `integration-tests/db/document.db`.
+The integration tests do not use the same database as `pnpm server:start`. Instead, the tracked fixture database lives at `packages/trilium-core/src/test/fixtures/document.db`.
## In-memory database
-Even though we are running our own database, there is still the problem of one test affecting the content for the others or accidentally removing important test notes.
+Even though we ship our own database, there is still the problem of one test affecting the content for the others or accidentally removing important test notes.
-To avoid this, the integration test server (run via `integration-mem-db`) loads the database from `integration-test` into memory and operates from there. That means that any changes done on the integration test server (port 8082) will not be persisted between restarts of the server.
-
-Another benefit of having the database in memory for tests is that they can run in parallel without the risk on interfering with each other.
+To avoid this, the test setup (`apps/server/spec/setup.ts`) loads the fixture into memory and operates from there. That means any changes made while tests run are never persisted to disk. Another benefit of having the database in memory is that test files can run in parallel (each vitest fork gets its own copy) without interfering with each other.
## How to make changes to the database
-As mentioned previously, the database itself can be edited manually in order to add content that is relevant to the tests.
-
-In order to do so, run a separate integration test server with:
+The database can be edited manually to add content that is relevant to the tests. To do so, run a dedicated editing server:
```
-npm run integration-edit-db
+pnpm --filter server run edit-integration-db
```
-This will open up a server on port 8081 which can be used to alter the integration test DB. After finishing the desired changes, it's ideal to close the server to prevent any interferences with further running of tests.
+This opens a server on port **8086** that attaches **directly** to the tracked fixture (`packages/trilium-core/src/test/fixtures/document.db`) via `TRILIUM_DOCUMENT_PATH`, so your changes land in the committed file — no copy step is required. Ancillary runtime files (logs, tmp, `config.ini`) still live in the git-ignored `apps/server/spec/db/`.
+
+After finishing the desired changes, close the server (Ctrl-C) to prevent any interference with further test runs.
## The database is tracked by Git
-This is intentional, meaning that any change to the database will mark the file as changed in Git as well. Some tests require a specific note and it would be too wasteful to have to recreate it via Playwright each time. Instead the content is added manually and then the tests operate directly on the said notes.
+This is intentional: any change to the database marks the file as changed in Git as well. Some tests require a specific note and it would be too wasteful to recreate it via Playwright each time. Instead the content is added manually and the tests operate directly on those notes.
-In order to make the database easier to track, SQLite WAL was disabled but only for the integration database. This means that only the `.db` file is present and needs to be committed.
+To keep the database easy to track, the editing server opens it in the rollback (`DELETE`) journal mode instead of WAL (see `apps/server/src/sql_provider.ts`). This means only the single `.db` file is produced and needs to be committed — no `-wal`/`-shm` sidecars. (Those sidecars are git-ignored under the fixtures directory regardless.)
## Cleaning up the database
-It's recommended to clean up any deleted notes to avoid unnecessary changes being committed. To do so go to Recent Changes in the launcher and select “Erase deleted notes now”.
+It's recommended to clean up any deleted notes to avoid unnecessary changes being committed. To do so go to Recent Changes in the launcher and select "Erase deleted notes now".
-It's also a good idea to go to Options → Advanced → Vacuum database to clean up it.
\ No newline at end of file
+It's also a good idea to go to Options → Advanced → Vacuum database to clean it up.