Skip to content

Commit 46aeef5

Browse files
committed
test: Start using playwright e2e tests
1 parent 2bf778b commit 46aeef5

9 files changed

Lines changed: 245 additions & 1 deletion

File tree

.github/workflows/e2e.yml

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
# To upgrade pinned actions: Use https://github.com/mheap/pin-github-action
2+
3+
name: CI - E2E
4+
5+
env:
6+
OS: &os ubuntu-24.04
7+
8+
# run job only under the following conditions:
9+
# - can be triggered manually from any repository
10+
# - can be triggered as workflow call by another workflow
11+
# - if on pull request, only run if from a fork
12+
# (our own repo is covered by the push event)
13+
# - if on push, only run CI automatically for the
14+
# main getkirby/kirby repo and for forks
15+
SHOULD_RUN: &should-run >-
16+
github.event_name == 'workflow_dispatch' ||
17+
github.event_name == 'workflow_call' ||
18+
(github.event_name == 'pull_request' &&
19+
github.event.pull_request.head.repo.full_name != github.repository) ||
20+
(github.event_name == 'push' &&
21+
(github.repository == 'getkirby/kirby' || github.repository_owner != 'getkirby'))
22+
23+
on:
24+
push: &e2e-triggers
25+
branches-ignore:
26+
- "main"
27+
- "release/**"
28+
paths:
29+
- "**"
30+
- "!.github/**"
31+
- ".github/actions/setup-npm/**"
32+
- ".github/actions/setup-php/**"
33+
- ".github/workflows/e2e.yml"
34+
- "!.tx/**"
35+
- "!.vscode/**"
36+
- "!assets/**"
37+
- "!scripts/**"
38+
pull_request: *e2e-triggers
39+
workflow_call:
40+
workflow_dispatch:
41+
42+
concurrency:
43+
group: e2e-${{ github.ref }}
44+
cancel-in-progress: true
45+
46+
jobs:
47+
tests:
48+
name: "Tests"
49+
if: *should-run
50+
runs-on: *os
51+
timeout-minutes: 15
52+
53+
steps:
54+
- name: Checkout sandbox
55+
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
56+
with:
57+
repository: getkirby/sandbox
58+
ref: feat/develop-license
59+
path: sandbox
60+
61+
- name: Checkout kirby into sandbox
62+
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
63+
with:
64+
path: sandbox/kirby
65+
66+
- name: Setup PHP environment
67+
uses: ./sandbox/kirby/.github/actions/setup-php
68+
with:
69+
php: "8.4"
70+
extensions: "mbstring, ctype, curl, gd"
71+
72+
- name: Create sandbox config
73+
run: |
74+
cat > sandbox/sandbox.config.php << 'EOF'
75+
<?php
76+
return [
77+
'url' => 'http://localhost:8000',
78+
'panel' => ['dev' => false]
79+
];
80+
EOF
81+
82+
- name: Start PHP server
83+
run: php -S localhost:8000 -t sandbox sandbox/router.php &
84+
85+
- name: Set up Node.js and cache npm dependencies
86+
uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4
87+
with:
88+
node-version: 22
89+
cache: "npm"
90+
cache-dependency-path: sandbox/kirby/panel/package-lock.json
91+
92+
- name: Install npm dependencies
93+
working-directory: sandbox/kirby/panel
94+
run: npm ci
95+
96+
- name: Install Playwright browsers
97+
working-directory: sandbox/kirby/panel
98+
run: npx playwright install --with-deps chromium
99+
100+
- name: Build Panel
101+
working-directory: sandbox/kirby/panel
102+
run: npm run build
103+
104+
- name: Run E2E tests
105+
working-directory: sandbox/kirby/panel
106+
run: npm run test:e2e
107+
env:
108+
BASE_URL: http://localhost:8000

.github/workflows/frontend.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,3 +82,4 @@ jobs:
8282

8383
- name: "Prettier: JavaScript coding style violations"
8484
run: npm run format -- --check
85+

.github/workflows/release.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,7 @@ jobs:
1818
name: "Release: CI - Frontend"
1919
uses: ./.github/workflows/frontend.yml
2020
secrets: inherit
21+
release_e2e:
22+
name: "Release: CI - E2E"
23+
uses: ./.github/workflows/e2e.yml
24+
secrets: inherit

panel/.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ yarn-error.log*
1515

1616
# tests
1717
coverage
18+
e2e/session.json
19+
e2e/report
20+
e2e/results
1821

1922
# Editor directories and files
2023
.idea

panel/e2e/setup.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import { test } from "@playwright/test";
2+
3+
test("authenticate", async ({ page }) => {
4+
await page.goto("/env/auth/admin");
5+
await page.context().storageState({ path: "e2e/session.json" });
6+
});
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import { test, expect } from "@playwright/test";
2+
3+
test("bar component", async ({ page }) => {
4+
page.on("console", (msg) => console.log("CONSOLE:", msg.type(), msg.text()));
5+
page.on("pageerror", (err) => console.log("PAGE ERROR:", err.message));
6+
7+
await page.goto("/panel/lab/components/bar");
8+
await page.waitForLoadState("networkidle");
9+
console.log("Page content:", await page.content());
10+
11+
const examples = page.locator(".k-lab-examples");
12+
await expect(examples).toBeVisible();
13+
14+
const bars = examples.locator(".k-bar");
15+
await expect(bars).toHaveCount(4);
16+
17+
await expect(bars.nth(0)).toHaveAttribute("data-align", "start");
18+
await expect(bars.nth(0).locator(":scope > *")).toHaveCount(3);
19+
20+
await expect(bars.nth(1)).toHaveAttribute("data-align", "start");
21+
await expect(bars.nth(1).locator(":scope > *")).toHaveCount(1);
22+
23+
await expect(bars.nth(2)).toHaveAttribute("data-align", "center");
24+
await expect(bars.nth(2).locator(":scope > *")).toHaveCount(2);
25+
26+
await expect(bars.nth(3)).toHaveAttribute("data-align", "end");
27+
await expect(bars.nth(3).locator(":scope > *")).toHaveCount(1);
28+
});

panel/package-lock.json

Lines changed: 64 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

panel/package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
11
{
22
"name": "kirby",
33
"private": true,
4+
"type": "module",
45
"scripts": {
56
"build": "vite build",
67
"build:docs": "node scripts/docs.mjs",
78
"dev": "vite --host",
89
"lint": "eslint \"src/**/*.{js,vue}\"",
910
"lint:fix": "npm run lint -- --fix",
1011
"format": "prettier --write \"src/**/*.{js,vue}\"",
11-
"test:unit": "vitest run"
12+
"test:unit": "vitest run",
13+
"test:e2e": "playwright test"
1214
},
1315
"dependencies": {
1416
"autosize": "^6.0.1",
@@ -25,6 +27,7 @@
2527
"vue": "^3.5.27"
2628
},
2729
"devDependencies": {
30+
"@playwright/test": "^1.58.2",
2831
"@vitejs/plugin-vue": "^6.0.4",
2932
"@vitest/eslint-plugin": "^1.6.6",
3033
"@vue/compiler-sfc": "^3.5.27",

panel/playwright.config.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/* eslint-env node */
2+
import { defineConfig } from "@playwright/test";
3+
4+
const BASE_URL = process.env.BASE_URL ?? "https://sandbox.test";
5+
6+
export default defineConfig({
7+
testMatch: ["{lab,e2e}/**/*.spec.js"],
8+
outputDir: "e2e/results",
9+
reporter: process.env.CI ? "dot" : [["html", { outputFolder: "e2e/report" }]],
10+
11+
use: {
12+
baseURL: BASE_URL,
13+
ignoreHTTPSErrors: true
14+
},
15+
16+
projects: [
17+
{
18+
name: "setup",
19+
testMatch: "e2e/setup.js"
20+
},
21+
{
22+
name: "tests",
23+
dependencies: ["setup"],
24+
use: { storageState: "e2e/session.json" }
25+
}
26+
]
27+
});

0 commit comments

Comments
 (0)