Skip to content

Commit 9c942a0

Browse files
committed
feat: Added playwright to example site + gh action for CI
1 parent 3bc0273 commit 9c942a0

File tree

12 files changed

+209
-5
lines changed

12 files changed

+209
-5
lines changed

.github/workflows/playwright.yml

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
name: Testing for visual regression on old theme
2+
3+
# Run the workflow when code is pushed or when a pull request is created
4+
on:
5+
push:
6+
branches:
7+
- '**'
8+
pull_request:
9+
branches:
10+
- main
11+
12+
jobs:
13+
playwright:
14+
name: Run Playwright
15+
runs-on: ubuntu-latest
16+
steps:
17+
# Checkout the repository so the workflow has access to the code
18+
- name: Checkout code
19+
uses: actions/checkout@v3
20+
- name: Install dependencies
21+
run: cd tests && npm ci
22+
- name: Install Playwright browsers
23+
run: npx playwright install --with-deps
24+
- name: Run Playwright tests
25+
run: make tests
26+
- uses: actions/upload-artifact@v4
27+
if: ${{ !cancelled() }}
28+
with:
29+
name: playwright-report
30+
path: tests/playwright-report/
31+
retention-days: 30
32+
- uses: actions/upload-artifact@v4
33+
if: ${{ !cancelled() }}
34+
with:
35+
name: test-results
36+
path: tests/test-results/
37+
retention-days: 30

.gitignore

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ Thumbs.db
1515
########
1616
*.log
1717

18-
node_modules/*
18+
*/node_modules
1919
.markdownlint.json
2020
resources/*
2121

@@ -27,4 +27,9 @@ public/*
2727
exampleSite/public
2828

2929
# Python
30-
.venv
30+
.venv
31+
32+
# Playwright
33+
/coverage
34+
*/test-results
35+
*/playwright-report

Makefile

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,12 @@ list help::
1212
@echo " biome-lint: Runs the biome linter."
1313
@echo " biome-all: Runs both the lint and formatting commands."
1414
@echo " (Set BIOME_ARGS to add additional arguments to biome command (ex: make biome-all BIOME_ARGS=write))"
15+
@echo "<PRE-COMMIT>"
16+
@echo " setup-pre-commit: Sets up pre-commit (assuming it is installed)"
17+
@echo "<PLAYWRIGHT TESTS>"
18+
@echo " test: Runs playwright against the old theme."
1519

16-
.PHONY: biome-format biome-lint biome-all setup-pre-commit
17-
BIOME_ARGS ?=
20+
.PHONY: biome-format biome-lint biome-all setup-pre-commit tests
1821
FLAG :=
1922
ifeq ($(BIOME_ARGS), write)
2023
FLAG := $(WRITE_FLAG)
@@ -36,3 +39,6 @@ setup-pre-commit:
3639
pre-commit install --hook-type commit-msg; \
3740
echo "pre-commit hooks have been successfully installed."; \
3841
fi
42+
43+
tests:
44+
cd tests && npx playwright test

biome.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,9 @@
2222
"**/coveo.css",
2323
"**/f5-hugo.css",
2424
"**/highlight.css",
25-
"**/*-overrides.css"
25+
"**/*-overrides.css",
26+
"public/*",
27+
"test-results/*"
2628
]
2729
},
2830
"formatter": {

tests/package-lock.json

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

tests/package.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"name": "nginx-docs-theme-test",
3+
"version": "1.0.0",
4+
"private": "true",
5+
"devDependencies": {
6+
"@playwright/test": "^1.48.0"
7+
}
8+
}

tests/playwright.config.js

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import { defineConfig, devices } from '@playwright/test';
2+
3+
const BASE_URL = 'http://127.0.0.1';
4+
const PORT = 1313;
5+
export default defineConfig({
6+
testDir: './src',
7+
fullyParallel: true,
8+
workers: 1,
9+
outputDir: './test-results',
10+
snapshotPathTemplate: '{testDir}/__screenshots__/{testFilePath}/{arg}{ext}',
11+
reporter: [['html', { outputFolder: './playwright-report' }]],
12+
use: {
13+
baseURL: `${BASE_URL}:${PORT}`,
14+
screenshots: 'only-on-failure',
15+
video: 'retain-on-failure',
16+
trace: 'on-first-retry',
17+
},
18+
projects: [
19+
{
20+
name: 'chromium',
21+
use: { ...devices['Desktop Chrome'] },
22+
},
23+
{
24+
name: 'firefox',
25+
use: { ...devices['Desktop Firefox'] },
26+
},
27+
{
28+
name: 'webkit',
29+
use: { ...devices['Desktop Safari'] },
30+
},
31+
{
32+
name: 'Mobile Chrome',
33+
use: { ...devices['Pixel 5'] },
34+
},
35+
],
36+
webServer: {
37+
command: `cd ../exampleSite && hugo mod get && hugo --gc -e production && hugo serve --port ${PORT}`,
38+
url: `${BASE_URL}:${PORT}`,
39+
stdout: 'ignore',
40+
},
41+
expect: {
42+
toHaveScreenshot: {
43+
pathTemplate:
44+
'{testDir}/__screenshots__{/projectName}/{testFilePath}/{arg}{ext}',
45+
},
46+
},
47+
});
Loading
Loading
Loading
Loading

tests/src/visual-regression.spec.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import { expect, test } from '@playwright/test';
2+
3+
test.describe('Testing old theme', () => {
4+
test('should ensure the old theme does not visually regress', async ({
5+
page,
6+
}) => {
7+
const currentPlus = 'nginx/installing-nginx-open-source/';
8+
await page.goto(`/${currentPlus}`, { waitUntil: 'networkidle' });
9+
await page.evaluate(() => {
10+
// switch to old theme
11+
useNewTheme(false);
12+
});
13+
await page.waitForTimeout(500);
14+
await page.screenshot({
15+
path: './test-results/example-site-snapshot.png',
16+
fullPage: true,
17+
});
18+
19+
await expect(page).toHaveScreenshot('example-site-screenshot.png');
20+
});
21+
});

0 commit comments

Comments
 (0)