Skip to content

Commit 69ab32b

Browse files
committed
feat: playwright — setting up for testing
1 parent 6c3df2a commit 69ab32b

File tree

3 files changed

+116
-1
lines changed

3 files changed

+116
-1
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/

playwright.config.ts

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
import { defineConfig, devices } from '@playwright/test';
2+
3+
/**
4+
* Read environment variables from file.
5+
* https://github.com/motdotla/dotenv
6+
*/
7+
import dotenv from 'dotenv';
8+
import path from 'path';
9+
dotenv.config({ path: path.resolve(path.dirname("/"), '.env') });
10+
11+
12+
const localhost = "http://localhost:8080"
13+
/**
14+
* See https://playwright.dev/docs/test-configuration.
15+
*/
16+
export default defineConfig({
17+
testDir: './tests',
18+
/* Run tests in files in parallel */
19+
fullyParallel: true,
20+
/* Fail the build on CI if you accidentally left test.only in the source code. */
21+
forbidOnly: !!process.env.CI,
22+
/* Retry on CI only */
23+
retries: process.env.CI ? 2 : 0,
24+
/* Opt out of parallel tests on CI. */
25+
workers: process.env.CI ? 1 : undefined,
26+
/* Reporter to use. See https://playwright.dev/docs/test-reporters */
27+
reporter: [['html', { open: 'never' }]],
28+
/* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */
29+
use: {
30+
/* Base URL to use in actions like `await page.goto('/')`. */
31+
baseURL: localhost,
32+
33+
/* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */
34+
trace: 'on-first-retry',
35+
},
36+
37+
/* Configure projects for major browsers */
38+
projects: [
39+
{
40+
name: 'chromium',
41+
use: { ...devices['Desktop Chrome'] },
42+
},
43+
44+
{
45+
name: 'firefox',
46+
use: { ...devices['Desktop Firefox'] },
47+
},
48+
49+
{
50+
name: 'webkit',
51+
use: { ...devices['Desktop Safari'] },
52+
},
53+
54+
/* Test against mobile viewports. */
55+
// {
56+
// name: 'Mobile Chrome',
57+
// use: { ...devices['Pixel 5'] },
58+
// },
59+
// {
60+
// name: 'Mobile Safari',
61+
// use: { ...devices['iPhone 12'] },
62+
// },
63+
64+
/* Test against branded browsers. */
65+
// {
66+
// name: 'Microsoft Edge',
67+
// use: { ...devices['Desktop Edge'], channel: 'msedge' },
68+
// },
69+
// {
70+
// name: 'Google Chrome',
71+
// use: { ...devices['Desktop Chrome'], channel: 'chrome' },
72+
// },
73+
],
74+
75+
/* Run your local dev server before starting the tests */
76+
webServer: {
77+
command: 'npm run dev',
78+
url: localhost,
79+
reuseExistingServer: !process.env.CI,
80+
},
81+
});

0 commit comments

Comments
 (0)