Skip to content

Commit c793a65

Browse files
committed
fix tests: use file-based SQLite database instead of in-memory
The in-memory SQLite database can cause issues in CI environments where worker processes may not properly share the same in-memory state. Using a file-based database ensures consistent behavior across all environments.
1 parent 3232e2d commit c793a65

1 file changed

Lines changed: 16 additions & 2 deletions

File tree

packages/backend/test/setup.ts

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,9 +83,23 @@ for (const path of loggerPaths) {
8383
// Initialize database for tests
8484
import { initializeDatabase } from '../src/db/client';
8585
import { runMigrations } from '../src/db/migrate';
86+
import path from 'node:path';
87+
import fs from 'node:fs';
88+
89+
// Use a file-based database in CI to avoid in-memory database issues
90+
// The in-memory database can have issues with worker processes in some environments
91+
const testDbPath = path.join(process.cwd(), '.test-db.sqlite');
92+
const testDbUrl = process.env.PLEXUS_TEST_DB_URL || `sqlite://${testDbPath}`;
93+
94+
// Clean up any existing test database before initializing
95+
try {
96+
if (fs.existsSync(testDbPath)) {
97+
fs.unlinkSync(testDbPath);
98+
}
99+
} catch {
100+
// Ignore cleanup errors
101+
}
86102

87-
// Load minimal test config with database section before initializing database
88-
const testDbUrl = process.env.PLEXUS_TEST_DB_URL || 'sqlite://:memory:';
89103
const testConfig = `
90104
database:
91105
connection_string: "${testDbUrl}"

0 commit comments

Comments
 (0)