test: refine testHooks
This commit is contained in:
@@ -1,10 +1,11 @@
|
||||
import { existsSync, promises } from 'fs'
|
||||
import json5 from 'json5'
|
||||
import { dirname, resolve } from 'path'
|
||||
import path from 'path'
|
||||
import { fileURLToPath } from 'url'
|
||||
|
||||
const { readFile, writeFile, rm } = promises
|
||||
const { parse } = json5
|
||||
const filename = fileURLToPath(import.meta.url)
|
||||
const dirname = path.dirname(filename)
|
||||
|
||||
type TestHooks = {
|
||||
afterTest: () => Promise<void>
|
||||
@@ -12,13 +13,10 @@ type TestHooks = {
|
||||
}
|
||||
|
||||
export const createTestHooks = async (testSuiteName = '_community'): Promise<TestHooks> => {
|
||||
const __filename = fileURLToPath(import.meta.url)
|
||||
const __dirname = dirname(__filename)
|
||||
|
||||
console.log('\nUsing config:', testSuiteName, '\n')
|
||||
|
||||
const tsConfigPath = resolve(__dirname, '..', 'tsconfig.json')
|
||||
const tsConfig = await parse(await readFile(tsConfigPath, 'utf8'))
|
||||
const tsConfigPath = path.resolve(dirname, '..', 'tsconfig.json')
|
||||
const tsConfig = await json5.parse(await readFile(tsConfigPath, 'utf8'))
|
||||
const originalPayloadConfigTsValue =
|
||||
tsConfig.compilerOptions.paths['@payload-config'] ?? './test/_community/config.ts'
|
||||
|
||||
@@ -28,7 +26,7 @@ export const createTestHooks = async (testSuiteName = '_community'): Promise<Tes
|
||||
*/
|
||||
beforeTest: async () => {
|
||||
// Delete next webpack cache
|
||||
const nextWebpackCache = resolve(__dirname, '..', '.next/cache/webpack')
|
||||
const nextWebpackCache = path.resolve(dirname, '..', '.next/cache/webpack')
|
||||
if (existsSync(nextWebpackCache)) {
|
||||
await rm(nextWebpackCache, { recursive: true })
|
||||
}
|
||||
@@ -37,7 +35,7 @@ export const createTestHooks = async (testSuiteName = '_community'): Promise<Tes
|
||||
tsConfig.compilerOptions.paths['@payload-config'] = [`./test/${testSuiteName}/config.ts`]
|
||||
await writeFile(tsConfigPath, JSON.stringify(tsConfig, null, 2))
|
||||
|
||||
const PAYLOAD_CONFIG_PATH = resolve(testSuiteName, 'config')
|
||||
const PAYLOAD_CONFIG_PATH = path.resolve(testSuiteName, 'config')
|
||||
process.env.PAYLOAD_CONFIG_PATH = PAYLOAD_CONFIG_PATH
|
||||
},
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user