Skip to content

Commit 4443d4b

Browse files
test: add e2e test (#25)
* setup e2e and add test job in pipeline * revert deploy and test * Revert "revert deploy and test" This reverts commit cf8ebee. * fix lint * use pnpm in e2e job * move pnpm before setup nodejs * add html reporter * install playwright deps properly in gitpod and pipeline * properly assert against screenshots * adjust dependencies a bit * fix spelling * disable animations for screenshots * add diff pixel ratio to screenshots --------- Co-authored-by: mariusheine <[email protected]>
1 parent 1c66a1e commit 4443d4b

File tree

12 files changed

+686
-14
lines changed

12 files changed

+686
-14
lines changed

.cspell.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77
".vscode/settings.json",
88
".cspell.json",
99
".nuxt",
10-
"pnpm-lock.yaml"
10+
"pnpm-lock.yaml",
11+
"playwright-report"
1112
],
1213
"words": [
1314
"dprint",
@@ -21,6 +22,10 @@
2122
"language": "de,en",
2223
"words": [
2324
]
25+
},
26+
{
27+
"filename": ["package.json"],
28+
"words": ["libatk1.0-0", "libatk-bridge2.0-0", "libcups2", "libxkbcommon0", "libatspi2.0-0", "libxcomposite1", "libxdamage1", "libxfixes3", "libxrandr2", "libgbm1"]
2429
}
2530
]
2631
}

.github/workflows/deploy.yaml

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
name: Deploy
22

33
on:
4-
pull_request:
5-
branches:
6-
- main
7-
push:
8-
branches:
9-
- main
4+
workflow_run:
5+
workflows: [Tests]
6+
types:
7+
- completed
8+
if: ${{ github.event.workflow_run.conclusion == 'success' }}
109

1110
jobs:
1211
build:

.github/workflows/tests.yaml

Lines changed: 43 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
name: Tests
2-
3-
on: push
2+
on:
3+
push:
4+
branches:
5+
- main
6+
pull_request:
7+
branches:
8+
- main
49

510
jobs:
611
lint:
@@ -41,3 +46,39 @@ jobs:
4146
with:
4247
run_install: true
4348
- run: pnpm spelling
49+
50+
e2e:
51+
name: E2E Tests
52+
runs-on: ubuntu-latest
53+
54+
steps:
55+
- name: Checkout code
56+
uses: actions/checkout@v4
57+
58+
- name: Setup pnpm
59+
uses: pnpm/action-setup@v4
60+
with:
61+
run_install: false
62+
63+
- name: Setup Node.js
64+
uses: actions/setup-node@v4
65+
with:
66+
node-version: 22
67+
cache: pnpm
68+
69+
- name: Install dependencies
70+
run: pnpm install --frozen-lockfile
71+
72+
- name: Install Playwright browsers and system dependencies
73+
run: pnpm playwright:install
74+
75+
- name: Run Playwright tests
76+
run: pnpm test:e2e
77+
78+
- name: Upload Playwright Test Report
79+
if: always()
80+
uses: actions/upload-artifact@v4
81+
with:
82+
name: playwright-report
83+
path: playwright-report/
84+
retention-days: 30

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,8 @@ logs
2424
.env
2525
.env.*
2626
!.env.example
27+
28+
# playwright report
29+
playwright-report/
30+
test-results/
31+

.gitpod.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# This configuration file was automatically generated by Gitpod.
2+
# Please adjust to your needs (see https://www.gitpod.io/docs/introduction/learn-gitpod/gitpod-yaml)
3+
# and commit this file to your remote git repository to share the goodness with others.
4+
5+
# Learn more from ready-to-use templates: https://www.gitpod.io/docs/introduction/getting-started/quickstart
6+
7+
tasks:
8+
- init: pnpm install && pnpm run build
9+
command: pnpm run dev

e2e/tests/navigation.test.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import { expect, test } from '@nuxt/test-utils/playwright';
2+
3+
test.describe('Page Navigation', () => {
4+
test('should navigate to the Start page on click', async ({ page }) => {
5+
await page.goto('/');
6+
await page.click('text="Start page"');
7+
await expect(page).toHaveURL('/');
8+
await expect(page).toHaveScreenshot('start-page.png');
9+
});
10+
11+
test('should navigate to the Other page on click', async ({ page }) => {
12+
await page.goto('/');
13+
await page.click('text="Other page"');
14+
await expect(page).toHaveURL('/other');
15+
await expect(page).toHaveScreenshot('other-page.png');
16+
});
17+
});
7.6 KB
Loading
7.65 KB
Loading

gitpod.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,11 @@ tasks:
1010
pnpm install
1111
nvm alias default 22
1212
echo "nvm use default &>/dev/null" >> ~/.bashrc.d/51-nvm-fix
13+
gp sync-done install
1314
command: pnpm dev
15+
16+
- name: Playwright install
17+
before: |
18+
gp sync-await install
19+
pnpm playwright:install
20+
exit 0

package.json

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@
1414
"spelling": "cspell lint --no-progress '**'",
1515
"typecheck": "nuxt typecheck",
1616
"preview": "nuxt preview",
17-
"postinstall": "nuxt prepare"
17+
"postinstall": "nuxt prepare",
18+
"test:e2e": "playwright test",
19+
"playwright:install": "playwright install && sudo apt-get install libatk1.0-0 libatk-bridge2.0-0 libcups2 libxkbcommon0 libatspi2.0-0 libxcomposite1 libxdamage1 libxfixes3 libxrandr2 libgbm1"
1820
},
1921
"dependencies": {
2022
"@nuxt/ui": "3.1.0",
@@ -25,9 +27,14 @@
2527
"devDependencies": {
2628
"@antfu/eslint-config": "4.13.3",
2729
"@cspell/dict-de-de": "4.1.0",
30+
"@nuxt/test-utils": "3.19.1",
31+
"@playwright/test": "1.53.0",
32+
"@vue/test-utils": "2.4.6",
2833
"cspell": "9.0.1",
2934
"eslint": "9.28.0",
3035
"eslint-plugin-format": "1.0.1",
36+
"happy-dom": "18.0.1",
37+
"vitest": "3.2.3",
3138
"vue-tsc": "2.2.10"
3239
}
3340
}

0 commit comments

Comments
 (0)