* feat(richtext-lexical): 'bottom' position value for plugins * feat: TestRecorderFeature * chore: restructuring to seed and clear db before each test * chore: make sure all tests pass * chore: make sure indexes are created in seed.ts - this fixes one erroring test * chore: speed up test runs through db snapshots * chore: support drizzle when resetting db * chore: simplify seeding process, by moving boilerplate db reset / snapshot logic into a wrapper function * chore: add new seeding process to admin test suite * chore(deps): upgrade jest and playwright * chore: make sure mongoose-specific tests are not skipped * chore: fix point test, which was depending on another test (that's bad!) * chore: fix incorrect import * chore: remove unnecessary comments * chore: clearly label lexicalE2E test file as todo * chore: simplify seed logic * chore: move versions test suite to new seed system
71 lines
1.7 KiB
TypeScript
71 lines
1.7 KiB
TypeScript
import swcRegister from '@swc/register'
|
|
import express from 'express'
|
|
import getPort from 'get-port'
|
|
import path from 'path'
|
|
import shelljs from 'shelljs'
|
|
import { v4 as uuid } from 'uuid'
|
|
|
|
import type { Payload } from '../../packages/payload/src'
|
|
import type { InitOptions } from '../../packages/payload/src/config/types'
|
|
|
|
import payload from '../../packages/payload/src'
|
|
|
|
type Options = {
|
|
__dirname: string
|
|
init?: Partial<InitOptions>
|
|
}
|
|
|
|
type InitializedPayload = { payload: Payload; serverURL: string }
|
|
|
|
export async function initPayloadE2E(__dirname: string): Promise<InitializedPayload> {
|
|
const webpackCachePath = path.resolve(__dirname, '../../node_modules/.cache/webpack')
|
|
shelljs.rm('-rf', webpackCachePath)
|
|
return initPayloadTest({
|
|
__dirname,
|
|
init: {
|
|
local: false,
|
|
},
|
|
})
|
|
}
|
|
|
|
export async function initPayloadTest(options: Options): Promise<InitializedPayload> {
|
|
const initOptions = {
|
|
local: true,
|
|
secret: uuid(),
|
|
mongoURL: `mongodb://localhost/${uuid()}`,
|
|
...(options.init || {}),
|
|
}
|
|
|
|
process.env.PAYLOAD_DROP_DATABASE = 'true'
|
|
process.env.NODE_ENV = 'test'
|
|
process.env.PAYLOAD_CONFIG_PATH = path.resolve(options.__dirname, './config.ts')
|
|
|
|
if (!initOptions?.local) {
|
|
initOptions.express = express()
|
|
}
|
|
|
|
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
// @ts-ignore - bad @swc/register types
|
|
swcRegister({
|
|
sourceMaps: 'inline',
|
|
jsc: {
|
|
parser: {
|
|
syntax: 'typescript',
|
|
tsx: true,
|
|
},
|
|
},
|
|
module: {
|
|
type: 'commonjs',
|
|
},
|
|
})
|
|
|
|
await payload.init(initOptions)
|
|
|
|
const port = await getPort()
|
|
if (initOptions.express) {
|
|
initOptions.express.listen(port)
|
|
}
|
|
|
|
return { serverURL: `http://localhost:${port}`, payload }
|
|
}
|