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; }