chore: _community e2e

This commit is contained in:
James
2024-03-12 10:01:51 -04:00
parent b327dd31b7
commit 0fc120d7d5
2 changed files with 13 additions and 31 deletions

View File

@@ -7,18 +7,17 @@ import { fileURLToPath } from 'url'
import { initPageConsoleErrorCatch } from '../helpers.js' import { initPageConsoleErrorCatch } from '../helpers.js'
import { AdminUrlUtil } from '../helpers/adminUrlUtil.js' import { AdminUrlUtil } from '../helpers/adminUrlUtil.js'
import { initPayloadE2E } from '../helpers/configHelpers.js' import { initPayloadE2E } from '../helpers/configHelpers.js'
import config from './config.js'
const filename = fileURLToPath(import.meta.url) const filename = fileURLToPath(import.meta.url)
const dirname = path.dirname(filename) const dirname = path.dirname(filename)
const { beforeAll, describe } = test
describe('Admin Panel', () => { describe('Admin Panel', () => {
let page: Page let page: Page
let url: AdminUrlUtil let url: AdminUrlUtil
beforeAll(async ({ browser }) => { test.beforeAll(async ({ browser }) => {
const { serverURL } = await initPayloadE2E({ dirname }) const { payload, serverURL } = await initPayloadE2E({ config, dirname })
url = new AdminUrlUtil(serverURL, 'posts') url = new AdminUrlUtil(serverURL, 'posts')
const context = await browser.newContext() const context = await browser.newContext()

View File

@@ -1,19 +1,24 @@
import { spawn } from 'child_process'
import getPort from 'get-port' import getPort from 'get-port'
import { nextDev } from 'next/dist/cli/next-dev.js' import { nextDev } from 'next/dist/cli/next-dev.js'
import path from 'path' import path from 'path'
import type { SanitizedConfig } from '../../packages/payload/src/config/types.js'
import type { Payload } 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'
type Args = { type Args = {
config: Promise<SanitizedConfig>
dirname: string dirname: string
} }
type Result = { type Result = {
payload: Payload
serverURL: string serverURL: string
} }
export async function initPayloadE2E({ dirname }: Args): Promise<Result> { export async function initPayloadE2E({ config, dirname }: Args): Promise<Result> {
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'
@@ -21,6 +26,8 @@ export async function initPayloadE2E({ dirname }: Args): Promise<Result> {
process.env.PAYLOAD_DROP_DATABASE = 'true' process.env.PAYLOAD_DROP_DATABASE = 'true'
process.env.PORT = String(port) process.env.PORT = String(port)
const payload = await getPayload({ config })
// @ts-expect-error // @ts-expect-error
process.env.NODE_ENV = 'test' process.env.NODE_ENV = 'test'
@@ -33,29 +40,5 @@ export async function initPayloadE2E({ dirname }: Args): Promise<Result> {
}) })
await wait(3000) await wait(3000)
return { serverURL } return { payload, serverURL }
}
export async function initPayloadSpawn({ dirname }: Args): Promise<Result> {
const port = await getPort()
const serverURL = `http://localhost:${port}`
// Tried using a child process to get
// turbopack to pick up our tsconfig aliases
// but this didn't make a difference.
// Keeping it here so we can continue to try.
spawn('pnpm', ['dev', '--turbo'], {
cwd: path.resolve(dirname, '../../'),
env: {
...process.env,
NODE_ENV: 'test',
PORT: String(port),
PAYLOAD_CONFIG_PATH: path.resolve(dirname, '../../config.js'),
PAYLOAD_DROP_DATABASE: 'true',
},
})
await wait(3000)
return { serverURL }
} }