Skip to content

Commit 80be76a

Browse files
authored
Merge pull request #3335 from metacpan/oalders/local
Add a simple Playwright test
2 parents afb9fa5 + 364d5ae commit 80be76a

File tree

7 files changed

+152
-0
lines changed

7 files changed

+152
-0
lines changed

.github/workflows/test.yml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,29 @@ jobs:
6262
load: true
6363
- name: Run Perl tests
6464
run: docker run -i ${{ steps.docker-build-test.outputs.imageid }}
65+
playwright:
66+
runs-on: ubuntu-24.04
67+
name: playwright test
68+
steps:
69+
- uses: actions/checkout@v4
70+
- name: Build test image
71+
id: docker-build-test
72+
uses: docker/build-push-action@v6
73+
with:
74+
target: server
75+
push: false
76+
load: true
77+
- name: Run Perl tests
78+
run: >
79+
docker run -d -i -p 8000:80
80+
${{ steps.docker-build-test.outputs.imageid }}
81+
- uses: actions/setup-node@v4
82+
with:
83+
node-version: 22
84+
- name: Install Playwright Browsers
85+
run: ./bin/install-playwright
86+
- name: Run Playwright tests
87+
run: npx playwright test
6588
test:
6689
runs-on: ubuntu-24.04
6790
name: Dockerless

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
/metacpan_web_local.*
1313
/node_modules/
1414
/perltidy.LOG
15+
/playwright
1516
/pm_to_blib
1617
/tidyall.ERR
1718
/var

bin/install-playwright

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#!/bin/bash
2+
3+
set -eu -o pipefail
4+
npm i
5+
npx playwright install chromium --with-deps

e2e/home.spec.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import { test, expect } from '@playwright/test';
2+
3+
test('home page', async ({ page }) => {
4+
await page.goto('/');
5+
await expect(page).toHaveTitle(/Search the CPAN - metacpan.org/, { timeout: 10 });
6+
});

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.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
"homepage": "https://github.com/metacpan/metacpanweb#readme",
1919
"devDependencies": {
2020
"@eslint/js": "^9.5.0",
21+
"@playwright/test": "^1.52.0",
2122
"eslint": "^9.25.1",
2223
"globals": "^16.0.0",
2324
"js-beautify": "^1.15.4",

playwright.config.ts

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
import { defineConfig, devices } from "@playwright/test";
2+
3+
/**
4+
* Read environment variables from file.
5+
* https://github.com/motdotla/dotenv
6+
*/
7+
// require('dotenv').config();
8+
9+
/**
10+
* See https://playwright.dev/docs/test-configuration.
11+
*/
12+
export default defineConfig({
13+
testDir: "./e2e",
14+
outputDir: "./playwright/test-results",
15+
/* Run tests in files in parallel */
16+
fullyParallel: true,
17+
/* Fail the build on CI if you accidentally left test.only in the source code. */
18+
// forbidOnly: !!process.env.CI,
19+
/* Retry on CI only */
20+
retries: 0,
21+
/* Opt out of parallel tests on CI. */
22+
// workers: process.env.CI ? 1 : undefined,
23+
workers: 1,
24+
/* Reporter to use. See https://playwright.dev/docs/test-reporters */
25+
reporter: [["html", { outputFolder: "./playwright/report" }]],
26+
/* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */
27+
use: {
28+
/* Base URL to use in actions like `await page.goto('/')`. */
29+
baseURL: "http://127.0.0.1:8000",
30+
31+
/* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */
32+
trace: "on-first-retry",
33+
},
34+
35+
/* Configure projects for major browsers */
36+
projects: [
37+
{
38+
name: "chromium",
39+
use: { ...devices["Desktop Chrome"] },
40+
},
41+
42+
// {
43+
// name: 'firefox',
44+
// use: { ...devices['Desktop Firefox'] },
45+
// },
46+
//
47+
// {
48+
// name: 'webkit',
49+
// use: { ...devices['Desktop Safari'] },
50+
// },
51+
],
52+
});

0 commit comments

Comments
 (0)