diff --git a/apps/server/spec/setup.ts b/apps/server/spec/setup.ts index 484d582465..c84112610e 100644 --- a/apps/server/spec/setup.ts +++ b/apps/server/spec/setup.ts @@ -18,8 +18,13 @@ process.env.TRILIUM_ENV = "dev"; process.env.TRILIUM_PUBLIC_SERVER = "http://localhost:4200"; beforeAll(async () => { + // Load the integration test database into memory. The fixture at + // spec/db/document.db is pre-seeded with the schema, demo content, and + // a known password ("demo1234") that the ETAPI tests log in with. Each + // test file runs in its own vitest fork (pool: "forks"), so each gets a + // fresh in-memory copy and mutations don't leak across files. const dbProvider = new BetterSqlite3Provider(); - dbProvider.loadFromMemory(); + dbProvider.loadFromBuffer(readFileSync(join(__dirname, "db", "document.db"))); await initializeCore({ dbConfig: { diff --git a/apps/server/vite.config.mts b/apps/server/vite.config.mts index 2fa10ff798..5db1745722 100644 --- a/apps/server/vite.config.mts +++ b/apps/server/vite.config.mts @@ -13,7 +13,14 @@ export default defineConfig(() => ({ env: { NODE_ENV: "development", TRILIUM_DATA_DIR: "./spec/db", - TRILIUM_INTEGRATION_TEST: "memory" + TRILIUM_INTEGRATION_TEST: "memory", + // Must be set in the vitest env (not in spec/setup.ts) so import-time + // constants like `isDev` in apps/server/src/services/utils.ts evaluate + // correctly. setup.ts top-level statements run AFTER its static imports + // resolve, so any env var assigned there is too late for module-load + // constants in transitively-imported files. + TRILIUM_ENV: "dev", + TRILIUM_PUBLIC_SERVER: "http://localhost:4200" }, include: ['{src,spec}/**/*.{test,spec}.{js,mjs,cjs,ts,mts,cts,jsx,tsx}'], exclude: [