Skip to content

Commit 69d9b99

Browse files
committed
feat: initialises playwright e2e testing
1 parent 2395615 commit 69d9b99

9 files changed

+84
-5
lines changed

.github/workflows/main.yml

+13
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ jobs:
1616
- name: Install Dependencies
1717
run: bun install
1818

19+
- name: Install Playwright Browsers
20+
run: bun playwright install --with-deps
21+
1922
- name: Check Format
2023
run: bun format:check
2124

@@ -30,3 +33,13 @@ jobs:
3033

3134
- name: Build
3235
run: bun run build
36+
37+
- name: Run Playwright tests
38+
run: bun playwright test
39+
40+
- uses: actions/upload-artifact@v4
41+
if: always()
42+
with:
43+
name: playwright-report
44+
path: playwright-report/
45+
retention-days: 30

.gitignore

+7-1
Original file line numberDiff line numberDiff line change
@@ -131,4 +131,10 @@ dist
131131
.pnp.*
132132

133133
# DS Store files
134-
.DS_Store
134+
.DS_Store
135+
136+
# Playwright
137+
/test-results/
138+
/playwright-report/
139+
/blob-report/
140+
/playwright/.cache/

.vscode/extensions.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
"unifiedjs.vscode-mdx",
1313
"christian-kohler.path-intellisense",
1414
"YoavBls.pretty-ts-errors",
15-
"bradlc.vscode-tailwindcss"
15+
"bradlc.vscode-tailwindcss",
16+
"ms-playwright.playwright"
1617
]
1718
}

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
55
## Todo
66

7-
- [ ] Playwright E2E tests.
7+
- [x] Playwright E2E tests.
88
- [x] github actions.
99
- [ ] SEO (dub.co is a great reference) for example robots.ts file.
1010
- [ ] Shadcn UI.

bun.lockb

1.93 KB
Binary file not shown.

e2e/example.spec.ts

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import { expect, test } from '@playwright/test';
2+
3+
test('has title', async ({ page }) => {
4+
await page.goto('/');
5+
6+
await expect(page.getByText(/hello world/i)).toBeVisible();
7+
});

eslint.config.js

+19-2
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { FlatCompat } from '@eslint/eslintrc';
77
import js from '@eslint/js';
88
import eslintConfigPrettier from 'eslint-config-prettier';
99
import jsdoc from 'eslint-plugin-jsdoc';
10+
import playwright from 'eslint-plugin-playwright';
1011
import * as regexpPlugin from 'eslint-plugin-regexp';
1112
import pluginSecurity from 'eslint-plugin-security';
1213
import tseslint from 'typescript-eslint';
@@ -24,31 +25,47 @@ export default tseslint.config(
2425
ignores: ['.next'],
2526
},
2627

28+
// Base configurations
2729
js.configs.recommended,
2830
...tseslint.configs.strictTypeChecked,
2931
...tseslint.configs.stylisticTypeChecked,
32+
33+
// Next.js / React
3034
...fixupConfigRules(compat.extends('plugin:@next/next/recommended')),
3135
...fixupConfigRules(compat.extends('plugin:react/recommended')),
3236
...fixupConfigRules(compat.extends('plugin:react-hooks/recommended')),
33-
...fixupConfigRules(compat.extends('plugin:tailwindcss/recommended')),
3437
...fixupConfigRules(compat.extends('plugin:jsx-a11y/strict')),
38+
39+
// Tailwind CSS
40+
...fixupConfigRules(compat.extends('plugin:tailwindcss/recommended')),
41+
42+
// Other plugins
3543
comments.recommended,
3644
regexpPlugin.configs['flat/recommended'],
3745
pluginSecurity.configs.recommended,
3846
eslintConfigPrettier,
3947

48+
// JSDoc plugin only for TypeScript files
4049
{
4150
files: ['**/*.{ts,tsx}'],
4251
extends: [jsdoc.configs['flat/recommended-typescript-error']],
4352
},
4453

54+
// Unit tests
4555
{
46-
files: ['**/?(*.)+(spec|test).[jt]s?(x)'],
56+
files: ['src/**/?(*.)+(spec|test).[jt]s?(x)'],
4757
extends: [
4858
...fixupConfigRules(compat.extends('plugin:testing-library/react')),
4959
],
5060
},
5161

62+
// Playwright
63+
{
64+
files: ['e2e/**'],
65+
...playwright.configs['flat/recommended'],
66+
},
67+
68+
// Settings and rule overrides
5269
{
5370
linterOptions: {
5471
reportUnusedDisableDirectives: true,

package.json

+2
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@
7070
"@happy-dom/global-registrator": "^14.11.0",
7171
"@ianvs/prettier-plugin-sort-imports": "^4.2.1",
7272
"@next/eslint-plugin-next": "^14.2.3",
73+
"@playwright/test": "^1.44.0",
7374
"@tailwindcss/aspect-ratio": "^0.4.2",
7475
"@tailwindcss/container-queries": "^0.1.1",
7576
"@tailwindcss/forms": "^0.5.7",
@@ -89,6 +90,7 @@
8990
"eslint-config-prettier": "^9.1.0",
9091
"eslint-plugin-jsdoc": "^48.2.5",
9192
"eslint-plugin-jsx-a11y": "^6.8.0",
93+
"eslint-plugin-playwright": "^1.6.1",
9294
"eslint-plugin-react": "^7.34.1",
9395
"eslint-plugin-react-hooks": "^4.6.2",
9496
"eslint-plugin-regexp": "^2.5.0",

playwright.config.ts

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

0 commit comments

Comments
 (0)