chore: automatically adjust tsconfig @payload-config path when running e2e tests

This commit is contained in:
Alessio Gravili
2024-03-13 12:32:06 -04:00
parent e3c6d5859b
commit 8954af5c53

View File

@@ -1,6 +1,11 @@
import getPort from 'get-port'
import json5 from 'json5'
import { nextDev } from 'next/dist/cli/next-dev.js'
import path from 'path'
import path, { resolve } from 'path'
const { parse } = json5
import { promises as _promises, promises } from 'fs'
const { readFile } = promises
const { writeFile } = _promises
import type { SanitizedConfig } from '../../packages/payload/src/config/types.js'
import type { Payload } from '../../packages/payload/src/index.js'
@@ -22,10 +27,20 @@ export async function initPayloadE2E({ config, dirname }: Args): Promise<Result>
const port = await getPort()
const serverURL = `http://localhost:${port}`
process.env.NODE_OPTIONS = '--no-deprecation'
process.env.PAYLOAD_CONFIG_PATH = path.resolve(dirname, './config.js')
const configPath = path.resolve(dirname, './config.js')
process.env.PAYLOAD_CONFIG_PATH = configPath
process.env.PAYLOAD_DROP_DATABASE = 'true'
process.env.PORT = String(port)
const testSuite = configPath.split('/test/')[1].split('/')[0]
// Set path.'payload-config' in tsconfig.json
const tsConfigPath = resolve(process.cwd(), 'tsconfig.json')
const tsConfig = await parse(await readFile(tsConfigPath, 'utf8'))
tsConfig.compilerOptions.paths['@payload-config'] = [`./test/${testSuite}/config.ts`]
await writeFile(tsConfigPath, JSON.stringify(tsConfig, null, 2))
const payload = await getPayload({ config })
// @ts-expect-error