Skip to content

chore(tests): move from testcafe to playwright #2088

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 13 commits into from
Closed
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
21 changes: 0 additions & 21 deletions .github/workflows/library-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,27 +21,6 @@ jobs:
working-directory: packages/browser
- run: git diff --exit-code # fail if e.g. the mangled properties list has changed, see rollup.config.js

integration:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

two significant changes here

  1. no longer running these tests on push to main

i think we should still run them, just to catch the very rare risk of things being valid in the PR but not once merged

  1. we've gone from two e2e suites - one of which uses posthog cloud - to one e2e suite without that distinction

it'd be good and my instinct is faster to run them as two suites. the replay ones don't hit posthog cloud iirc and would be good to keep them clearly separate

name: Playwright E2E tests
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v4
- uses: ./.github/actions/setup
- run: pnpm build
working-directory: packages/browser
- name: Install Playwright Browsers
run: pnpm exec playwright install --with-deps
working-directory: packages/browser
- name: Run Playwright tests
run: pnpm exec playwright test
working-directory: packages/browser
- uses: actions/upload-artifact@v4
if: ${{ !cancelled() }}
with:
name: playwright-report
path: packages/browser/playwright-report/
retention-days: 30

functional:
name: Functional tests
runs-on: ubuntu-22.04
Expand Down
42 changes: 42 additions & 0 deletions .github/workflows/playwright.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
name: Playwright Tests

on: [pull_request]

env:
POSTHOG_PROJECT_KEY: "${{ secrets.POSTHOG_PROJECT_KEY }}"
POSTHOG_API_KEY: "${{ secrets.POSTHOG_API_KEY }}"

jobs:
integration:
name: Playwright - ${{ matrix.project }}
runs-on: ubuntu-22.04
strategy:
matrix:
project:
- "chromium"
- "firefox"
- "webkit"
fail-fast: false
steps:
- uses: actions/checkout@v4
- uses: ./.github/actions/setup
- run: pnpm build
working-directory: packages/browser
- name: Install Playwright Browsers
run: pnpm exec playwright install ${{ matrix.project }} --with-deps
working-directory: packages/browser
- name: Run Playwright tests
run: pnpm exec playwright test --project ${{ matrix.project }}
working-directory: packages/browser
timeout-minutes: 10
env:
WITH_INGESTION_CHECKS: true
BRANCH_NAME: ${{ github.head_ref || github.ref_name }}
RUN_ID: ${{ github.run_id }}
BROWSER: ${{ matrix.project }}
- uses: actions/upload-artifact@v4
if: ${{ !cancelled() }}
with:
name: playwright-report-${{ matrix.project }}
path: packages/browser/playwright-report/
retention-days: 30
61 changes: 0 additions & 61 deletions .github/workflows/testcafe.yml

This file was deleted.

22 changes: 20 additions & 2 deletions packages/browser/.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,33 @@ module.exports = {
},
},
{
files: './playwright/**/*.ts',
files: './playwright/**/*',
rules: {
'posthog-js/no-direct-array-check': 'off',
'posthog-js/no-direct-undefined-check': 'off',
'posthog-js/no-direct-null-check': 'off',
'@typescript-eslint/naming-convention': 'off',
'compat/compat': 'off',
'@typescript-eslint/no-unsafe-function-type': 'off',
'no-empty-pattern': 'off',
'@typescript-eslint/no-empty-object-type': 'off',
},
env: {
node: true,
},
},
{
files: './playwright/mock-server.mjs',
rules: {
'no-console': 'off',
},
env: {
node: true,
},
parserOptions: {
project: null,
ecmaVersion: 2018,
sourceType: 'module',
project: true,
},
},
{
Expand Down
1 change: 1 addition & 0 deletions packages/browser/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,4 @@ cypress/downloads/downloads.html
/blob-report/
/playwright/.cache/
/stats
/playwright/ingestion/*.results.json
9 changes: 6 additions & 3 deletions packages/browser/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@
"test:typecheck": "cd src/__tests__ && tsc --noEmit --project tsconfig.json",
"typecheck": "tsc --noEmit --project tsconfig.json",
"playwright": "pnpm exec playwright test --project webkit --project firefox --project chromium",
"playwright:integration": "pnpm exec playwright test --config=playwright.config.integration.ts --project webkit --project firefox --project chromium",
"playwright-ui": "pnpm exec playwright test --ui --project webkit --project firefox --project chromium",
"playwright-webserver": "npx http-server ./ -p 8082",
"playwright:surveys": "pnpm exec playwright test playwright/surveys/* --project webkit --project firefox --project chromium",
"playwright:surveys:ui": "pnpm exec playwright test playwright/surveys/* --ui --project webkit --project firefox --project chromium",
"prepare": "[ -z \"$VERCEL\" ] && husky install || echo \"Skipping husky install on vercel build\"",
"deprecate-old-versions": "node scripts/deprecate-old-versions.mjs",
"check-testcafe-results": "ts-node testcafe/check-testcafe-results.js",
"check-api-results": "ts-node playwright/ingestion/check-api-results.ts",
"run-testcafe-localhost": "node scripts/run-testcafe-localhost.mjs",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

logic: This script still references TestCafe and should be removed or updated for Playwright

"write-mangled-property-names": "WRITE_MANGLED_PROPERTIES=1 pnpm build-rollup",
"gen-specs": "pnpm exec tsc && pnpm exec api-extractor run --config ./api-extractor.json --local",
Expand Down Expand Up @@ -84,6 +84,7 @@
"@testing-library/dom": "^9.3.0",
"@testing-library/jest-dom": "^6.5.0",
"@testing-library/preact": "^3.2.4",
"@types/express": "^5.0.3",
"@types/jest": "^27.5.2",
"@types/node": "^22.5.0",
"@types/react-dom": "^18.0.10",
Expand All @@ -94,15 +95,17 @@
"compare-versions": "^6.1.0",
"cssnano": "^7.0.7",
"date-fns": "^3.6.0",
"dotenv": "^17.2.0",
"expect": "^29.7.0",
"express": "^5.1.0",
"fast-check": "^2.17.0",
"http-server": "14.1.1",
"husky": "^8.0.1",
"identity-obj-proxy": "^3.0.0",
"jest": "^27.5.1",
"jest-environment-jsdom": "^27.5.1",
"jsdom": "16.5.0",
"jsdom-global": "3.0.2",
"jest-environment-jsdom": "^27.5.1",
"localStorage": "1.0.4",
"msw": "^1.3.3",
"node-fetch": "^2.6.11",
Expand Down
19 changes: 19 additions & 0 deletions packages/browser/playwright.config.integration.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import baseConfig from './playwright.config'

/**
* Read environment variables from file.
* https://github.com/motdotla/dotenv
*/
import dotenv from 'dotenv'
import path from 'path'
import fs from 'fs'

if (fs.existsSync(path.resolve(__dirname, '.env'))) {
dotenv.config({ path: path.resolve(__dirname, '.env') })
}

export default {
...baseConfig,
testDir: './playwright/integration',
testIgnore: undefined,
}
29 changes: 6 additions & 23 deletions packages/browser/playwright.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { defineConfig, devices } from '@playwright/test'
*/
export default defineConfig({
testDir: './playwright',
testIgnore: '**/playwright/integration/**',
/* Run tests in files in parallel */
fullyParallel: true,
/* Fail the build on CI if you accidentally left test.only in the source code. */
Expand All @@ -26,7 +27,7 @@ export default defineConfig({
/* 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:8082',
baseURL: 'http://localhost:2345',

/* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */
trace: 'on-first-retry',
Expand All @@ -48,32 +49,14 @@ export default defineConfig({
name: 'webkit',
use: { ...devices['Desktop Safari'] },
},

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

/* Test against branded browsers. */
// {
// name: 'Microsoft Edge',
// use: { ...devices['Desktop Edge'], channel: 'msedge' },
// },
// {
// name: 'Google Chrome',
// use: { ...devices['Desktop Chrome'], channel: 'chrome' },
// },
],

/* Run your local dev server before starting the tests */
webServer: {
command: 'pnpm run playwright-webserver',
url: 'http://localhost:8082',
command: 'node playwright/mock-server.mjs --port 2345',
port: 2345,
reuseExistingServer: !process.env.CI,
stdout: 'pipe',
stderr: 'pipe',
},
})
Loading
Loading