Skip to content

Commit

Permalink
chore: deflake joins e2e tests (#11034)
Browse files Browse the repository at this point in the history
Previously, data created by other tests was also leaking into unrelated tests, causing them to fail. The new reset-db-between-tests logic added by this PR fixes this. 

Additionally, this increases playwright timeouts for CI, and adds a specific timeout override for opening a drawer, as it was incredibly slow in CI
  • Loading branch information
AlessioGr authored Feb 7, 2025
1 parent 7277f17 commit 098fe10
Show file tree
Hide file tree
Showing 31 changed files with 71 additions and 46 deletions.
2 changes: 1 addition & 1 deletion test/fields/collections/Array/e2e.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ describe('Array', () => {
if (client) {
await client.logout()
}
client = new RESTClient(null, { defaultSlug: 'users', serverURL })
client = new RESTClient({ defaultSlug: 'users', serverURL })
await client.login()

await ensureCompilationIsDone({ page, serverURL })
Expand Down
2 changes: 1 addition & 1 deletion test/fields/collections/Blocks/e2e.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ describe('Block fields', () => {
if (client) {
await client.logout()
}
client = new RESTClient(null, { defaultSlug: 'users', serverURL })
client = new RESTClient({ defaultSlug: 'users', serverURL })
await client.login()

await ensureCompilationIsDone({ page, serverURL })
Expand Down
2 changes: 1 addition & 1 deletion test/fields/collections/Checkbox/e2e.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ describe('Checkboxes', () => {
if (client) {
await client.logout()
}
client = new RESTClient(null, { defaultSlug: 'users', serverURL })
client = new RESTClient({ defaultSlug: 'users', serverURL })
await client.login()
await ensureCompilationIsDone({ page, serverURL })
})
Expand Down
2 changes: 1 addition & 1 deletion test/fields/collections/Collapsible/e2e.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ describe('Collapsibles', () => {
if (client) {
await client.logout()
}
client = new RESTClient(null, { defaultSlug: 'users', serverURL })
client = new RESTClient({ defaultSlug: 'users', serverURL })
await client.login()
await ensureCompilationIsDone({ page, serverURL })
})
Expand Down
2 changes: 1 addition & 1 deletion test/fields/collections/ConditionalLogic/e2e.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ describe('Conditional Logic', () => {
if (client) {
await client.logout()
}
client = new RESTClient(null, { defaultSlug: 'users', serverURL })
client = new RESTClient({ defaultSlug: 'users', serverURL })
await client.login()
await ensureCompilationIsDone({ page, serverURL })
})
Expand Down
2 changes: 1 addition & 1 deletion test/fields/collections/CustomID/e2e.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ describe('Custom IDs', () => {
if (client) {
await client.logout()
}
client = new RESTClient(null, { defaultSlug: 'users', serverURL })
client = new RESTClient({ defaultSlug: 'users', serverURL })
await client.login()
await ensureCompilationIsDone({ page, serverURL })
})
Expand Down
2 changes: 1 addition & 1 deletion test/fields/collections/Date/e2e.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ describe('Date', () => {
if (client) {
await client.logout()
}
client = new RESTClient(null, { defaultSlug: 'users', serverURL })
client = new RESTClient({ defaultSlug: 'users', serverURL })
await client.login()

await ensureCompilationIsDone({ page, serverURL })
Expand Down
2 changes: 1 addition & 1 deletion test/fields/collections/Email/e2e.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ describe('Email', () => {
if (client) {
await client.logout()
}
client = new RESTClient(null, { defaultSlug: 'users', serverURL })
client = new RESTClient({ defaultSlug: 'users', serverURL })
await client.login()

await ensureCompilationIsDone({ page, serverURL })
Expand Down
2 changes: 1 addition & 1 deletion test/fields/collections/Indexed/e2e.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ describe('Radio', () => {
if (client) {
await client.logout()
}
client = new RESTClient(null, { defaultSlug: 'users', serverURL })
client = new RESTClient({ defaultSlug: 'users', serverURL })
await client.login()
await ensureCompilationIsDone({ page, serverURL })
})
Expand Down
2 changes: 1 addition & 1 deletion test/fields/collections/JSON/e2e.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ describe('JSON', () => {
if (client) {
await client.logout()
}
client = new RESTClient(null, { defaultSlug: 'users', serverURL })
client = new RESTClient({ defaultSlug: 'users', serverURL })
await client.login()
await ensureCompilationIsDone({ page, serverURL })
})
Expand Down
2 changes: 1 addition & 1 deletion test/fields/collections/Lexical/e2e/blocks/e2e.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ describe('lexicalBlocks', () => {
if (client) {
await client.logout()
}
client = new RESTClient(null, { defaultSlug: 'rich-text-fields', serverURL })
client = new RESTClient({ defaultSlug: 'rich-text-fields', serverURL })
await client.login()
})

Expand Down
2 changes: 1 addition & 1 deletion test/fields/collections/Lexical/e2e/main/e2e.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ describe('lexicalMain', () => {
if (client) {
await client.logout()
}
client = new RESTClient(null, { defaultSlug: 'rich-text-fields', serverURL })
client = new RESTClient({ defaultSlug: 'rich-text-fields', serverURL })
await client.login()
})

Expand Down
2 changes: 1 addition & 1 deletion test/fields/collections/Number/e2e.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ describe('Number', () => {
if (client) {
await client.logout()
}
client = new RESTClient(null, { defaultSlug: 'users', serverURL })
client = new RESTClient({ defaultSlug: 'users', serverURL })
await client.login()
await ensureCompilationIsDone({ page, serverURL })
})
Expand Down
2 changes: 1 addition & 1 deletion test/fields/collections/Point/e2e.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ describe('Point', () => {
if (client) {
await client.logout()
}
client = new RESTClient(null, { defaultSlug: 'users', serverURL })
client = new RESTClient({ defaultSlug: 'users', serverURL })
await client.login()

await ensureCompilationIsDone({ page, serverURL })
Expand Down
2 changes: 1 addition & 1 deletion test/fields/collections/Radio/e2e.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ describe('Radio', () => {
if (client) {
await client.logout()
}
client = new RESTClient(null, { defaultSlug: 'users', serverURL })
client = new RESTClient({ defaultSlug: 'users', serverURL })
await client.login()
await ensureCompilationIsDone({ page, serverURL })
})
Expand Down
2 changes: 1 addition & 1 deletion test/fields/collections/Relationship/e2e.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ describe('relationship', () => {
if (client) {
await client.logout()
}
client = new RESTClient(null, { defaultSlug: 'users', serverURL })
client = new RESTClient({ defaultSlug: 'users', serverURL })
await client.login()

await ensureCompilationIsDone({ page, serverURL })
Expand Down
2 changes: 1 addition & 1 deletion test/fields/collections/RichText/e2e.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ describe('Rich Text', () => {
if (client) {
await client.logout()
}
client = new RESTClient(null, { defaultSlug: 'users', serverURL })
client = new RESTClient({ defaultSlug: 'users', serverURL })
await client.login()

await ensureCompilationIsDone({ page, serverURL })
Expand Down
2 changes: 1 addition & 1 deletion test/fields/collections/Row/e2e.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ describe('Row', () => {
if (client) {
await client.logout()
}
client = new RESTClient(null, { defaultSlug: 'users', serverURL })
client = new RESTClient({ defaultSlug: 'users', serverURL })
await client.login()
await ensureCompilationIsDone({ page, serverURL })
})
Expand Down
2 changes: 1 addition & 1 deletion test/fields/collections/Select/e2e.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ describe('Radio', () => {
if (client) {
await client.logout()
}
client = new RESTClient(null, { defaultSlug: 'users', serverURL })
client = new RESTClient({ defaultSlug: 'users', serverURL })
await client.login()
await ensureCompilationIsDone({ page, serverURL })
})
Expand Down
2 changes: 1 addition & 1 deletion test/fields/collections/Tabs/e2e.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ describe('Tabs', () => {
if (client) {
await client.logout()
}
client = new RESTClient(null, { defaultSlug: 'users', serverURL })
client = new RESTClient({ defaultSlug: 'users', serverURL })
await client.login()

await ensureCompilationIsDone({ page, serverURL })
Expand Down
2 changes: 1 addition & 1 deletion test/fields/collections/Tabs2/e2e.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ describe('Tabs', () => {
if (client) {
await client.logout()
}
client = new RESTClient(null, { defaultSlug: 'users', serverURL })
client = new RESTClient({ defaultSlug: 'users', serverURL })
await client.login()

await ensureCompilationIsDone({ page, serverURL })
Expand Down
2 changes: 1 addition & 1 deletion test/fields/collections/Text/e2e.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ describe('Text', () => {
if (client) {
await client.logout()
}
client = new RESTClient(null, { defaultSlug: 'users', serverURL })
client = new RESTClient({ defaultSlug: 'users', serverURL })
await client.login()

await ensureCompilationIsDone({ page, serverURL })
Expand Down
2 changes: 1 addition & 1 deletion test/fields/collections/UI/e2e.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ describe('Radio', () => {
if (client) {
await client.logout()
}
client = new RESTClient(null, { defaultSlug: 'users', serverURL })
client = new RESTClient({ defaultSlug: 'users', serverURL })
await client.login()
await ensureCompilationIsDone({ page, serverURL })
})
Expand Down
2 changes: 1 addition & 1 deletion test/fields/collections/Upload/e2e.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ describe('Upload', () => {
if (client) {
await client.logout()
}
client = new RESTClient(null, { defaultSlug: 'users', serverURL })
client = new RESTClient({ defaultSlug: 'users', serverURL })
await client.login()

await ensureCompilationIsDone({ page, serverURL })
Expand Down
2 changes: 1 addition & 1 deletion test/fields/collections/UploadRestricted/e2e.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ describe('Upload with restrictions', () => {
if (client) {
await client.logout()
}
client = new RESTClient(null, { defaultSlug: 'users', serverURL })
client = new RESTClient({ defaultSlug: 'users', serverURL })
await client.login()

await ensureCompilationIsDone({ page, serverURL })
Expand Down
7 changes: 2 additions & 5 deletions test/helpers/rest.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
import type { Config, PaginatedDocs, TypedUser, Where } from 'payload'
import type { PaginatedDocs, TypedUser, Where } from 'payload'

import * as qs from 'qs-esm'

Expand Down Expand Up @@ -110,8 +110,6 @@ type QueryResponse<T> = {
}

export class RESTClient {
private readonly config: Config

private defaultSlug: string

private token: string
Expand All @@ -120,8 +118,7 @@ export class RESTClient {

public user: TypedUser

constructor(config: Config, args: Args) {
this.config = config
constructor(args: Args) {
this.serverURL = args.serverURL
this.defaultSlug = args.defaultSlug
}
Expand Down
46 changes: 37 additions & 9 deletions test/joins/e2e.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,34 +13,64 @@ import {
exactText,
initPageConsoleErrorCatch,
saveDocAndAssert,
throttleTest,
} from '../helpers.js'
import { AdminUrlUtil } from '../helpers/adminUrlUtil.js'
import { navigateToDoc } from '../helpers/e2e/navigateToDoc.js'
import { initPayloadE2ENoConfig } from '../helpers/initPayloadE2ENoConfig.js'
import { TEST_TIMEOUT_LONG } from '../playwright.config.js'
import { EXPECT_TIMEOUT, TEST_TIMEOUT_LONG } from '../playwright.config.js'
import { categoriesJoinRestrictedSlug, categoriesSlug, postsSlug, uploadsSlug } from './shared.js'
import { reInitializeDB } from '../helpers/reInitializeDB.js'
import { RESTClient } from '../helpers/rest.js'

const filename = fileURLToPath(import.meta.url)
const dirname = path.dirname(filename)

let payload: PayloadTestSDK<Config>
let serverURL: string
let client: RESTClient

test.describe('Join Field', () => {
const { beforeAll, beforeEach, describe } = test

describe('Join Field', () => {
let page: Page
let categoriesURL: AdminUrlUtil
let uploadsURL: AdminUrlUtil
let categoriesJoinRestrictedURL: AdminUrlUtil
let categoryID: string | number

test.beforeAll(async ({ browser }, testInfo) => {
beforeAll(async ({ browser }, testInfo) => {
testInfo.setTimeout(TEST_TIMEOUT_LONG)
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 initPayloadE2ENoConfig<Config>({
dirname,
}))

categoriesURL = new AdminUrlUtil(serverURL, categoriesSlug)
uploadsURL = new AdminUrlUtil(serverURL, uploadsSlug)
categoriesJoinRestrictedURL = new AdminUrlUtil(serverURL, categoriesJoinRestrictedSlug)

const context = await browser.newContext()
page = await context.newPage()
initPageConsoleErrorCatch(page)
await ensureCompilationIsDone({ page, serverURL })

//await throttleTest({ context, delay: 'Slow 4G', page })
})

beforeEach(async () => {
await reInitializeDB({
serverURL,
snapshotKey: 'joinsTest',
uploadsDir: [],
})

if (client) {
await client.logout()
}
client = new RESTClient({ defaultSlug: postsSlug, serverURL })
await client.login()

const { docs } = await payload.find({
collection: categoriesSlug,
where: {
Expand All @@ -55,11 +85,6 @@ test.describe('Join Field', () => {
}

;({ id: categoryID } = docs[0])

const context = await browser.newContext()
page = await context.newPage()
initPageConsoleErrorCatch(page)
await ensureCompilationIsDone({ page, serverURL })
})

test('should populate joined relationships in table cells of list view', async () => {
Expand Down Expand Up @@ -254,6 +279,8 @@ test.describe('Join Field', () => {
const joinField = page.locator('#field-relatedPosts.field-type.join')
await expect(joinField).toBeVisible()

await expect(joinField.locator('tbody tr')).toHaveCount(3)

const addButton = joinField.locator('.relationship-table__actions button.doc-drawer__toggler', {
hasText: exactText('Add new'),
})
Expand All @@ -263,8 +290,9 @@ test.describe('Join Field', () => {
await addButton.click()
const drawer = page.locator('[id^=doc-drawer_posts_1_]')
await expect(drawer).toBeVisible()

const categoryField = drawer.locator('#field-category')
await expect(categoryField).toBeVisible()
await expect(categoryField).toBeVisible({ timeout: EXPECT_TIMEOUT * 5 })
const categoryValue = categoryField.locator('.relationship--single-value__text')
await expect(categoryValue).toHaveText('example')
const titleField = drawer.locator('#field-title')
Expand Down
6 changes: 3 additions & 3 deletions test/joins/seed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import {
const filename = fileURLToPath(import.meta.url)
const dirname = path.dirname(filename)

export const seed = async (_payload) => {
export const seed = async (_payload: Payload) => {
await _payload.create({
collection: 'users',
data: {
Expand Down Expand Up @@ -90,7 +90,7 @@ export const seed = async (_payload) => {
await _payload.create({
collection: postsSlug,
data: {
upload: uploadedImage.id,
upload: uploadedImage,
},
})

Expand Down Expand Up @@ -123,6 +123,6 @@ export async function clearAndSeedEverything(_payload: Payload) {
_payload,
collectionSlugs,
seedFunction: seed,
snapshotKey: 'adminTest',
snapshotKey: 'joinsTest',
})
}
2 changes: 1 addition & 1 deletion test/localization/e2e.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ describe('Localization', () => {

initPageConsoleErrorCatch(page)

client = new RESTClient(null, { defaultSlug: 'users', serverURL })
client = new RESTClient({ defaultSlug: 'users', serverURL })
await client.login()

await ensureCompilationIsDone({ page, serverURL })
Expand Down
4 changes: 2 additions & 2 deletions test/playwright.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ const dirname = path.dirname(filename)

dotenv.config({ path: path.resolve(dirname, 'test.env') })

let multiplier = process.env.CI ? 3 : 1
let smallMultiplier = process.env.CI ? 2 : 1
let multiplier = process.env.CI ? 5 : 1
let smallMultiplier = process.env.CI ? 4 : 1

export const TEST_TIMEOUT_LONG = 640000 * multiplier // 8*3 minutes - used as timeOut for the beforeAll
export const TEST_TIMEOUT = 40000 * multiplier
Expand Down
Loading

0 comments on commit 098fe10

Please sign in to comment.