22 lines
1.3 KiB
TypeScript
22 lines
1.3 KiB
TypeScript
import { join } from "node:path";
|
|
import type { JobContext, ServerContext } from "@stc/contracts";
|
|
import { createCourseRepository } from "@stc/course-format";
|
|
import type { Deps } from "../src/context";
|
|
import { PYTHON, tmp } from "./fixtures";
|
|
|
|
export interface TestEnv { deps: Deps; dataDir: string; queued: { kind: string; payload: unknown }[]; jc: JobContext; progress: [number, string | undefined][] }
|
|
|
|
export async function makeEnv(env: Record<string, string | undefined> = {}): Promise<TestEnv> {
|
|
const dataDir = await tmp("stc-data-");
|
|
const courses = await createCourseRepository([join(dataDir, "courses")]);
|
|
const queued: TestEnv["queued"] = [];
|
|
const progress: TestEnv["progress"] = [];
|
|
const ctx = {
|
|
config: { port: 0, databaseUrl: "sqlite://:memory:", dataDir, courseDirs: [join(dataDir, "courses")], secret: "t", publicUrl: "http://x" },
|
|
courses,
|
|
jobs: { enqueue: async (kind: string, payload: unknown) => { queued.push({ kind, payload }); return "j1"; }, get: async () => null, list: async () => [] },
|
|
} as unknown as ServerContext;
|
|
const jc: JobContext = { signal: new AbortController().signal, reportProgress: async (f, m) => { progress.push([f, m]); } };
|
|
return { deps: { ctx, env, tools: { ffmpeg: "ffmpeg", ffprobe: "ffprobe" }, python: PYTHON }, dataDir, queued, jc, progress };
|
|
}
|