test: parse and update tsconfig in before test hook

This commit is contained in:
Elliot DeNolf
2024-04-30 00:23:56 -04:00
parent 45b3f06e1b
commit dc31d9c715
2 changed files with 14 additions and 1 deletions

View File

@@ -35,6 +35,7 @@ const packageWhitelist = [
// Adapters
'email-nodemailer',
'email-resend-rest',
'storage-s3',
'storage-azure',

View File

@@ -1,14 +1,20 @@
// @ts-check
import { existsSync, promises } from 'fs'
import { parse, stringify } from 'comment-json'
import path from 'path'
import { fileURLToPath } from 'url'
const { rm } = promises
const { readFile, writeFile, rm } = promises
const filename = fileURLToPath(import.meta.url)
const dirname = path.dirname(filename)
export const createTestHooks = async (testSuiteName = '_community') => {
const tsConfigPath = path.resolve(dirname, '../tsconfig.json')
const tsConfigContent = await readFile(tsConfigPath, 'utf8')
const tsConfig = parse(tsConfigContent)
return {
/**
* Clear next webpack cache and set '@payload-config' path in tsconfig.json
@@ -20,6 +26,12 @@ export const createTestHooks = async (testSuiteName = '_community') => {
await rm(nextCache, { recursive: true })
}
// Set '@payload-config' in tsconfig.json
// @ts-expect-error
tsConfig.compilerOptions.paths['@payload-config'] = [`./test/${testSuiteName}/config.ts`]
await writeFile(tsConfigPath, stringify(tsConfig, null, 2) + '\n')
process.env.PAYLOAD_CONFIG_PATH = path.resolve(testSuiteName, 'config')
},
}