test(server): integration database not initialized properly

This commit is contained in:
Elian Doran
2026-04-09 13:46:44 +03:00
parent d35b55f7d3
commit d34ba8b6f3
2 changed files with 14 additions and 2 deletions

View File

@@ -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: {

View File

@@ -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: [