Sets up Vitest (jsdom, Testing Library, v8 coverage) per the Next 16 testing guide, using Vite's native tsconfig path resolution instead of vite-tsconfig-paths. A server-only stub and a temp-data helper let server modules run in isolation. @types/node moves to ^24 to match the Node 24 runtime (a vitest 5 peer requirement). First 68 tests cover the discover route (including iss-dbwgww8: no raw errors in responses), the credential store, the camera registry, camera-route helpers and the refresh-rate schema. Line coverage is 31.2%, toward the 95% goal. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
29 lines
924 B
TypeScript
29 lines
924 B
TypeScript
import { mkdtemp, rm } from "node:fs/promises";
|
|
import os from "node:os";
|
|
import path from "node:path";
|
|
import { afterEach, beforeEach, vi } from "vitest";
|
|
|
|
/**
|
|
* Points the registry and credential store at a fresh temp directory for each test and
|
|
* resets the module cache, so modules that read env at import time pick it up.
|
|
*/
|
|
export function withTempDataDir() {
|
|
const dir = { path: "" };
|
|
|
|
beforeEach(async () => {
|
|
dir.path = await mkdtemp(path.join(os.tmpdir(), "cameras-test-"));
|
|
vi.stubEnv("CAMERA_REGISTRY_FILE", path.join(dir.path, "cameras.json"));
|
|
vi.stubEnv("CAMERA_CREDENTIALS_FILE", path.join(dir.path, "credentials.json"));
|
|
vi.stubEnv("CAMERA_CREDENTIALS_KEY", "test-key");
|
|
vi.stubEnv("ONVIF_USERNAME", "");
|
|
vi.stubEnv("ONVIF_PASSWORD", "");
|
|
vi.resetModules();
|
|
});
|
|
|
|
afterEach(async () => {
|
|
await rm(dir.path, { recursive: true, force: true });
|
|
});
|
|
|
|
return dir;
|
|
}
|