Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 50 additions & 0 deletions .github/workflows/playwright.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
name: Playwright Tests

on:
push:
branches:
- main
pull_request:
branches:
- '**'

jobs:
test:
timeout-minutes: 5
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: lts/*

- name: Install dependencies
run: npm install -g pnpm && pnpm install

- name: Get Playwright Version
id: playwright-version
working-directory: app
run: echo "PLAYWRIGHT_VERSION=$(pnpm exec playwright --version | sed 's/Version //')" >> $GITHUB_ENV

- name: Cache Playwright Browsers
uses: actions/cache@v3
with:
path: ~/.cache/ms-playwright
key: ${{ runner.os }}-playwright-${{ env.PLAYWRIGHT_VERSION }}
restore-keys: |
${{ runner.os }}-playwright-

- name: Install Playwright Browsers
run: pnpm exec playwright install --with-deps
working-directory: app

- name: Run Playwright tests
run: pnpm test-e2e
working-directory: app

- uses: actions/upload-artifact@v4
if: always()
with:
name: playwright-report
path: app/playwright-report/
retention-days: 30
8 changes: 7 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,10 @@ coverage/
dist/
tsconfig.tsbuildinfo
.DS_Store
.env
.env

# Playwright
test-results/
playwright-report/
blob-report/
playwright/.cache/
5 changes: 4 additions & 1 deletion app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,9 @@
"yjs": "^13.6.15"
},
"devDependencies": {
"@playwright/test": "^1.44.1",
"@types/jsdom": "^21.1.7",
"@types/node": "^20.11.24",
"@types/react": "^18.2.61",
"@types/react-dom": "^18.2.19",
"@vitejs/plugin-react": "^4.2.1",
Expand All @@ -58,7 +60,8 @@
"scripts": {
"build": "vite build",
"dev": "vite dev",
"test": "vitest run"
"test": "vitest run",
"test-e2e": "playwright test"
},
"browserslist": [
">0.2%",
Expand Down
79 changes: 79 additions & 0 deletions app/playwright.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
import { defineConfig, devices } from '@playwright/test';

export default defineConfig({
/* Fail the build on CI if you accidentally left test.only in the source code. */
forbidOnly: !!process.env.CI,

/* Run tests in files in parallel */
fullyParallel: true,

/* Configure projects for major browsers */
projects: [
{
name: 'chromium',
use: {
...devices['Desktop Chrome'],
contextOptions: {
permissions: ['clipboard-read', 'clipboard-write'],
},
},
},

{
name: 'webkit',
use: {
...devices['Desktop Safari'],
contextOptions: {
permissions: ['clipboard-read'],
},
},
},

/* Test against mobile viewports. */
{
name: 'Mobile Chrome',
use: {
...devices['Pixel 5'],
contextOptions: {
permissions: ['clipboard-read', 'clipboard-write'],
},
},
},
{
name: 'Mobile Safari',
use: {
...devices['iPhone 12'],
contextOptions: {
permissions: ['clipboard-read'],
},
},
},
],

/* Reporter to use. See https://playwright.dev/docs/test-reporters */
reporter: 'html',

/* Retry on CI only */
retries: process.env.CI ? 2 : 0,

testDir: './tests-e2e',

/* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */
use: {
/* Base URL to use in actions like `await page.goto('/')`. */
baseURL: 'http://localhost:5173',

/* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */
trace: 'on-first-retry',
},

/* Run your local dev server before starting the tests */
webServer: {
command: 'pnpm dev',
reuseExistingServer: !process.env.CI,
url: 'http://localhost:5173',
},

/* Opt out of parallel tests on CI. */
workers: process.env.CI ? 1 : undefined,
});
32 changes: 32 additions & 0 deletions app/tests-e2e/smoke.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { expect, test } from '@playwright/test';

test('has title', async ({ page }) => {
await page.goto('/');

await expect(page).toHaveTitle(/Collabify/);
});

test('can invite collaborator and share text', async ({ browser }) => {
const hostContext = await browser.newContext();
const collaboratorContext = await browser.newContext();

const hostPage = await hostContext.newPage();
const collaboratorPage = await collaboratorContext.newPage();

// Start a new session as host
await hostPage.goto('/new');
await hostPage.getByRole('textbox').fill('Hello world');

// Invite the collaborator
await hostPage
.locator('button')
.filter({ hasText: 'Copy invite URL' })
.click();
const joinUrl = await hostPage.evaluate(() => navigator.clipboard.readText());
await collaboratorPage.goto(joinUrl);

// The collaborator should see the text from the host
await expect(collaboratorPage.getByRole('textbox')).toContainText(
'Hello world',
);
});
3 changes: 3 additions & 0 deletions app/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,7 @@ export default defineConfig({
'@': path.resolve(__dirname, './src'),
},
},
test: {
exclude: ['node_modules', 'tests-e2e'],
},
});
41 changes: 41 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.