Skip to content

Commit

Permalink
chore: add console e2e testing with playwright (#2462)
Browse files Browse the repository at this point in the history
Fixes #2416
  • Loading branch information
wesbillman authored Aug 21, 2024
1 parent 3da112c commit f2686f9
Show file tree
Hide file tree
Showing 13 changed files with 232 additions and 11 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,8 @@ jobs:
run: npm run lint
- name: Console Build
run: just build-frontend
- name: Console Test
run: just test-frontend
extension:
name: VSCode Extension
runs-on: ubuntu-latest
Expand Down
5 changes: 4 additions & 1 deletion Justfile
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,9 @@ test-scripts:
GIT_AUTHOR_EMAIL="[email protected]" \
scripts/tests/test-ensure-frozen-migrations.sh

test-frontend: build-frontend
@cd frontend && npx playwright install --with-deps && npm run test

# Lint the frontend
lint-frontend: build-frontend
@cd frontend && npm run lint && tsc
Expand Down Expand Up @@ -233,4 +236,4 @@ grafana-stop:

storybook:
#!/bin/bash
cd frontend && npm run storybook
cd frontend && npm run storybook
6 changes: 5 additions & 1 deletion frontend/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,8 @@ dist-ssr
*.sln
*.sw?
*/.parcel-cache
*storybook.log
*storybook.log
/test-results/
/playwright-report/
/blob-report/
/playwright/.cache/
4 changes: 2 additions & 2 deletions frontend/biome.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@
"noArrayIndexKey": "off"
}
},
"include": ["src/**/*.ts", "src/**/*.tsx", "src/**/*.js", "src/**/*.jsx", "src/**/*.cjs", "src/**/*.mjs"],
"include": ["src/**/*.ts", "src/**/*.tsx", "src/**/*.js", "src/**/*.jsx", "src/**/*.cjs", "src/**/*.mjs", "tests/**/*.ts"],
"ignore": ["./node_modules", "./dist", "./src/protos"]
},
"formatter": {
"indentStyle": "space",
"indentWidth": 2,
"lineWidth": 160,
"include": ["src/**/*.ts", "src/**/*.tsx", "src/**/*.js", "src/**/*.jsx", "src/**/*.cjs", "src/**/*.mjs"],
"include": ["src/**/*.ts", "src/**/*.tsx", "src/**/*.js", "src/**/*.jsx", "src/**/*.cjs", "src/**/*.mjs", "tests/**/*.ts"],
"ignore": ["./node_modules", "./dist", "./src/protos"]
},
"javascript": {
Expand Down
100 changes: 95 additions & 5 deletions frontend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 9 additions & 2 deletions frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,18 @@
"dev": "vite",
"lint": "biome check .",
"lint:fix": "biome format . --write",
"test": "playwright test",
"storybook": "storybook dev -p 6006",
"build-storybook": "storybook build"
},
"lint-staged": {
"*.(js|cjs|tsx|ts)": ["npm run lint:fix"]
"*.(js|cjs|tsx|ts)": [
"npm run lint:fix"
]
},
"browserslist": ["> 2%"],
"browserslist": [
"> 2%"
],
"source": "index.html",
"dependencies": {
"@bufbuild/protoc-gen-es": "1.10.0",
Expand Down Expand Up @@ -51,6 +56,7 @@
"devDependencies": {
"@biomejs/biome": "1.8.3",
"@chromatic-com/storybook": "^1.6.1",
"@playwright/test": "^1.46.1",
"@storybook/addon-essentials": "^8.2.7",
"@storybook/addon-interactions": "^8.2.7",
"@storybook/addon-links": "^8.2.7",
Expand All @@ -62,6 +68,7 @@
"@storybook/react-vite": "^8.2.7",
"@storybook/test": "^8.2.7",
"@tanstack/eslint-plugin-query": "^5.51.15",
"@types/node": "^22.4.1",
"@types/react": "18.3.3",
"@types/react-dom": "18.3.0",
"buffer": "^6.0.3",
Expand Down
43 changes: 43 additions & 0 deletions frontend/playwright.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import { defineConfig, devices } from '@playwright/test';

/**
* See https://playwright.dev/docs/test-configuration.
*/
export default defineConfig({
testDir: './tests',
fullyParallel: true,
/* Fail the build on CI if you accidentally left test.only in the source code. */
forbidOnly: !!process.env.CI,
/* Retry on CI only */
retries: process.env.CI ? 2 : 0,
/* Opt out of parallel tests on CI. */
workers: process.env.CI ? 1 : undefined,
reporter: 'html',
use: {
baseURL: 'http://localhost:8892',

/* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */
trace: 'on-first-retry',
},
projects: [
{
name: 'chromium',
use: { ...devices['Desktop Chrome'] },
},

{
name: 'firefox',
use: { ...devices['Desktop Firefox'] },
},

{
name: 'webkit',
use: { ...devices['Desktop Safari'] },
},
],
webServer: {
command: 'ftl dev --recreate',
url: 'http://localhost:8892',
reuseExistingServer: true,
},
});
1 change: 1 addition & 0 deletions frontend/src/layout/navigation/Navigation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ export const Navigation = ({
{item.name}
{['/modules', '/deployments'].includes(item.href) && (
<span
id='deployments-count'
className='ml-auto w-9 min-w-max whitespace-nowrap rounded-full bg-indigo-600 px-2.5 py-0.5 text-center text-xs font-medium leading-5 text-white ring-1 ring-inset ring-indigo-500'
aria-hidden='true'
>
Expand Down
14 changes: 14 additions & 0 deletions frontend/tests/deployment.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { expect, ftlTest } from './ftl-test'

ftlTest('shows verbs for deployment', async ({ page }) => {
const deploymentsNavItem = page.getByRole('link', { name: 'Deployments' })
await deploymentsNavItem.click()

const deploymentEcho = page.getByText('dpl-echo')
await deploymentEcho.click()

await expect(page).toHaveURL(/\/deployments\/dpl-echo-.*/)

await expect(page.getByText('echo', { exact: true })).toBeVisible()
await expect(page.getByText('exported', { exact: true })).toBeVisible()
})
10 changes: 10 additions & 0 deletions frontend/tests/deployments.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { expect, ftlTest } from './ftl-test'

ftlTest('shows active deployments', async ({ page }) => {
const deploymentsNavItem = page.getByRole('link', { name: 'Deployments' })
await deploymentsNavItem.click()
await expect(page).toHaveURL(/\/deployments$/)

await expect(page.getByText('dpl-time')).toBeVisible()
await expect(page.getByText('dpl-echo')).toBeVisible()
})
7 changes: 7 additions & 0 deletions frontend/tests/events.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { expect, ftlTest } from './ftl-test'

ftlTest('defaults to the events page', async ({ page }) => {
const eventsNavItem = page.getByRole('link', { name: 'Events' })

await expect(eventsNavItem).toHaveClass(/bg-indigo-600 text-white/)
})
17 changes: 17 additions & 0 deletions frontend/tests/ftl-test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { test as base, expect } from '@playwright/test'

const ftlTest = base.extend<{
// biome-ignore lint/suspicious/noExplicitAny: <explanation>
page: any
}>({
page: async ({ page }, use) => {
await page.goto('http://localhost:8892')
await page.waitForFunction(() => {
const element = document.querySelector('#deployments-count')
return element && element.textContent?.trim() === '2'
})
await use(page)
},
})

export { ftlTest, expect }
23 changes: 23 additions & 0 deletions frontend/tests/verb.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { expect, ftlTest } from './ftl-test'

ftlTest.beforeEach(async ({ page }) => {
const deploymentsNavItem = page.getByRole('link', { name: 'Deployments' })
await deploymentsNavItem.click()

const deploymentEcho = page.getByText('dpl-echo')
await deploymentEcho.click()

const verbEcho = page.getByText('echo', { exact: true })
await verbEcho.click()

await expect(page).toHaveURL(/\/deployments\/dpl-echo-[^/]+\/verbs\/echo/)
})

ftlTest('shows verb form', async ({ page }) => {
await expect(page.getByText('CALL', { exact: true })).toBeVisible()
await expect(page.locator('input#request-path')).toHaveValue('echo.echo')

await expect(page.getByText('Body', { exact: true })).toBeVisible()
await expect(page.getByText('Verb Schema', { exact: true })).toBeVisible()
await expect(page.getByText('JSONSchema', { exact: true })).toBeVisible()
})

0 comments on commit f2686f9

Please sign in to comment.