From e912dde08ded93515228d17bb6e9f2fef1e634c4 Mon Sep 17 00:00:00 2001 From: Alessio Gravili <70709113+AlessioGr@users.noreply.github.com> Date: Thu, 4 Apr 2024 13:39:06 -0400 Subject: [PATCH] chore: ensure autologin passes before starting tests for all e2e test suites (#5659) --- test/_community/e2e.spec.ts | 3 +- test/access-control/e2e.spec.ts | 2 + test/admin/e2e.spec.ts | 2 + test/field-error-states/e2e.spec.ts | 4 +- test/fields-relationship/e2e.spec.ts | 11 ++++- test/fields/e2e.spec.ts | 3 ++ test/helpers.ts | 24 +++++++++ test/live-preview/e2e.spec.ts | 74 +++++++++++++++++----------- test/localization/e2e.spec.ts | 3 ++ test/plugin-form-builder/e2e.spec.ts | 4 +- test/plugin-nested-docs/e2e.spec.ts | 4 +- test/plugin-seo/e2e.spec.ts | 4 +- test/uploads/e2e.spec.ts | 8 ++- test/versions/e2e.spec.ts | 7 ++- 14 files changed, 116 insertions(+), 37 deletions(-) diff --git a/test/_community/e2e.spec.ts b/test/_community/e2e.spec.ts index 4df3db52b..948b2b738 100644 --- a/test/_community/e2e.spec.ts +++ b/test/_community/e2e.spec.ts @@ -4,7 +4,7 @@ import { expect, test } from '@playwright/test' import * as path from 'path' import { fileURLToPath } from 'url' -import { initPageConsoleErrorCatch } from '../helpers.js' +import { ensureAutoLoginAndCompilationIsDone, initPageConsoleErrorCatch } from '../helpers.js' import { AdminUrlUtil } from '../helpers/adminUrlUtil.js' import { initPayloadE2ENoConfig } from '../helpers/initPayloadE2ENoConfig.js' @@ -22,6 +22,7 @@ test.describe('Admin Panel', () => { const context = await browser.newContext() page = await context.newPage() initPageConsoleErrorCatch(page) + await ensureAutoLoginAndCompilationIsDone({ page, serverURL }) }) test('example test', async () => { diff --git a/test/access-control/e2e.spec.ts b/test/access-control/e2e.spec.ts index d83181cdc..0d046404e 100644 --- a/test/access-control/e2e.spec.ts +++ b/test/access-control/e2e.spec.ts @@ -9,6 +9,7 @@ import type { ReadOnlyCollection, RestrictedVersion } from './payload-types.js' import { closeNav, + ensureAutoLoginAndCompilationIsDone, exactText, initPageConsoleErrorCatch, openDocControls, @@ -59,6 +60,7 @@ describe('access control', () => { const context = await browser.newContext() page = await context.newPage() initPageConsoleErrorCatch(page) + await ensureAutoLoginAndCompilationIsDone({ page, serverURL }) }) test('field without read access should not show', async () => { diff --git a/test/admin/e2e.spec.ts b/test/admin/e2e.spec.ts index 89bbfe067..073795f25 100644 --- a/test/admin/e2e.spec.ts +++ b/test/admin/e2e.spec.ts @@ -11,6 +11,7 @@ import type { Geo, Post } from './payload-types.js' import { checkBreadcrumb, checkPageTitle, + ensureAutoLoginAndCompilationIsDone, exactText, initPageConsoleErrorCatch, openDocControls, @@ -78,6 +79,7 @@ describe('admin', () => { }) beforeEach(async () => { await clearAndSeedEverything(payload) + await ensureAutoLoginAndCompilationIsDone({ page, serverURL }) }) describe('Nav', () => { diff --git a/test/field-error-states/e2e.spec.ts b/test/field-error-states/e2e.spec.ts index cb245f0c9..2348baa43 100644 --- a/test/field-error-states/e2e.spec.ts +++ b/test/field-error-states/e2e.spec.ts @@ -4,7 +4,7 @@ import { expect, test } from '@playwright/test' import path from 'path' import { fileURLToPath } from 'url' -import { initPageConsoleErrorCatch } from '../helpers.js' +import { ensureAutoLoginAndCompilationIsDone, initPageConsoleErrorCatch } from '../helpers.js' import { initPayloadE2ENoConfig } from '../helpers/initPayloadE2ENoConfig.js' const { beforeAll, describe } = test @@ -20,6 +20,8 @@ describe('field error states', () => { const context = await browser.newContext() page = await context.newPage() initPageConsoleErrorCatch(page) + + await ensureAutoLoginAndCompilationIsDone({ page, serverURL }) }) test('Remove row should remove error states from parent fields', async () => { diff --git a/test/fields-relationship/e2e.spec.ts b/test/fields-relationship/e2e.spec.ts index 45b81f0e2..a78701595 100644 --- a/test/fields-relationship/e2e.spec.ts +++ b/test/fields-relationship/e2e.spec.ts @@ -14,9 +14,16 @@ import type { RelationWithTitle, } from './payload-types.js' -import { initPageConsoleErrorCatch, openDocControls, saveDocAndAssert } from '../helpers.js' +import { + delayNetwork, + ensureAutoLoginAndCompilationIsDone, + initPageConsoleErrorCatch, + openDocControls, + 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 { relationFalseFilterOptionSlug, relationOneSlug, @@ -123,6 +130,8 @@ describe('fields - relationship', () => { relationshipWithTitle: relationWithTitle.id, }, })) as any + + await ensureAutoLoginAndCompilationIsDone({ page, serverURL }) }) test('should create relationship', async () => { diff --git a/test/fields/e2e.spec.ts b/test/fields/e2e.spec.ts index 436f559f7..37e0b2a25 100644 --- a/test/fields/e2e.spec.ts +++ b/test/fields/e2e.spec.ts @@ -9,6 +9,7 @@ import { fileURLToPath } from 'url' import type { RelationshipField, TextField } from './payload-types.js' import { + ensureAutoLoginAndCompilationIsDone, exactText, initPageConsoleErrorCatch, saveDocAndAssert, @@ -56,6 +57,8 @@ describe('fields', () => { } client = new RESTClient(null, { defaultSlug: 'users', serverURL }) await client.login() + + await ensureAutoLoginAndCompilationIsDone({ page, serverURL }) }) describe('text', () => { let url: AdminUrlUtil diff --git a/test/helpers.ts b/test/helpers.ts index 8a4b1fa2a..f4bfbec9e 100644 --- a/test/helpers.ts +++ b/test/helpers.ts @@ -35,6 +35,30 @@ const networkConditions = { }, } +/** + * Load admin panel and make sure autologin has passed before running tests + * @param page + * @param serverURL + */ +export async function ensureAutoLoginAndCompilationIsDone({ + page, + serverURL, +}: { + page: Page + serverURL: string +}): Promise { + const adminURL = `${serverURL}/admin` + + await page.goto(adminURL) + await page.waitForURL(adminURL) + await expect(() => expect(page.url()).not.toContain(`/admin/login`)).toPass({ + timeout: POLL_TOPASS_TIMEOUT, + }) + await expect(() => expect(page.url()).not.toContain(`/admin/create-first-user`)).toPass({ + timeout: POLL_TOPASS_TIMEOUT, + }) +} + export async function delayNetwork({ context, page, diff --git a/test/live-preview/e2e.spec.ts b/test/live-preview/e2e.spec.ts index 77b29b59e..fac56bf7e 100644 --- a/test/live-preview/e2e.spec.ts +++ b/test/live-preview/e2e.spec.ts @@ -4,9 +4,15 @@ import { expect, test } from '@playwright/test' import path from 'path' import { fileURLToPath } from 'url' -import { exactText, initPageConsoleErrorCatch, saveDocAndAssert } from '../helpers.js' +import { + ensureAutoLoginAndCompilationIsDone, + exactText, + initPageConsoleErrorCatch, + saveDocAndAssert, +} from '../helpers.js' import { AdminUrlUtil } from '../helpers/adminUrlUtil.js' import { initPayloadE2ENoConfig } from '../helpers/initPayloadE2ENoConfig.js' +import { POLL_TOPASS_TIMEOUT } from '../playwright.config.js' import { mobileBreakpoint } from './shared.js' const filename = fileURLToPath(import.meta.url) const dirname = path.dirname(filename) @@ -22,7 +28,7 @@ describe('Live Preview', () => { await page.goto(url.list) const linkToDoc = page.locator('tbody tr:first-child .cell-title a').first() - await expect(() => expect(linkToDoc).toBeTruthy()).toPass({ timeout: 45000 }) + await expect(() => expect(linkToDoc).toBeTruthy()).toPass({ timeout: POLL_TOPASS_TIMEOUT }) const linkDocHref = await linkToDoc.getAttribute('href') await linkToDoc.click() @@ -48,6 +54,8 @@ describe('Live Preview', () => { page = await context.newPage() initPageConsoleErrorCatch(page) + + await ensureAutoLoginAndCompilationIsDone({ page, serverURL }) }) test('collection - has tab', async () => { @@ -57,13 +65,15 @@ describe('Live Preview', () => { hasText: exactText('Live Preview'), }) - await expect(() => expect(livePreviewTab).toBeTruthy()).toPass({ timeout: 45000 }) + await expect(() => expect(livePreviewTab).toBeTruthy()).toPass({ timeout: POLL_TOPASS_TIMEOUT }) const href = await livePreviewTab.locator('a').first().getAttribute('href') const docURL = page.url() const pathname = new URL(docURL).pathname - await expect(() => expect(href).toBe(`${pathname}/preview`)).toPass({ timeout: 45000 }) + await expect(() => expect(href).toBe(`${pathname}/preview`)).toPass({ + timeout: POLL_TOPASS_TIMEOUT, + }) }) test('collection - has route', async () => { @@ -71,7 +81,9 @@ describe('Live Preview', () => { const url = page.url() await goToCollectionPreview(page) - await expect(() => expect(page.url()).toBe(`${url}/preview`)).toPass({ timeout: 45000 }) + await expect(() => expect(page.url()).toBe(`${url}/preview`)).toPass({ + timeout: POLL_TOPASS_TIMEOUT, + }) }) test('collection - renders iframe', async () => { @@ -90,13 +102,13 @@ describe('Live Preview', () => { // Forces the test to wait for the nextjs route to render before we try editing a field await expect(() => expect(frame.locator('#page-title')).toBeVisible()).toPass({ - timeout: 45000, + timeout: POLL_TOPASS_TIMEOUT, }) await field.fill(titleValue) await expect(() => expect(frame.locator('#page-title')).toHaveText(titleValue)).toPass({ - timeout: 45000, + timeout: POLL_TOPASS_TIMEOUT, }) await saveDocAndAssert(page) @@ -123,17 +135,21 @@ describe('Live Preview', () => { hasText: exactText('Live Preview'), }) - await expect(() => expect(livePreviewTab).toBeTruthy()).toPass({ timeout: 45000 }) + await expect(() => expect(livePreviewTab).toBeTruthy()).toPass({ timeout: POLL_TOPASS_TIMEOUT }) const href = await livePreviewTab.locator('a').first().getAttribute('href') - await expect(() => expect(href).toBe(`${pathname}/preview`)).toPass({ timeout: 45000 }) + await expect(() => expect(href).toBe(`${pathname}/preview`)).toPass({ + timeout: POLL_TOPASS_TIMEOUT, + }) }) test('global - has route', async () => { const url = page.url() await goToGlobalPreview(page, 'header') - await expect(() => expect(page.url()).toBe(`${url}/preview`)).toPass({ timeout: 45000 }) + await expect(() => expect(page.url()).toBe(`${url}/preview`)).toPass({ + timeout: POLL_TOPASS_TIMEOUT, + }) }) test('global - renders iframe', async () => { @@ -160,7 +176,9 @@ describe('Live Preview', () => { await goToCollectionPreview(page) - await expect(() => expect(page.url()).toContain('/preview')).toPass({ timeout: 45000 }) + await expect(() => expect(page.url()).toContain('/preview')).toPass({ + timeout: POLL_TOPASS_TIMEOUT, + }) const iframe = page.locator('iframe') @@ -172,10 +190,10 @@ describe('Live Preview', () => { const widthInput = page.locator('.live-preview-toolbar input[name="live-preview-width"]') - await expect(() => expect(widthInput).toBeTruthy()).toPass({ timeout: 45000 }) + await expect(() => expect(widthInput).toBeTruthy()).toPass({ timeout: POLL_TOPASS_TIMEOUT }) const heightInput = page.locator('.live-preview-toolbar input[name="live-preview-height"]') - await expect(() => expect(heightInput).toBeTruthy()).toPass({ timeout: 45000 }) + await expect(() => expect(heightInput).toBeTruthy()).toPass({ timeout: POLL_TOPASS_TIMEOUT }) const widthInputValue = await widthInput.getAttribute('value') const width = parseInt(widthInputValue) @@ -186,19 +204,19 @@ describe('Live Preview', () => { const tolerance = 2 await expect(() => expect(iframeWidthInPx).toBeLessThanOrEqual(width + tolerance)).toPass({ - timeout: 45000, + timeout: POLL_TOPASS_TIMEOUT, }) await expect(() => expect(iframeWidthInPx).toBeGreaterThanOrEqual(width - tolerance)).toPass({ - timeout: 45000, + timeout: POLL_TOPASS_TIMEOUT, }) await expect(() => expect(iframeHeightInPx).toBeLessThanOrEqual(height + tolerance)).toPass({ - timeout: 45000, + timeout: POLL_TOPASS_TIMEOUT, }) await expect(() => expect(iframeHeightInPx).toBeGreaterThanOrEqual(height - tolerance)).toPass({ - timeout: 45000, + timeout: POLL_TOPASS_TIMEOUT, }) }) @@ -211,7 +229,7 @@ describe('Live Preview', () => { await goToCollectionPreview(page) await expect(() => expect(page.url()).toContain('/preview')).toPass({ - timeout: 45000, + timeout: POLL_TOPASS_TIMEOUT, }) // Check that the breakpoint select is present @@ -220,7 +238,7 @@ describe('Live Preview', () => { ) await expect(() => expect(breakpointSelector).toBeTruthy()).toPass({ - timeout: 45000, + timeout: POLL_TOPASS_TIMEOUT, }) // Select the mobile breakpoint @@ -241,7 +259,7 @@ describe('Live Preview', () => { const iframe = page.locator('iframe') await expect(() => expect(iframe).toBeTruthy()).toPass({ - timeout: 45000, + timeout: POLL_TOPASS_TIMEOUT, }) const iframeSize = await iframe.boundingBox() const iframeWidthInPx = iframeSize?.width @@ -251,49 +269,49 @@ describe('Live Preview', () => { await expect(() => expect(iframeWidthInPx).toBeLessThanOrEqual(mobileBreakpoint.width + tolerance), ).toPass({ - timeout: 45000, + timeout: POLL_TOPASS_TIMEOUT, }) await expect(() => expect(iframeWidthInPx).toBeGreaterThanOrEqual(mobileBreakpoint.width - tolerance), ).toPass({ - timeout: 45000, + timeout: POLL_TOPASS_TIMEOUT, }) await expect(() => expect(iframeHeightInPx).toBeLessThanOrEqual(mobileBreakpoint.height + tolerance), ).toPass({ - timeout: 45000, + timeout: POLL_TOPASS_TIMEOUT, }) await expect(() => expect(iframeHeightInPx).toBeGreaterThanOrEqual(mobileBreakpoint.height - tolerance), ).toPass({ - timeout: 45000, + timeout: POLL_TOPASS_TIMEOUT, }) // Check that the inputs have been updated to reflect the new size const widthInput = page.locator('.live-preview-toolbar input[name="live-preview-width"]') await expect(() => expect(widthInput).toBeTruthy()).toPass({ - timeout: 45000, + timeout: POLL_TOPASS_TIMEOUT, }) const heightInput = page.locator('.live-preview-toolbar input[name="live-preview-height"]') await expect(() => expect(heightInput).toBeTruthy()).toPass({ - timeout: 45000, + timeout: POLL_TOPASS_TIMEOUT, }) const widthInputValue = await widthInput.getAttribute('value') const width = parseInt(widthInputValue) await expect(() => expect(width).toBe(mobileBreakpoint.width)).toPass({ - timeout: 45000, + timeout: POLL_TOPASS_TIMEOUT, }) const heightInputValue = await heightInput.getAttribute('value') const height = parseInt(heightInputValue) await expect(() => expect(height).toBe(mobileBreakpoint.height)).toPass({ - timeout: 45000, + timeout: POLL_TOPASS_TIMEOUT, }) }) }) diff --git a/test/localization/e2e.spec.ts b/test/localization/e2e.spec.ts index 8305d564d..81c1bdb49 100644 --- a/test/localization/e2e.spec.ts +++ b/test/localization/e2e.spec.ts @@ -10,6 +10,7 @@ import type { Config, LocalizedPost } from './payload-types.js' import { changeLocale, + ensureAutoLoginAndCompilationIsDone, initPageConsoleErrorCatch, openDocControls, saveDocAndAssert, @@ -60,6 +61,8 @@ describe('Localization', () => { page = await context.newPage() initPageConsoleErrorCatch(page) + + await ensureAutoLoginAndCompilationIsDone({ page, serverURL }) }) describe('localized text', () => { diff --git a/test/plugin-form-builder/e2e.spec.ts b/test/plugin-form-builder/e2e.spec.ts index b05806697..a99516884 100644 --- a/test/plugin-form-builder/e2e.spec.ts +++ b/test/plugin-form-builder/e2e.spec.ts @@ -7,7 +7,7 @@ import { fileURLToPath } from 'url' import type { PayloadTestSDK } from '../helpers/sdk/index.js' import type { Config } from './payload-types.js' -import { initPageConsoleErrorCatch } from '../helpers.js' +import { ensureAutoLoginAndCompilationIsDone, initPageConsoleErrorCatch } from '../helpers.js' import { AdminUrlUtil } from '../helpers/adminUrlUtil.js' import { initPayloadE2ENoConfig } from '../helpers/initPayloadE2ENoConfig.js' import { POLL_TOPASS_TIMEOUT } from '../playwright.config.js' @@ -33,6 +33,8 @@ test.describe('Form Builder', () => { const context = await browser.newContext() page = await context.newPage() initPageConsoleErrorCatch(page) + + await ensureAutoLoginAndCompilationIsDone({ page, serverURL }) }) test.describe('Forms collection', () => { diff --git a/test/plugin-nested-docs/e2e.spec.ts b/test/plugin-nested-docs/e2e.spec.ts index 852d7c22e..433bd1c2a 100644 --- a/test/plugin-nested-docs/e2e.spec.ts +++ b/test/plugin-nested-docs/e2e.spec.ts @@ -6,7 +6,7 @@ import { fileURLToPath } from 'url' import type { Page as PayloadPage } from './payload-types.js' -import { initPageConsoleErrorCatch } from '../helpers.js' +import { ensureAutoLoginAndCompilationIsDone, initPageConsoleErrorCatch } from '../helpers.js' import { AdminUrlUtil } from '../helpers/adminUrlUtil.js' import { initPayloadE2E } from '../helpers/initPayloadE2E.js' @@ -67,6 +67,8 @@ describe('Nested Docs Plugin', () => { _status: 'draft', }) draftChildId = draftChildPage.id + + await ensureAutoLoginAndCompilationIsDone({ page, serverURL }) }) describe('Core functionality', () => { diff --git a/test/plugin-seo/e2e.spec.ts b/test/plugin-seo/e2e.spec.ts index 866143aba..0dcda420d 100644 --- a/test/plugin-seo/e2e.spec.ts +++ b/test/plugin-seo/e2e.spec.ts @@ -7,7 +7,7 @@ import { fileURLToPath } from 'url' import type { Page as PayloadPage } from './payload-types.js' -import { initPageConsoleErrorCatch } from '../helpers.js' +import { ensureAutoLoginAndCompilationIsDone, initPageConsoleErrorCatch } from '../helpers.js' import { AdminUrlUtil } from '../helpers/adminUrlUtil.js' import { initPayloadE2E } from '../helpers/initPayloadE2E.js' import { mediaSlug } from './shared.js' @@ -53,6 +53,8 @@ describe('SEO Plugin', () => { }, })) as unknown as PayloadPage id = createdPage.id + + await ensureAutoLoginAndCompilationIsDone({ page, serverURL }) }) describe('Core functionality', () => { diff --git a/test/uploads/e2e.spec.ts b/test/uploads/e2e.spec.ts index 98b8076a9..0597406e7 100644 --- a/test/uploads/e2e.spec.ts +++ b/test/uploads/e2e.spec.ts @@ -8,7 +8,11 @@ import { fileURLToPath } from 'url' import type { Media } from './payload-types.js' -import { initPageConsoleErrorCatch, saveDocAndAssert } from '../helpers.js' +import { + ensureAutoLoginAndCompilationIsDone, + initPageConsoleErrorCatch, + saveDocAndAssert, +} from '../helpers.js' import { AdminUrlUtil } from '../helpers/adminUrlUtil.js' import { initPayloadE2E } from '../helpers/initPayloadE2E.js' import { RESTClient } from '../helpers/rest.js' @@ -74,6 +78,8 @@ describe('uploads', () => { }) audioDoc = findAudio.docs[0] as unknown as Media + + await ensureAutoLoginAndCompilationIsDone({ page, serverURL }) }) test('should see upload filename in relation list', async () => { diff --git a/test/versions/e2e.spec.ts b/test/versions/e2e.spec.ts index a49ceb6bb..e31e9f13f 100644 --- a/test/versions/e2e.spec.ts +++ b/test/versions/e2e.spec.ts @@ -35,6 +35,7 @@ import type { Config } from './payload-types.js' import { globalSlug } from '../admin/slugs.js' import { changeLocale, + ensureAutoLoginAndCompilationIsDone, exactText, findTableCell, initPageConsoleErrorCatch, @@ -70,7 +71,7 @@ const waitForAutoSaveToComplete = async (page: Page) => { page.locator('.autosave:has-text("Last saved less than a minute ago")'), ).toBeVisible() }).toPass({ - timeout: 45000, + timeout: POLL_TOPASS_TIMEOUT, }) } @@ -78,7 +79,7 @@ const waitForAutoSaveToRunAndComplete = async (page: Page) => { await expect(async () => { await expect(page.locator('.autosave:has-text("Saving...")')).toBeVisible() }).toPass({ - timeout: 45000, + timeout: POLL_TOPASS_TIMEOUT, }) await waitForAutoSaveToComplete(page) @@ -107,6 +108,8 @@ describe('versions', () => { serverURL, snapshotKey: 'versionsTest', }) + + await ensureAutoLoginAndCompilationIsDone({ page, serverURL }) //await clearAndSeedEverything(payload) })