Tests: boot Payload without type generation, guard against the leak

Outside production getPayload() spawns a detached generate:types child.
With no PAYLOAD_CONFIG_PATH it never finds a config (tsconfig rootDir
'./' sends Payload's findUpSync into an endless loop), so every full
vitest run left six processes spinning at ~40% CPU.

- test/helpers.ts: buildTestConfig() = buildConfig with
  typescript.autoGenerate false
- the six tests that boot Payload use it
- test/testConfig.test.ts: fails if a test calls buildConfig directly

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
Radosław Smoliński
2026-10-27 14:59:41 +01:00
co-authored by Claude Opus 5.5
parent e53d09b720
commit 53a8920564
8 changed files with 56 additions and 14 deletions
+12 -1
View File
@@ -1,7 +1,18 @@
import type { BasePayload } from 'payload'
import type { BasePayload, Config } from 'payload'
import { buildConfig } from 'payload'
import { vi } from 'vitest'
/**
* The only way a test builds a real Payload config. Outside production
* getPayload() spawns a detached `payload generate:types` child; with no
* PAYLOAD_CONFIG_PATH it never finds a config (tsconfig rootDir "./" makes
* Payload's findUpSync loop forever) and is left spinning after vitest exits.
* test/testConfig.test.ts fails when a test calls buildConfig directly.
*/
export const buildTestConfig = (config: Config) =>
buildConfig({ ...config, typescript: { ...config.typescript, autoGenerate: false } })
type FakeOptions = {
forms?: Record<string, { fields: Record<string, unknown>[] }>
integrations?: Record<string, unknown>