Skip to content

Commit

Permalink
test(e2e): setup base tests using playwright
Browse files Browse the repository at this point in the history
  • Loading branch information
d-koppenhagen committed Dec 20, 2024
1 parent 5c32f4c commit 0a393d7
Show file tree
Hide file tree
Showing 9 changed files with 245 additions and 1,745 deletions.
23 changes: 18 additions & 5 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,31 @@ on:
branches-ignore:
- main
- gh-pages
pull_request:
branches:
- main

jobs:
build-and-test:
timeout-minutes: 60
runs-on: ubuntu-latest
steps:
- name: Checkout 🛎️
uses: actions/[email protected]
- uses: actions/setup-node@v4
with:
node-version: 22
- name: Build and Run End2End tests with Cypress
uses: cypress-io/github-action@v4
- name: Install dependencies
run: npm ci
- name: Build
run: npm run build
- name: Install Playwright Browsers
run: npx playwright install --with-deps
- name: Run Playwright tests
run: npx playwright test
- uses: actions/upload-artifact@v4
if: ${{ !cancelled() }}
with:
build: npm run build
start: npm run dev
wait-on: "http://localhost:8080"
name: playwright-report
path: playwright-report/
retention-days: 30
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,7 @@ pnpm-debug.log*
*.njsproj
*.sln
*.sw?
/test-results/
/playwright-report/
/blob-report/
/playwright/.cache/
9 changes: 0 additions & 9 deletions cypress.config.ts

This file was deleted.

15 changes: 0 additions & 15 deletions cypress/e2e/smoke.cy.ts

This file was deleted.

46 changes: 46 additions & 0 deletions e2e/smoke.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import { expect, Page, test } from "@playwright/test"
import * as path from "path"

const trivyReportUrl =
"https://raw.githubusercontent.com/dbsystel/trivy-vulnerability-explorer/refs/heads/main/public/alpine-3.9.2.json"

async function verifyTableResult(page: Page) {
expect(await page.locator("table").isVisible()).toBe(true)
const rows = page.locator("table tr")
expect(await rows.count()).toBeGreaterThanOrEqual(20)
}

test("should have the correct title", async ({ page }) => {
const expectedTitle = "Trivy Vulnerability Explorer"
await page.goto("http://localhost:8080")
expect(await page.title()).toMatch(expectedTitle)
expect(await page.getByRole("banner").textContent()).toBe(expectedTitle)
})

test("fetches from URL", async ({ page }) => {
await page.goto("http://localhost:8080")

await page.getByRole("button", { name: "URL" }).click()
const fetchButton = page.getByRole("button", { name: "Fetch" })

expect(await fetchButton.isDisabled()).toBe(true)
await page.getByRole("textbox", { name: "Url" }).fill(trivyReportUrl)

const responsePromise = page.waitForResponse(trivyReportUrl)
await fetchButton.click()
await responsePromise

await verifyTableResult(page)
})

test("fetches from uploaded file", async ({ page }) => {
await page.goto("http://localhost:8080")

await page.getByRole("button", { name: "File" }).click()

const fileInput = page.locator("input[type=file]")
const invalidFilePath = path.resolve(__dirname, "../public/alpine-3.9.2.json")
await fileInput.setInputFiles(invalidFilePath)

await verifyTableResult(page)
})
Loading

0 comments on commit 0a393d7

Please sign in to comment.