Skip to content

Commit da867d7

Browse files
authored
feat: playwright — setting up for testing (#317)
feat: `playwright` — setting up for testing
2 parents 9e32e91 + bb4edd8 commit da867d7

File tree

7 files changed

+177
-4
lines changed

7 files changed

+177
-4
lines changed

.github/workflows/playwright.yml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
name: Playwright Tests
2+
on:
3+
push:
4+
branches: [ main, master ]
5+
pull_request:
6+
branches: [ main, master ]
7+
jobs:
8+
test:
9+
timeout-minutes: 60
10+
runs-on: ubuntu-latest
11+
steps:
12+
- uses: actions/checkout@v4
13+
- uses: actions/setup-node@v4
14+
with:
15+
node-version: lts/*
16+
- name: Install dependencies
17+
run: npm ci
18+
- name: Install Playwright Browsers
19+
run: npx playwright install --with-deps
20+
- name: Run Playwright tests
21+
run: npx playwright test
22+
- uses: actions/upload-artifact@v4
23+
if: ${{ !cancelled() }}
24+
with:
25+
name: playwright-report
26+
path: playwright-report/
27+
retention-days: 30

.gitignore

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,11 @@
88

99
# /src/blog/example/*
1010

11-
.cache
11+
.cache
12+
13+
# Playwright
14+
node_modules/
15+
/test-results/
16+
/playwright-report/
17+
/blob-report/
18+
/playwright/.cache/

package-lock.json

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

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
"watch:sass": "npm run sass:compressed -- --watch",
1616
"watch:postcss": "npm run postcss -- --watch",
1717
"build": "npm run sass:compressed && npm run postcss && npm run minify:js && eleventy && npm run prettify:html",
18-
"start": "npm-run-all sass:compressed postcss --parallel watch:*",
18+
"start": "npm-run-all --parallel watch:eleventy",
1919
"dev": "npm run watch",
2020
"test:highlightjs-lines": "node ./lib/highlightjs-lines.test.js",
2121
"test": "node --test"
@@ -34,6 +34,8 @@
3434
"devDependencies": {
3535
"@11ty/eleventy": "^3.1.1",
3636
"@11ty/eleventy-plugin-rss": "^2.0.4",
37+
"@playwright/test": "^1.53.1",
38+
"@types/node": "^24.0.7",
3739
"autoprefixer": "^10.4.21",
3840
"postcss": "^8.5.5",
3941
"postcss-cli": "^11.0.1",

playwright.config.ts

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import { defineConfig, devices } from '@playwright/test';
2+
3+
const localhost = "http://localhost:8080"
4+
5+
export default defineConfig({
6+
testDir: './tests',
7+
fullyParallel: true,
8+
forbidOnly: !!process.env.CI,
9+
retries: process.env.CI ? 2 : 0,
10+
workers: process.env.CI ? 1 : undefined,
11+
reporter: [['html', { open: 'never' }]],
12+
use: {
13+
baseURL: localhost,
14+
trace: 'on-first-retry',
15+
},
16+
projects: [
17+
{
18+
name: 'chromium',
19+
use: { ...devices['Desktop Chrome'] },
20+
},
21+
{
22+
name: 'firefox',
23+
use: { ...devices['Desktop Firefox'] },
24+
},
25+
{
26+
name: 'webkit',
27+
use: { ...devices['Desktop Webkit'] },
28+
},
29+
],
30+
webServer: {
31+
command: 'npm start',
32+
url: localhost,
33+
reuseExistingServer: !process.env.CI,
34+
},
35+
});

src/_includes/sections/hero.njk

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,10 +78,10 @@
7878
<ul class="title-action__group">
7979
<li data-animation="left-show" data-delay="2">
8080
<a href="./assets/Curriculum Vitae.pdf"
81-
aria-label="Open PDF of my Curriculum Vitae"
81+
aria-label="Download my Curriculum Vitae"
8282
target="_blank"
8383
rel="noopener noreferrer"
84-
class="title-action">
84+
class="title-action" download>
8585
<svg fill="currentColor"
8686
viewBox="0 0 20 20"
8787
xmlns="http://www.w3.org/2000/svg"

tests/landing-page.spec.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import { test, expect } from '@playwright/test';
2+
3+
test('has title', async ({ page }) => {
4+
await page.goto('/');
5+
await expect(page).toHaveTitle(/EmptyWork/);
6+
});
7+
8+
test('find a curriculum vitae and download', async ({ page }) => {
9+
test.setTimeout(0);
10+
11+
await page.goto('/');
12+
13+
const downloadPromise = page.waitForEvent('download');
14+
await page.getByRole('link', { name: 'Download my Curriculum Vitae' }).click();
15+
const download = await downloadPromise;
16+
17+
const fileName = download.suggestedFilename();
18+
expect(fileName).toMatch(/\.pdf$/);
19+
20+
});

0 commit comments

Comments
 (0)