From c7c66eeb37a511d1a0d477e5843f895f6d93e928 Mon Sep 17 00:00:00 2001 From: Wes Date: Tue, 8 Oct 2024 13:38:02 -0700 Subject: [PATCH] chore: replace custom test fixture with global setup --- frontend/console/e2e/echo.spec.ts | 8 +++---- frontend/console/e2e/events.spec.ts | 4 ++-- frontend/console/e2e/ftl-test.ts | 19 ---------------- frontend/console/e2e/global-setup.ts | 25 +++++++++++++++++++++ frontend/console/e2e/helpers.ts | 1 + frontend/console/e2e/infrastructure.spec.ts | 5 +++-- frontend/console/e2e/ingress-http.spec.ts | 12 +++++----- frontend/console/e2e/module.spec.ts | 4 ++-- frontend/console/e2e/modules.spec.ts | 5 +++-- frontend/console/playwright.config.ts | 8 +++++-- 10 files changed, 52 insertions(+), 39 deletions(-) delete mode 100644 frontend/console/e2e/ftl-test.ts create mode 100644 frontend/console/e2e/global-setup.ts diff --git a/frontend/console/e2e/echo.spec.ts b/frontend/console/e2e/echo.spec.ts index 5f2665845..814fcf11c 100644 --- a/frontend/console/e2e/echo.spec.ts +++ b/frontend/console/e2e/echo.spec.ts @@ -1,7 +1,7 @@ -import { expect, ftlTest } from './ftl-test' +import { expect, test } from '@playwright/test' import { navigateToDecl } from './helpers' -ftlTest('shows echo verb form', async ({ page }) => { +test('shows echo verb form', async ({ page }) => { await navigateToDecl(page, 'echo', 'echo') await expect(page.getByText('CALL', { exact: true })).toBeVisible() @@ -12,7 +12,7 @@ ftlTest('shows echo verb form', async ({ page }) => { await expect(page.getByText('JSONSchema', { exact: true })).toBeVisible() }) -ftlTest('send echo request', async ({ page }) => { +test('send echo request', async ({ page }) => { await navigateToDecl(page, 'echo', 'echo') // Check the initial value of the path input @@ -31,7 +31,7 @@ ftlTest('send echo request', async ({ page }) => { await expect(responseEditor).toBeVisible() const responseText = await responseEditor.textContent() - const responseJson = JSON.parse(responseText.trim()) + const responseJson = JSON.parse(responseText?.trim() || '{}') const expectedStart = 'Hello, wicket!!! It is ' expect(responseJson.message.startsWith(expectedStart)).toBe(true) diff --git a/frontend/console/e2e/events.spec.ts b/frontend/console/e2e/events.spec.ts index dd2c8b6fb..e6f1375d9 100644 --- a/frontend/console/e2e/events.spec.ts +++ b/frontend/console/e2e/events.spec.ts @@ -1,6 +1,6 @@ -import { expect, ftlTest } from './ftl-test' +import { expect, test } from '@playwright/test' -ftlTest('defaults to the events page', async ({ page }) => { +test('defaults to the events page', async ({ page }) => { await page.goto('http://localhost:8892') const eventsNavItem = page.getByRole('link', { name: 'Events' }) diff --git a/frontend/console/e2e/ftl-test.ts b/frontend/console/e2e/ftl-test.ts deleted file mode 100644 index d5f97d707..000000000 --- a/frontend/console/e2e/ftl-test.ts +++ /dev/null @@ -1,19 +0,0 @@ -import { test as base, expect } from '@playwright/test' - -const ftlTest = base.extend<{ - // biome-ignore lint/suspicious/noExplicitAny: any is what playwright expects - page: any -}>({ - page: async ({ page }, use) => { - await page.goto('http://localhost:8892/modules') - await page.waitForFunction(() => { - const timeItem = document.querySelector('li#module-tree-module-time') - const echoItem = document.querySelector('li#module-tree-module-echo') - return timeItem !== null && echoItem !== null - }) - - await use(page) - }, -}) - -export { ftlTest, expect } diff --git a/frontend/console/e2e/global-setup.ts b/frontend/console/e2e/global-setup.ts new file mode 100644 index 000000000..854fd64dc --- /dev/null +++ b/frontend/console/e2e/global-setup.ts @@ -0,0 +1,25 @@ +import { type FullConfig, chromium } from '@playwright/test' + +const globalSetup = async (config: FullConfig) => { + console.log('Waiting for server to be available...') + + const browser = await chromium.launch({ headless: false }) + const context = await browser.newContext() + const page = await context.newPage() + await page.goto('http://localhost:8892/modules') + + console.log('Waiting for modules to load...') + await page.waitForFunction( + () => { + const moduleNames = ['time', 'echo', 'cron', 'fsm', 'http', 'pubsub'] + + return moduleNames.every((module) => document.querySelector(`li#module-tree-module-${module}`) !== null) + }, + { timeout: 120000 }, + ) + console.log('Modules loaded!') + + await browser.close() +} + +export default globalSetup diff --git a/frontend/console/e2e/helpers.ts b/frontend/console/e2e/helpers.ts index b9cc3305b..8c383d3cd 100644 --- a/frontend/console/e2e/helpers.ts +++ b/frontend/console/e2e/helpers.ts @@ -1,6 +1,7 @@ import { type Page, expect } from '@playwright/test' export async function navigateToModule(page: Page, moduleName: string) { + await page.goto('http://localhost:8892/modules') await page.getByRole('link', { name: 'Modules' }).click() // Navigate to the module page diff --git a/frontend/console/e2e/infrastructure.spec.ts b/frontend/console/e2e/infrastructure.spec.ts index 38cb2f64e..12c884d88 100644 --- a/frontend/console/e2e/infrastructure.spec.ts +++ b/frontend/console/e2e/infrastructure.spec.ts @@ -1,6 +1,7 @@ -import { expect, ftlTest } from './ftl-test' +import { expect, test } from '@playwright/test' -ftlTest('shows infrastructure', async ({ page }) => { +test('shows infrastructure', async ({ page }) => { + await page.goto('http://localhost:8892') const infrastructureNavItem = page.getByRole('link', { name: 'Infrastructure' }) await infrastructureNavItem.click() await expect(page).toHaveURL(/\/infrastructure\/controllers$/) diff --git a/frontend/console/e2e/ingress-http.spec.ts b/frontend/console/e2e/ingress-http.spec.ts index 0a2358ac4..69e308315 100644 --- a/frontend/console/e2e/ingress-http.spec.ts +++ b/frontend/console/e2e/ingress-http.spec.ts @@ -1,7 +1,7 @@ -import { expect, ftlTest } from './ftl-test' +import { expect, test } from '@playwright/test' import { navigateToDecl } from './helpers' -ftlTest('shows http ingress form', async ({ page }) => { +test('shows http ingress form', async ({ page }) => { await navigateToDecl(page, 'http', 'get') await expect(page.locator('#call-type')).toHaveText('GET') @@ -12,7 +12,7 @@ ftlTest('shows http ingress form', async ({ page }) => { await expect(page.getByText('JSONSchema', { exact: true })).toBeVisible() }) -ftlTest('send get request with path and query params', async ({ page }) => { +test('send get request with path and query params', async ({ page }) => { await navigateToDecl(page, 'http', 'get') // Check the initial value of the path input @@ -29,7 +29,7 @@ ftlTest('send get request with path and query params', async ({ page }) => { await expect(responseEditor).toBeVisible() const responseText = await responseEditor.textContent() - const responseJson = JSON.parse(responseText) + const responseJson = JSON.parse(responseText?.trim() || '{}') expect(responseJson).toEqual({ age: '10', @@ -37,7 +37,7 @@ ftlTest('send get request with path and query params', async ({ page }) => { }) }) -ftlTest('send post request with body', async ({ page }) => { +test('send post request with body', async ({ page }) => { await navigateToDecl(page, 'http', 'post') // Check the initial value of the path input @@ -56,7 +56,7 @@ ftlTest('send post request with body', async ({ page }) => { await expect(responseEditor).toBeVisible() const responseText = await responseEditor.textContent() - const responseJson = JSON.parse(responseText) + const responseJson = JSON.parse(responseText?.trim() || '{}') expect(responseJson).toEqual({ age: 10, diff --git a/frontend/console/e2e/module.spec.ts b/frontend/console/e2e/module.spec.ts index ce7896907..ae6f13143 100644 --- a/frontend/console/e2e/module.spec.ts +++ b/frontend/console/e2e/module.spec.ts @@ -1,7 +1,7 @@ -import { expect, ftlTest } from './ftl-test' +import { expect, test } from '@playwright/test' import { navigateToModule } from './helpers' -ftlTest('shows verbs for deployment', async ({ page }) => { +test('shows verbs for deployment', async ({ page }) => { await navigateToModule(page, 'echo') await expect(page.getByText('module echo {')).toBeVisible() diff --git a/frontend/console/e2e/modules.spec.ts b/frontend/console/e2e/modules.spec.ts index 97a3d0604..522100c09 100644 --- a/frontend/console/e2e/modules.spec.ts +++ b/frontend/console/e2e/modules.spec.ts @@ -1,6 +1,7 @@ -import { expect, ftlTest } from './ftl-test' +import { expect, test } from '@playwright/test' -ftlTest('shows active modules', async ({ page }) => { +test('shows active modules', async ({ page }) => { + await page.goto('http://localhost:8892') const modulesNavItem = page.getByRole('link', { name: 'Modules' }) await modulesNavItem.click() await expect(page).toHaveURL(/\/modules$/) diff --git a/frontend/console/playwright.config.ts b/frontend/console/playwright.config.ts index 1cf8813df..18ae44a8d 100644 --- a/frontend/console/playwright.config.ts +++ b/frontend/console/playwright.config.ts @@ -1,10 +1,12 @@ import { defineConfig, devices } from '@playwright/test' +import { PlaywrightTestConfig } from '@playwright/test'; /** * See https://playwright.dev/docs/test-configuration. */ -export default defineConfig({ +const config: PlaywrightTestConfig = { testDir: './e2e', + globalSetup: './e2e/global-setup.ts', fullyParallel: true, /* Fail the build on CI if you accidentally left test.only in the source code. */ forbidOnly: !!process.env.CI, @@ -44,4 +46,6 @@ export default defineConfig({ /* If the test ends up needing to pull the postgres docker image, this can take a while. Give it a few minutes. */ timeout: 180000, }, -}) +} + +export default config