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