chore: converts e2e suites to new pattern

This commit is contained in:
James
2024-04-01 16:37:12 -04:00
parent df75914e30
commit 5e52339135
12 changed files with 24 additions and 30 deletions

View File

@@ -1,11 +1,13 @@
import type { Payload } from 'payload'
import path from 'path'
import { fileURLToPath } from 'url'
import type { NextRESTClient } from '../helpers/NextRESTClient.js'
import { devUser } from '../credentials.js'
import { initPayloadInt } from '../helpers/initPayloadInt.js'
import { postsSlug } from './collections/Posts/index.js'
import configPromise from './config.js'
let payload: Payload
let token: string
@@ -13,12 +15,15 @@ let restClient: NextRESTClient
const { email, password } = devUser
const filename = fileURLToPath(import.meta.url)
const dirname = path.dirname(filename)
describe('_Community Tests', () => {
// --__--__--__--__--__--__--__--__--__
// Boilerplate test setup/teardown
// --__--__--__--__--__--__--__--__--__
beforeAll(async () => {
const initialized = await initPayloadInt(configPromise)
const initialized = await initPayloadInt(dirname)
;({ payload, restClient } = initialized)
const data = await restClient

View File

@@ -18,7 +18,6 @@ import {
import { AdminUrlUtil } from '../helpers/adminUrlUtil.js'
import { initPayloadE2E } from '../helpers/initPayloadE2E.js'
import { POLL_TOPASS_TIMEOUT } from '../playwright.config.js'
import config from './config.js'
import {
docLevelAccessSlug,
readOnlySlug,
@@ -50,7 +49,7 @@ describe('access control', () => {
let serverURL: string
beforeAll(async ({ browser }) => {
;({ payload, serverURL } = await initPayloadE2E({ config, dirname }))
;({ payload, serverURL } = await initPayloadE2E({ dirname }))
url = new AdminUrlUtil(serverURL, slug)
restrictedUrl = new AdminUrlUtil(serverURL, restrictedSlug)

View File

@@ -5,11 +5,10 @@ import { expect, test } from '@playwright/test'
import path from 'path'
import { fileURLToPath } from 'url'
import { delayNetwork, initPageConsoleErrorCatch, login, saveDocAndAssert } from '../helpers.js'
import { initPageConsoleErrorCatch, login, saveDocAndAssert } from '../helpers.js'
import { AdminUrlUtil } from '../helpers/adminUrlUtil.js'
import { initPayloadE2E } from '../helpers/initPayloadE2E.js'
import { POLL_TOPASS_TIMEOUT } from '../playwright.config.js'
import config from './config.js'
import { apiKeysSlug, slug } from './shared.js'
const filename = fileURLToPath(import.meta.url)
const dirname = path.dirname(filename)
@@ -35,7 +34,7 @@ describe('auth', () => {
let apiURL: string
beforeAll(async ({ browser }) => {
;({ serverURL, payload } = await initPayloadE2E({ config, dirname }))
;({ serverURL, payload } = await initPayloadE2E({ dirname }))
apiURL = `${serverURL}/api`
url = new AdminUrlUtil(serverURL, slug)

View File

@@ -1,15 +1,13 @@
import type { Page } from '@playwright/test'
import { expect, test } from '@playwright/test'
import path from 'path'
import { fileURLToPath } from 'url'
import { initPageConsoleErrorCatch } from '../helpers.js'
import { initPayloadE2E } from '../helpers/initPayloadE2E.js'
import config from './config.js'
const { beforeAll, describe } = test
import path from 'path'
import { fileURLToPath } from 'url'
const filename = fileURLToPath(import.meta.url)
const dirname = path.dirname(filename)
@@ -18,7 +16,7 @@ describe('field error states', () => {
let page: Page
beforeAll(async ({ browser }) => {
;({ serverURL } = await initPayloadE2E({ config, dirname }))
;({ serverURL } = await initPayloadE2E({ dirname }))
const context = await browser.newContext()
page = await context.newPage()
initPageConsoleErrorCatch(page)

View File

@@ -15,7 +15,6 @@ import { initPayloadE2E } from '../helpers/initPayloadE2E.js'
import { RESTClient } from '../helpers/rest.js'
import { POLL_TOPASS_TIMEOUT } from '../playwright.config.js'
import { lexicalDocData } from './collections/Lexical/data.js'
import config from './config.js'
import { clearAndSeedEverything } from './seed.js'
import { lexicalFieldsSlug } from './slugs.js'
const filename = fileURLToPath(import.meta.url)
@@ -49,7 +48,7 @@ async function navigateToLexicalFields(navigateToListView: boolean = true) {
describe('lexical', () => {
beforeAll(async ({ browser }) => {
process.env.SEED_IN_CONFIG_ONINIT = 'false' // Makes it so the payload config onInit seed is not run. Otherwise, the seed would be run unnecessarily twice for the initial test run - once for beforeEach and once for onInit
;({ payload, serverURL } = await initPayloadE2E({ config, dirname }))
;({ payload, serverURL } = await initPayloadE2E({ dirname }))
const context = await browser.newContext()
page = await context.newPage()

View File

@@ -1,5 +1,6 @@
import type { SanitizedConfig } from 'payload/config'
import path from 'path'
import { type Payload, getPayload } from 'payload'
import { NextRESTClient } from './NextRESTClient.js'
@@ -9,9 +10,10 @@ import { startMemoryDB } from './startMemoryDB.js'
* Initialize Payload configured for integration tests
*/
export async function initPayloadInt(
config: Promise<SanitizedConfig>,
dirname: string,
): Promise<{ config: SanitizedConfig; payload: Payload; restClient: NextRESTClient }> {
await startMemoryDB()
const { default: config } = await import(path.resolve(dirname, 'config.ts'))
const payload = await getPayload({ config })
const restClient = new NextRESTClient(payload.config)

View File

@@ -8,7 +8,6 @@ import { fileURLToPath } from 'url'
import { exactText, initPageConsoleErrorCatch, saveDocAndAssert } from '../helpers.js'
import { AdminUrlUtil } from '../helpers/adminUrlUtil.js'
import { initPayloadE2E } from '../helpers/initPayloadE2E.js'
import config from './config.js'
import { mobileBreakpoint } from './shared.js'
const filename = fileURLToPath(import.meta.url)
const dirname = path.dirname(filename)
@@ -47,7 +46,7 @@ describe('Live Preview', () => {
}
beforeAll(async ({ browser }) => {
;({ serverURL, payload } = await initPayloadE2E({ config, dirname }))
;({ serverURL, payload } = await initPayloadE2E({ dirname }))
url = new AdminUrlUtil(serverURL, 'pages')
const context = await browser.newContext()
page = await context.newPage()

View File

@@ -17,7 +17,6 @@ import {
import { AdminUrlUtil } from '../helpers/adminUrlUtil.js'
import { initPayloadE2E } from '../helpers/initPayloadE2E.js'
import { POLL_TOPASS_TIMEOUT } from '../playwright.config.js'
import config from './config.js'
import {
englishTitle,
localizedPostsSlug,
@@ -52,10 +51,7 @@ let serverURL: string
describe('Localization', () => {
beforeAll(async ({ browser }) => {
;({ payload, serverURL } = await initPayloadE2E({
config,
dirname,
}))
;({ payload, serverURL } = await initPayloadE2E({ dirname }))
url = new AdminUrlUtil(serverURL, localizedPostsSlug)
urlWithRequiredLocalizedFields = new AdminUrlUtil(serverURL, withRequiredLocalizedFields)

View File

@@ -9,7 +9,6 @@ import type { Page as PayloadPage } from './payload-types.js'
import { initPageConsoleErrorCatch } from '../helpers.js'
import { AdminUrlUtil } from '../helpers/adminUrlUtil.js'
import { initPayloadE2E } from '../helpers/initPayloadE2E.js'
import config from './config.js'
const filename = fileURLToPath(import.meta.url)
const dirname = path.dirname(filename)
@@ -24,7 +23,7 @@ let childId: string
describe('Nested Docs Plugin', () => {
beforeAll(async ({ browser }) => {
const { serverURL, payload } = await initPayloadE2E({ config, dirname })
const { serverURL, payload } = await initPayloadE2E({ dirname })
url = new AdminUrlUtil(serverURL, 'pages')
const context = await browser.newContext()
page = await context.newPage()

View File

@@ -10,7 +10,6 @@ import type { Page as PayloadPage } from './payload-types.js'
import { initPageConsoleErrorCatch } from '../helpers.js'
import { AdminUrlUtil } from '../helpers/adminUrlUtil.js'
import { initPayloadE2E } from '../helpers/initPayloadE2E.js'
import config from './config.js'
import { mediaSlug } from './shared.js'
const filename = fileURLToPath(import.meta.url)
@@ -24,7 +23,7 @@ let id: string
describe('SEO Plugin', () => {
beforeAll(async ({ browser }) => {
const { serverURL, payload } = await initPayloadE2E({ config, dirname })
const { serverURL, payload } = await initPayloadE2E({ dirname })
url = new AdminUrlUtil(serverURL, 'pages')
const context = await browser.newContext()

View File

@@ -42,7 +42,6 @@ import {
import { AdminUrlUtil } from '../helpers/adminUrlUtil.js'
import { initPayloadE2E } from '../helpers/initPayloadE2E.js'
import { POLL_TOPASS_TIMEOUT } from '../playwright.config.js'
import config from './config.js'
import { clearAndSeedEverything } from './seed.js'
import { titleToDelete } from './shared.js'
import {
@@ -89,7 +88,7 @@ describe('versions', () => {
beforeAll(async ({ browser }) => {
process.env.SEED_IN_CONFIG_ONINIT = 'false' // Makes it so the payload config onInit seed is not run. Otherwise, the seed would be run unnecessarily twice for the initial test run - once for beforeEach and once for onInit
;({ payload, serverURL } = await initPayloadE2E({ config, dirname }))
;({ payload, serverURL } = await initPayloadE2E({ dirname }))
const context = await browser.newContext()
page = await context.newPage()

View File

@@ -37,7 +37,7 @@
],
"paths": {
"@payload-config": [
"./test/access-control/config.ts"
"./test/_community/config.ts"
],
"@payloadcms/live-preview": [
"./packages/live-preview/src"
@@ -160,4 +160,4 @@
".next/types/**/*.ts",
"scripts/**/*.ts"
]
}
}