Skip to content

Commit

Permalink
chore: setup e2e test with playwright
Browse files Browse the repository at this point in the history
  • Loading branch information
thomas-lebeau committed Jan 16, 2024
1 parent 37b98b6 commit 9ef8f66
Show file tree
Hide file tree
Showing 8 changed files with 109 additions and 7 deletions.
35 changes: 35 additions & 0 deletions .github/workflows/e2e.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: e2e

on:
deployment_status:

jobs:
playwright:
timeout-minutes: 60
runs-on: ubuntu-latest
if: github.event.deployment_status.state == 'success'
container:
image: mcr.microsoft.com/playwright:v1.40.0-jammy

steps:
- uses: actions/checkout@v4

- uses: actions/setup-node@v3
with:
node-version: 20
cache: "npm"

- run: npm ci

- run: npx playwright install --with-deps

- run: npx playwright test
env:
PLAYWRIGHT_TEST_BASE_URL: ${{ github.event.deployment_status.target_url }}

- uses: actions/upload-artifact@v3
if: always()
with:
name: playwright-report
path: playwright-report/
retention-days: 30
2 changes: 2 additions & 0 deletions .github/workflows/pr.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
name: pr

on:
push:
branches: [main]
pull_request:
branches: [main]

Expand Down
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,7 @@ next-env.d.ts
.env*
.flaskenv*
!.env.project
/test-results/
/playwright-report/
/blob-report/
/playwright/.cache/
17 changes: 17 additions & 0 deletions e2e/home.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { expect, test } from "@playwright/test";

test("has title", async ({ page }) => {
await page.goto("/");

await expect(page).toHaveTitle(/100-cims/);
});

test("get started link", async ({ page }) => {
await page.goto("/");

await page.getByRole("link", { name: "Get started" }).click();

await expect(
page.getByRole("heading", { name: "Installation" })
).toBeVisible();
});
30 changes: 23 additions & 7 deletions package-lock.json

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

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"lint": "next lint -- -f gha",
"test": "jest",
"test:watch": "jest --watch",
"e2e": "playwright test",
"postinstall": "prisma generate"
},
"prisma": {
Expand Down Expand Up @@ -51,6 +52,7 @@
"zod-fetch": "^0.1.1"
},
"devDependencies": {
"@playwright/test": "^1.41.0",
"@testing-library/jest-dom": "^6.2.0",
"@testing-library/react": "^14.1.2",
"@total-typescript/ts-reset": "^0.5.1",
Expand Down
24 changes: 24 additions & 0 deletions playwright.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { defineConfig, devices } from "@playwright/test";

require("dotenv").config();

export default defineConfig({
testDir: "./e2e",
fullyParallel: true,
forbidOnly: !!process.env.CI,
retries: process.env.CI ? 2 : 0,
workers: process.env.CI ? 1 : undefined,
reporter: process.env.GITHUB_ACTIONS ? "github" : "html",
use: {
baseURL: process.env.PLAYWRIGHT_TEST_BASE_URL,
trace: process.env.CI ? "on-first-retry" : "retain-on-failure",
video: process.env.CI ? "on-first-retry" : "retain-on-failure",
screenshot: "only-on-failure",
},
projects: [
{
name: "chromium",
use: { ...devices["Desktop Chrome"] },
},
],
});
2 changes: 2 additions & 0 deletions src/types/env.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ declare global {
CI: string | undefined;
GITHUB_ACTIONS: string | undefined;

PLAYWRIGHT_TEST_BASE_URL: string;

// make typescript error when using env vars that are not defined in here
[key: string]: undefined;
}
Expand Down

0 comments on commit 9ef8f66

Please sign in to comment.