get e2e and dev to work with test as new root directory
This commit is contained in:
@@ -1,49 +0,0 @@
|
||||
import { existsSync, promises } from 'fs'
|
||||
import json5 from 'json5'
|
||||
import path from 'path'
|
||||
import { fileURLToPath } from 'url'
|
||||
|
||||
const { readFile, writeFile, rm } = promises
|
||||
const filename = fileURLToPath(import.meta.url)
|
||||
const dirname = path.dirname(filename)
|
||||
|
||||
type TestHooks = {
|
||||
afterTest: () => Promise<void>
|
||||
beforeTest: () => Promise<void>
|
||||
}
|
||||
|
||||
export const createTestHooks = async (testSuiteName = '_community'): Promise<TestHooks> => {
|
||||
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'
|
||||
|
||||
return {
|
||||
/**
|
||||
* Clear next webpack cache and set '@payload-config' path in tsconfig.json
|
||||
*/
|
||||
beforeTest: async () => {
|
||||
// Delete next webpack cache
|
||||
const nextWebpackCache = path.resolve(dirname, '..', '.next/cache/webpack')
|
||||
if (existsSync(nextWebpackCache)) {
|
||||
await rm(nextWebpackCache, { recursive: true })
|
||||
}
|
||||
|
||||
// Set '@payload-config' in tsconfig.json
|
||||
tsConfig.compilerOptions.paths['@payload-config'] = [`./test/${testSuiteName}/config.ts`]
|
||||
await writeFile(tsConfigPath, JSON.stringify(tsConfig, null, 2))
|
||||
|
||||
const PAYLOAD_CONFIG_PATH = path.resolve(testSuiteName, 'config')
|
||||
process.env.PAYLOAD_CONFIG_PATH = PAYLOAD_CONFIG_PATH
|
||||
},
|
||||
/**
|
||||
* Reset the changes made to tsconfig.json
|
||||
*/
|
||||
afterTest: async () => {
|
||||
// Revert the changes made to tsconfig.json
|
||||
tsConfig.compilerOptions.paths['@payload-config'] = originalPayloadConfigTsValue
|
||||
|
||||
await writeFile(tsConfigPath, JSON.stringify(tsConfig, null, 2) + '\n')
|
||||
},
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user