mirror of
https://github.com/nicotsx/zerobyte.git
synced 2026-04-21 15:32:45 -04:00
* 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
26 lines
578 B
TypeScript
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;
|
|
};
|