import * as fsPromises from 'fs/promises'; import * as os from 'os'; import * as path from 'path'; import { vi } from 'vitest'; // In tests we run from source; loot-core's API fs uses __dirname (for the built dist/). // Mock the fs so path constants point at loot-core package root where migrations live. vi.mock( '../../loot-core/src/platform/server/fs/index.api', async importOriginal => { const actual = (await importOriginal()) as Record; const lootCoreRoot = path.join(__dirname, '..', '..', 'loot-core'); return { ...actual, migrationsPath: path.join(lootCoreRoot, 'migrations'), bundledDatabasePath: path.join(lootCoreRoot, 'default-db.sqlite'), demoBudgetPath: path.join(lootCoreRoot, 'demo-budget'), }; }, ); global.IS_TESTING = true; // Shared integration test lives in a filesystem-backed tmp dir. const dataDir = path.join( os.tmpdir(), `api-it-${Date.now()}-${Math.random().toString(36).slice(2)}`, ); await fsPromises.mkdir(dataDir, { recursive: true }); globalThis.__API_DATA_DIR__ = dataDir;