Skip to content

Commit aecc225

Browse files
playwright tests
1 parent 272c93c commit aecc225

12 files changed

+181
-7
lines changed

.github/workflows/playwright.yml

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

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,6 @@ node_modules
77
.env
88
.env.*
99
!.env.example
10+
/test-results/
11+
/playwright-report/
12+
/playwright/.cache/

package.json

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,20 +59,27 @@
5959
"scripts": {
6060
"dev": "vite dev",
6161
"build": "vite build",
62+
"preview": "vite preview",
6263
"package": "svelte-kit sync && tsup && publint",
6364
"prepublishOnly": "npm run package",
6465
"check": "svelte-check --tsconfig ./tsconfig.json",
6566
"check:watch": "svelte-check --tsconfig ./tsconfig.json --watch",
6667
"lint": "eslint --max-warnings 0 --report-unused-disable-directives --ignore-path ./.gitignore \"**/*.{js,cjs,mjs,ts,cts,mts,svelte}\"",
67-
"sourcemap": "source-map-explorer dist/*.js"
68+
"sourcemap": "source-map-explorer dist/*.js",
69+
"test": "playwright test",
70+
"test:ui": "playwright test --ui",
71+
"test:report": "playwright show-report",
72+
"test:update": "playwright test --update-snapshots"
6873
},
6974
"devDependencies": {
75+
"@playwright/test": "^1.38.1",
7076
"@sveltejs/adapter-static": "^2.0.3",
7177
"@sveltejs/kit": "^1.25.1",
7278
"@tailwindcss/forms": "^0.5.6",
7379
"@tailwindcss/typography": "^0.5.10",
7480
"@typescript-eslint/eslint-plugin": "^6.7.4",
7581
"@typescript-eslint/parser": "^6.7.4",
82+
"@types/node": "^20.8.2",
7683
"autoprefixer": "^10.4.16",
7784
"eslint": "^8.50.0",
7885
"eslint-plugin-svelte": "^2.34.0",

playwright.config.ts

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
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: './tests',
14+
/* Run tests in files in parallel */
15+
fullyParallel: true,
16+
/* Fail the build on CI if you accidentally left test.only in the source code. */
17+
forbidOnly: !!process.env.CI,
18+
/* Retry on CI only */
19+
retries: process.env.CI ? 2 : 0,
20+
/* Opt out of parallel tests on CI. */
21+
workers: process.env.CI ? 1 : undefined,
22+
/* Reporter to use. See https://playwright.dev/docs/test-reporters */
23+
reporter: 'html',
24+
/* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */
25+
use: {
26+
/* Base URL to use in actions like `await page.goto('/')`. */
27+
baseURL: 'http://localhost:4173',
28+
29+
/* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */
30+
trace: 'on-first-retry',
31+
},
32+
33+
/* Configure projects for major browsers */
34+
projects: [
35+
{
36+
name: 'chromium',
37+
use: { ...devices['Desktop Chrome'] },
38+
},
39+
40+
{
41+
name: 'firefox',
42+
use: { ...devices['Desktop Firefox'] },
43+
},
44+
45+
{
46+
name: 'webkit',
47+
use: { ...devices['Desktop Safari'] },
48+
},
49+
50+
/* Test against mobile viewports. */
51+
// {
52+
// name: 'Mobile Chrome',
53+
// use: { ...devices['Pixel 5'] },
54+
// },
55+
// {
56+
// name: 'Mobile Safari',
57+
// use: { ...devices['iPhone 12'] },
58+
// },
59+
60+
/* Test against branded browsers. */
61+
// {
62+
// name: 'Microsoft Edge',
63+
// use: { ...devices['Desktop Edge'], channel: 'msedge' },
64+
// },
65+
// {
66+
// name: 'Google Chrome',
67+
// use: { ...devices['Desktop Chrome'], channel: 'chrome' },
68+
// },
69+
],
70+
71+
webServer: {
72+
command: 'npm run build && npm run preview',
73+
port: 4173
74+
},
75+
});

pnpm-lock.yaml

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

tests/button.spec.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import { test, expect } from '@playwright/test';
2+
3+
test('toggle button', async ({ page }) => {
4+
await page.goto('/example/button');
5+
6+
const button = page.getByRole('button');
7+
8+
expect(button).toHaveAttribute('aria-label', 'Control Music')
9+
expect(button).toHaveAttribute('aria-pressed', 'false')
10+
expect(button).toHaveText('Play')
11+
await expect(page).toHaveScreenshot('unpressed.png');
12+
13+
await button.click()
14+
15+
expect(button).toHaveText('Pause')
16+
expect(button).toHaveAttribute('aria-pressed', 'true')
17+
await expect(page).toHaveScreenshot('pressed.png');
18+
});
Loading
Loading
Loading
Loading
Loading
Loading

0 commit comments

Comments
 (0)