Skip to content

Commit b3c1f0b

Browse files
committed
Setup playwright
1 parent d1027b0 commit b3c1f0b

File tree

7 files changed

+216
-2
lines changed

7 files changed

+216
-2
lines changed

.github/workflows/playwright.yml

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
name: Playwright Tests
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
pull_request:
8+
branches:
9+
- '**'
10+
11+
jobs:
12+
test:
13+
timeout-minutes: 5
14+
runs-on: ubuntu-latest
15+
steps:
16+
- uses: actions/checkout@v4
17+
- uses: actions/setup-node@v4
18+
with:
19+
node-version: lts/*
20+
21+
- name: Install dependencies
22+
run: npm install -g pnpm && pnpm install
23+
24+
- name: Get Playwright Version
25+
id: playwright-version
26+
working-directory: app
27+
run: echo "PLAYWRIGHT_VERSION=$(pnpm exec playwright --version | sed 's/Version //')" >> $GITHUB_ENV
28+
29+
- name: Cache Playwright Browsers
30+
uses: actions/cache@v3
31+
with:
32+
path: ~/.cache/ms-playwright
33+
key: ${{ runner.os }}-playwright-${{ env.PLAYWRIGHT_VERSION }}
34+
restore-keys: |
35+
${{ runner.os }}-playwright-
36+
37+
- name: Install Playwright Browsers
38+
run: pnpm exec playwright install --with-deps
39+
working-directory: app
40+
41+
- name: Run Playwright tests
42+
run: pnpm test-e2e
43+
working-directory: app
44+
45+
- uses: actions/upload-artifact@v4
46+
if: always()
47+
with:
48+
name: playwright-report
49+
path: app/playwright-report/
50+
retention-days: 30

.gitignore

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,10 @@ coverage/
55
dist/
66
tsconfig.tsbuildinfo
77
.DS_Store
8-
.env
8+
.env
9+
10+
# Playwright
11+
test-results/
12+
playwright-report/
13+
blob-report/
14+
playwright/.cache/

app/package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,9 @@
4545
"yjs": "^13.6.15"
4646
},
4747
"devDependencies": {
48+
"@playwright/test": "^1.44.1",
4849
"@types/jsdom": "^21.1.7",
50+
"@types/node": "^20.11.24",
4951
"@types/react": "^18.2.61",
5052
"@types/react-dom": "^18.2.19",
5153
"@vitejs/plugin-react": "^4.2.1",
@@ -58,7 +60,8 @@
5860
"scripts": {
5961
"build": "vite build",
6062
"dev": "vite dev",
61-
"test": "vitest run"
63+
"test": "vitest run",
64+
"test-e2e": "playwright test"
6265
},
6366
"browserslist": [
6467
">0.2%",

app/playwright.config.ts

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

app/tests-e2e/smoke.spec.ts

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import { expect, test } from '@playwright/test';
2+
3+
test('has title', async ({ page }) => {
4+
await page.goto('/');
5+
6+
await expect(page).toHaveTitle(/Collabify/);
7+
});
8+
9+
test('can invite collaborator and share text', async ({ browser }) => {
10+
const hostContext = await browser.newContext();
11+
const collaboratorContext = await browser.newContext();
12+
13+
const hostPage = await hostContext.newPage();
14+
const collaboratorPage = await collaboratorContext.newPage();
15+
16+
// Start a new session as host
17+
await hostPage.goto('/new');
18+
await hostPage.getByRole('textbox').fill('Hello world');
19+
20+
// Invite the collaborator
21+
await hostPage
22+
.locator('button')
23+
.filter({ hasText: 'Copy invite URL' })
24+
.click();
25+
const joinUrl = await hostPage.evaluate(() => navigator.clipboard.readText());
26+
await collaboratorPage.goto(joinUrl);
27+
28+
// The collaborator should see the text from the host
29+
await expect(collaboratorPage.getByRole('textbox')).toContainText(
30+
'Hello world',
31+
);
32+
});

app/vite.config.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,7 @@ export default defineConfig({
99
'@': path.resolve(__dirname, './src'),
1010
},
1111
},
12+
test: {
13+
exclude: ['node_modules', 'tests-e2e'],
14+
},
1215
});

pnpm-lock.yaml

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

0 commit comments

Comments
 (0)