Files
zerobyte/app/test/helpers/db.ts
Nico 4305057185 test: move test runner from Bun to Vitest (#727)
* chore: migrate to vitest

* test: speed up some suites by sharing sessions and mocking expensive non-tested actions

* test: refactor some tests to verify behavior instead of implementation details

* chore: fix linting issues
2026-04-01 20:05:54 +02:00

26 lines
578 B
TypeScript

import fs from "node:fs";
import path from "node:path";
import { tmpdir } from "node:os";
import { vi } from "vitest";
export const createTestDb = async () => {
const projectRoot = process.cwd();
const cacheRoot = fs.mkdtempSync(path.join(tmpdir(), "zerobyte-test-cache-"));
process.env.ZEROBYTE_DATABASE_URL = ":memory:";
vi.resetModules();
const database = await import("~/server/db/db");
await database.runDbMigrations();
process.chdir(cacheRoot);
try {
await import("~/server/utils/cache");
} finally {
process.chdir(projectRoot);
}
return database;
};