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]>
26 lines
1.1 KiB
TypeScript
26 lines
1.1 KiB
TypeScript
/**
|
|
* Guard: a test that boots Payload with a raw buildConfig leaks a spinning
|
|
* `payload generate:types` process per run (see buildTestConfig in helpers.ts).
|
|
*/
|
|
import { readdirSync, readFileSync } from 'node:fs'
|
|
import path from 'node:path'
|
|
import { describe, expect, test } from 'vitest'
|
|
|
|
import { buildTestConfig } from './helpers.js'
|
|
|
|
const dir = import.meta.dirname
|
|
|
|
describe('test configs never auto-generate types', () => {
|
|
test('buildTestConfig turns autoGenerate off', async () => {
|
|
const config = await buildTestConfig({ collections: [], secret: 'x', typescript: { outputFile: 'types.ts' } } as never)
|
|
expect(config.typescript).toMatchObject({ autoGenerate: false, outputFile: 'types.ts' })
|
|
})
|
|
|
|
test('no test calls buildConfig from payload directly', () => {
|
|
const offenders = readdirSync(dir)
|
|
.filter((f) => f.endsWith('.ts') && f !== 'helpers.ts' && f !== 'testConfig.test.ts')
|
|
.filter((f) => /\bbuildConfig\b/.test(readFileSync(path.join(dir, f), 'utf8').replace(/buildTestConfig/g, '')))
|
|
expect(offenders).toEqual([])
|
|
})
|
|
})
|