test(server): generate the OpenAPI spec once per suite

Each case rebuilt the whole spec, which walks every router and resume JSON
schema. The first case already carried a raised 15s timeout and still timed out
on a loaded machine. The spec is deterministic and only read here, so build it
once: the file drops from over 15s to 1.86s.
This commit is contained in:
Amruth Pillai
2026-08-17 22:19:52 +02:00
parent e8508e6d03
commit bfdd29f941
+11 -4
View File
@@ -18,10 +18,12 @@ type GeneratedSpecView = {
>; >;
}; };
async function generateSpec() { // Building the spec walks every router and resume JSON schema, which costs seconds. It is
process.env.APP_URL ??= "https://rxresu.me"; // deterministic and every test here only reads it, so generate it once for the whole file —
process.env.DATABASE_URL ??= "postgresql://localhost/reactive_resume_test"; // regenerating per test made the first case time out under a loaded machine.
process.env.AUTH_SECRET ??= "openapi-generator-test-process-only"; let specPromise: ReturnType<typeof generateOnce> | undefined;
async function generateOnce() {
const { generateOpenApiSpec } = await import("./generator"); const { generateOpenApiSpec } = await import("./generator");
return generateOpenApiSpec({ return generateOpenApiSpec({
appUrl: "https://rxresu.me", appUrl: "https://rxresu.me",
@@ -29,6 +31,11 @@ async function generateSpec() {
}); });
} }
function generateSpec() {
specPromise ??= generateOnce();
return specPromise;
}
function getRequestSchema(spec: GeneratedSpecView, path: string, method: string) { function getRequestSchema(spec: GeneratedSpecView, path: string, method: string) {
return spec.paths?.[path]?.[method]?.requestBody?.content?.["application/json"]?.schema; return spec.paths?.[path]?.[method]?.requestBody?.content?.["application/json"]?.schema;
} }