From bfdd29f941fba231efb6a59c8995601b982d691b Mon Sep 17 00:00:00 2001 From: Amruth Pillai Date: Mon, 17 Aug 2026 22:19:52 +0200 Subject: [PATCH] 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. --- apps/server/src/openapi/generator.test.ts | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/apps/server/src/openapi/generator.test.ts b/apps/server/src/openapi/generator.test.ts index 85fc0d31b..ddfec69fc 100644 --- a/apps/server/src/openapi/generator.test.ts +++ b/apps/server/src/openapi/generator.test.ts @@ -18,10 +18,12 @@ type GeneratedSpecView = { >; }; -async function generateSpec() { - process.env.APP_URL ??= "https://rxresu.me"; - process.env.DATABASE_URL ??= "postgresql://localhost/reactive_resume_test"; - process.env.AUTH_SECRET ??= "openapi-generator-test-process-only"; +// Building the spec walks every router and resume JSON schema, which costs seconds. It is +// deterministic and every test here only reads it, so generate it once for the whole file — +// regenerating per test made the first case time out under a loaded machine. +let specPromise: ReturnType | undefined; + +async function generateOnce() { const { generateOpenApiSpec } = await import("./generator"); return generateOpenApiSpec({ 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) { return spec.paths?.[path]?.[method]?.requestBody?.content?.["application/json"]?.schema; }