test: parse and update tsconfig in before test hook
This commit is contained in:
@@ -35,6 +35,7 @@ const packageWhitelist = [
|
|||||||
|
|
||||||
// Adapters
|
// Adapters
|
||||||
'email-nodemailer',
|
'email-nodemailer',
|
||||||
|
'email-resend-rest',
|
||||||
|
|
||||||
'storage-s3',
|
'storage-s3',
|
||||||
'storage-azure',
|
'storage-azure',
|
||||||
|
|||||||
@@ -1,14 +1,20 @@
|
|||||||
// @ts-check
|
// @ts-check
|
||||||
|
|
||||||
import { existsSync, promises } from 'fs'
|
import { existsSync, promises } from 'fs'
|
||||||
|
import { parse, stringify } from 'comment-json'
|
||||||
|
|
||||||
import path from 'path'
|
import path from 'path'
|
||||||
import { fileURLToPath } from 'url'
|
import { fileURLToPath } from 'url'
|
||||||
|
|
||||||
const { rm } = promises
|
const { readFile, writeFile, rm } = promises
|
||||||
const filename = fileURLToPath(import.meta.url)
|
const filename = fileURLToPath(import.meta.url)
|
||||||
const dirname = path.dirname(filename)
|
const dirname = path.dirname(filename)
|
||||||
|
|
||||||
export const createTestHooks = async (testSuiteName = '_community') => {
|
export const createTestHooks = async (testSuiteName = '_community') => {
|
||||||
|
const tsConfigPath = path.resolve(dirname, '../tsconfig.json')
|
||||||
|
const tsConfigContent = await readFile(tsConfigPath, 'utf8')
|
||||||
|
const tsConfig = parse(tsConfigContent)
|
||||||
|
|
||||||
return {
|
return {
|
||||||
/**
|
/**
|
||||||
* Clear next webpack cache and set '@payload-config' path in tsconfig.json
|
* 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 })
|
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')
|
process.env.PAYLOAD_CONFIG_PATH = path.resolve(testSuiteName, 'config')
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user