Add Playwright e2e test suite
This commit is contained in:
49
scripts/e2e-prepare.ts
Normal file
49
scripts/e2e-prepare.ts
Normal file
@@ -0,0 +1,49 @@
|
||||
import { mkdirSync, readFileSync, rmSync } from 'node:fs';
|
||||
import { dirname, join } from 'node:path';
|
||||
import { Database } from 'bun:sqlite';
|
||||
|
||||
const MIGRATION_FILES = [
|
||||
'0000_cold_silver_centurion.sql',
|
||||
'0001_glossy_statement_snapshots.sql',
|
||||
'0002_workflow_task_projection_metadata.sql',
|
||||
'0003_task_stage_event_timeline.sql',
|
||||
'0004_watchlist_company_taxonomy.sql',
|
||||
'0005_financial_taxonomy_v3.sql'
|
||||
] as const;
|
||||
|
||||
export const E2E_DATABASE_PATH = join(process.cwd(), 'data', 'e2e.sqlite');
|
||||
export const E2E_WORKFLOW_DATA_DIR = join(process.cwd(), '.workflow-data', 'e2e');
|
||||
|
||||
function removeFileIfPresent(path: string) {
|
||||
rmSync(path, { force: true });
|
||||
}
|
||||
|
||||
function applyMigrations(database: Database) {
|
||||
for (const file of MIGRATION_FILES) {
|
||||
const sql = readFileSync(join(process.cwd(), 'drizzle', file), 'utf8');
|
||||
database.exec(sql);
|
||||
}
|
||||
}
|
||||
|
||||
export function prepareE2eDatabase() {
|
||||
mkdirSync(dirname(E2E_DATABASE_PATH), { recursive: true });
|
||||
|
||||
removeFileIfPresent(E2E_DATABASE_PATH);
|
||||
removeFileIfPresent(`${E2E_DATABASE_PATH}-shm`);
|
||||
removeFileIfPresent(`${E2E_DATABASE_PATH}-wal`);
|
||||
rmSync(E2E_WORKFLOW_DATA_DIR, { force: true, recursive: true });
|
||||
|
||||
const database = new Database(E2E_DATABASE_PATH, { create: true });
|
||||
|
||||
try {
|
||||
database.exec('PRAGMA foreign_keys = ON;');
|
||||
applyMigrations(database);
|
||||
} finally {
|
||||
database.close();
|
||||
}
|
||||
}
|
||||
|
||||
if (import.meta.main) {
|
||||
prepareE2eDatabase();
|
||||
console.info(`[e2e] prepared SQLite database at ${E2E_DATABASE_PATH}`);
|
||||
}
|
||||
Reference in New Issue
Block a user