chore: alter @payload-config tsconfig for e2e tests
This commit is contained in:
@@ -8,3 +8,4 @@
|
|||||||
**/dist/**
|
**/dist/**
|
||||||
**/node_modules
|
**/node_modules
|
||||||
**/temp
|
**/temp
|
||||||
|
playwright.config.ts
|
||||||
|
|||||||
@@ -1,13 +0,0 @@
|
|||||||
import fs from 'fs'
|
|
||||||
|
|
||||||
async function globalSetup() {
|
|
||||||
try {
|
|
||||||
fs.rm('.next', { recursive: true }, () => {
|
|
||||||
console.log('Playwright removed the .next folder.')
|
|
||||||
})
|
|
||||||
} catch (err) {
|
|
||||||
console.error('Playwright failed to removed the .next folder:', err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export default globalSetup
|
|
||||||
@@ -14,5 +14,4 @@ export default defineConfig({
|
|||||||
timeout: 45000,
|
timeout: 45000,
|
||||||
},
|
},
|
||||||
workers: 16,
|
workers: 16,
|
||||||
globalSetup: './playwright-global-setup',
|
|
||||||
})
|
})
|
||||||
|
|||||||
35
test/beforeTest.js
Normal file
35
test/beforeTest.js
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
/* eslint-disable @typescript-eslint/no-var-requires */
|
||||||
|
import { promises as __promises, promises as _promises, existsSync, promises } from 'fs'
|
||||||
|
import json5 from 'json5'
|
||||||
|
import { dirname, resolve } from 'path'
|
||||||
|
import { fileURLToPath } from 'url'
|
||||||
|
|
||||||
|
const { readFile } = promises
|
||||||
|
const { writeFile } = _promises
|
||||||
|
const { rm } = __promises
|
||||||
|
const { parse } = json5
|
||||||
|
|
||||||
|
export const beforeTest = async (testSuiteName) => {
|
||||||
|
const __filename = fileURLToPath(import.meta.url)
|
||||||
|
const __dirname = dirname(__filename)
|
||||||
|
|
||||||
|
const testSuite = testSuiteName || '_community'
|
||||||
|
|
||||||
|
console.log('\nUsing config:', testSuite, '\n')
|
||||||
|
|
||||||
|
// Delete next webpack cache
|
||||||
|
const nextWebpackCache = resolve(__dirname, '..', '.next/cache/webpack')
|
||||||
|
if (existsSync(nextWebpackCache)) {
|
||||||
|
await rm(nextWebpackCache, { recursive: true })
|
||||||
|
}
|
||||||
|
|
||||||
|
// Set path.'payload-config' in tsconfig.json
|
||||||
|
const tsConfigPath = resolve(__dirname, '..', 'tsconfig.json')
|
||||||
|
const tsConfig = await parse(await readFile(tsConfigPath, 'utf8'))
|
||||||
|
tsConfig.compilerOptions.paths['@payload-config'] = [`./test/${testSuite}/config.ts`]
|
||||||
|
|
||||||
|
await writeFile(tsConfigPath, JSON.stringify(tsConfig, null, 2))
|
||||||
|
|
||||||
|
const PAYLOAD_CONFIG_PATH = resolve(testSuite, 'config')
|
||||||
|
process.env.PAYLOAD_CONFIG_PATH = PAYLOAD_CONFIG_PATH
|
||||||
|
}
|
||||||
35
test/dev.js
35
test/dev.js
@@ -1,16 +1,8 @@
|
|||||||
/* eslint-disable @typescript-eslint/no-var-requires */
|
|
||||||
import { existsSync, promises, promises as _promises, promises as __promises } from 'fs'
|
|
||||||
import json5 from 'json5'
|
|
||||||
import minimist from 'minimist'
|
import minimist from 'minimist'
|
||||||
import { nextDev } from 'next/dist/cli/next-dev.js'
|
import { nextDev } from 'next/dist/cli/next-dev.js'
|
||||||
import { dirname, resolve } from 'path'
|
import { resolve } from 'path'
|
||||||
import { fileURLToPath } from 'url'
|
|
||||||
|
|
||||||
const { readFile } = promises
|
import { beforeTest } from './beforeTest.js'
|
||||||
const { writeFile } = _promises
|
|
||||||
const { rm } = __promises
|
|
||||||
|
|
||||||
const { parse } = json5
|
|
||||||
|
|
||||||
main()
|
main()
|
||||||
|
|
||||||
@@ -26,28 +18,7 @@ async function main() {
|
|||||||
process.env.TURBOPACK = '1'
|
process.env.TURBOPACK = '1'
|
||||||
}
|
}
|
||||||
|
|
||||||
const __filename = fileURLToPath(import.meta.url)
|
beforeTest(testSuiteArg)
|
||||||
const __dirname = dirname(__filename)
|
|
||||||
|
|
||||||
const testSuite = testSuiteArg || '_community'
|
|
||||||
|
|
||||||
console.log('\nUsing config:', testSuite, '\n')
|
|
||||||
|
|
||||||
// Delete next webpack cache
|
|
||||||
const nextWebpackCache = resolve(__dirname, '..', '.next/cache/webpack')
|
|
||||||
if (existsSync(nextWebpackCache)) {
|
|
||||||
await rm(nextWebpackCache, { recursive: true })
|
|
||||||
}
|
|
||||||
|
|
||||||
// Set path.'payload-config' in tsconfig.json
|
|
||||||
const tsConfigPath = resolve(__dirname, '..', 'tsconfig.json')
|
|
||||||
const tsConfig = await parse(await readFile(tsConfigPath, 'utf8'))
|
|
||||||
tsConfig.compilerOptions.paths['@payload-config'] = [`./test/${testSuite}/config.ts`]
|
|
||||||
|
|
||||||
await writeFile(tsConfigPath, JSON.stringify(tsConfig, null, 2))
|
|
||||||
|
|
||||||
const PAYLOAD_CONFIG_PATH = resolve(testSuite, 'config')
|
|
||||||
process.env.PAYLOAD_CONFIG_PATH = PAYLOAD_CONFIG_PATH
|
|
||||||
|
|
||||||
nextDev({ _: [resolve(__dirname, '..')], port: process.env.PORT || 3000 })
|
nextDev({ _: [resolve(__dirname, '..')], port: process.env.PORT || 3000 })
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,17 +1,14 @@
|
|||||||
|
import { promises as _promises } from 'fs'
|
||||||
import getPort from 'get-port'
|
import getPort from 'get-port'
|
||||||
import json5 from 'json5'
|
|
||||||
import { nextDev } from 'next/dist/cli/next-dev.js'
|
import { nextDev } from 'next/dist/cli/next-dev.js'
|
||||||
import path, { resolve } from 'path'
|
import path from 'path'
|
||||||
const { parse } = json5
|
|
||||||
import { promises as _promises, promises } from 'fs'
|
|
||||||
const { readFile } = promises
|
|
||||||
const { writeFile } = _promises
|
|
||||||
|
|
||||||
import type { SanitizedConfig } from '../../packages/payload/src/config/types.js'
|
import type { SanitizedConfig } from '../../packages/payload/src/config/types.js'
|
||||||
import type { Payload } from '../../packages/payload/src/index.js'
|
import type { Payload } from '../../packages/payload/src/index.js'
|
||||||
|
|
||||||
import { getPayload } from '../../packages/payload/src/index.js'
|
import { getPayload } from '../../packages/payload/src/index.js'
|
||||||
import wait from '../../packages/payload/src/utilities/wait.js'
|
import wait from '../../packages/payload/src/utilities/wait.js'
|
||||||
|
import { beforeTest } from '../beforeTest.js'
|
||||||
|
|
||||||
type Args = {
|
type Args = {
|
||||||
config: Promise<SanitizedConfig>
|
config: Promise<SanitizedConfig>
|
||||||
@@ -24,23 +21,15 @@ type Result = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export async function initPayloadE2E({ config, dirname }: Args): Promise<Result> {
|
export async function initPayloadE2E({ config, dirname }: Args): Promise<Result> {
|
||||||
|
const testSuiteName = dirname.split('/').pop()
|
||||||
|
await beforeTest(testSuiteName)
|
||||||
|
|
||||||
const port = await getPort()
|
const port = await getPort()
|
||||||
const serverURL = `http://localhost:${port}`
|
const serverURL = `http://localhost:${port}`
|
||||||
process.env.NODE_OPTIONS = '--no-deprecation'
|
process.env.NODE_OPTIONS = '--no-deprecation'
|
||||||
const configPath = path.resolve(dirname, './config.js')
|
|
||||||
process.env.PAYLOAD_CONFIG_PATH = configPath
|
|
||||||
process.env.PAYLOAD_DROP_DATABASE = 'true'
|
process.env.PAYLOAD_DROP_DATABASE = 'true'
|
||||||
process.env.PORT = String(port)
|
process.env.PORT = String(port)
|
||||||
|
|
||||||
const testSuite = configPath.split('/test/')[1].split('/')[0]
|
|
||||||
|
|
||||||
// Set path.'payload-config' in tsconfig.json
|
|
||||||
const tsConfigPath = resolve(process.cwd(), 'tsconfig.json')
|
|
||||||
const tsConfig = await parse(await readFile(tsConfigPath, 'utf8'))
|
|
||||||
tsConfig.compilerOptions.paths['@payload-config'] = [`./test/${testSuite}/config.ts`]
|
|
||||||
|
|
||||||
await writeFile(tsConfigPath, JSON.stringify(tsConfig, null, 2))
|
|
||||||
|
|
||||||
const payload = await getPayload({ config })
|
const payload = await getPayload({ config })
|
||||||
|
|
||||||
// @ts-expect-error
|
// @ts-expect-error
|
||||||
|
|||||||
Reference in New Issue
Block a user