Skip to content

Commit

Permalink
chore: replace custom test fixture with global setup
Browse files Browse the repository at this point in the history
  • Loading branch information
wesbillman committed Oct 8, 2024
1 parent 68d6ba3 commit c7c66ee
Show file tree
Hide file tree
Showing 10 changed files with 52 additions and 39 deletions.
8 changes: 4 additions & 4 deletions frontend/console/e2e/echo.spec.ts
Original file line number Diff line number Diff line change
@@ -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()
Expand All @@ -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
Expand All @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions frontend/console/e2e/events.spec.ts
Original file line number Diff line number Diff line change
@@ -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' })

Expand Down
19 changes: 0 additions & 19 deletions frontend/console/e2e/ftl-test.ts

This file was deleted.

25 changes: 25 additions & 0 deletions frontend/console/e2e/global-setup.ts
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions frontend/console/e2e/helpers.ts
Original file line number Diff line number Diff line change
@@ -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
Expand Down
5 changes: 3 additions & 2 deletions frontend/console/e2e/infrastructure.spec.ts
Original file line number Diff line number Diff line change
@@ -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$/)
Expand Down
12 changes: 6 additions & 6 deletions frontend/console/e2e/ingress-http.spec.ts
Original file line number Diff line number Diff line change
@@ -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')
Expand All @@ -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
Expand All @@ -29,15 +29,15 @@ 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',
name: 'wicket',
})
})

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
Expand All @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions frontend/console/e2e/module.spec.ts
Original file line number Diff line number Diff line change
@@ -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()
Expand Down
5 changes: 3 additions & 2 deletions frontend/console/e2e/modules.spec.ts
Original file line number Diff line number Diff line change
@@ -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$/)
Expand Down
8 changes: 6 additions & 2 deletions frontend/console/playwright.config.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -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

0 comments on commit c7c66ee

Please sign in to comment.