From 78ddf6b71ee795cc3c69b93c27c397d26f1200f1 Mon Sep 17 00:00:00 2001 From: Sid Vishnoi <8426945+sidvishnoi@users.noreply.github.com> Date: Fri, 13 Sep 2024 18:32:04 +0530 Subject: [PATCH] test(e2e): support running in headless mode (#594) * test(e2e): allow running in headless mode * add required env var to env.example also * don't need xvfb-run * update `test:e2e` script and docs --- .github/workflows/nightly-build.yaml | 2 +- .github/workflows/tests-e2e.yml | 2 +- docs/TESTING.md | 4 +++- package.json | 3 ++- tests/e2e/.env.example | 1 + tests/e2e/fixtures/helpers.ts | 3 ++- 6 files changed, 10 insertions(+), 5 deletions(-) diff --git a/.github/workflows/nightly-build.yaml b/.github/workflows/nightly-build.yaml index 56870341..7ae44196 100644 --- a/.github/workflows/nightly-build.yaml +++ b/.github/workflows/nightly-build.yaml @@ -45,7 +45,7 @@ jobs: run: pnpm exec playwright install --with-deps - name: Run Playwright tests - run: xvfb-run pnpm test:e2e:${{ matrix.project }} + run: pnpm test:e2e:${{ matrix.project }} env: PLAYWRIGHT_PROJECT: ${{ matrix.project }} PW_EXPERIMENTAL_SERVICE_WORKER_NETWORK_EVENTS: '1' diff --git a/.github/workflows/tests-e2e.yml b/.github/workflows/tests-e2e.yml index 33763569..00669954 100644 --- a/.github/workflows/tests-e2e.yml +++ b/.github/workflows/tests-e2e.yml @@ -47,7 +47,7 @@ jobs: run: pnpm exec playwright install --with-deps - name: Run Playwright tests - run: xvfb-run pnpm test:e2e:${{ matrix.project }} + run: pnpm test:e2e:${{ matrix.project }} env: PLAYWRIGHT_PROJECT: ${{ matrix.project }} PW_EXPERIMENTAL_SERVICE_WORKER_NETWORK_EVENTS: '1' diff --git a/docs/TESTING.md b/docs/TESTING.md index 8bb9f5d6..1af731c1 100644 --- a/docs/TESTING.md +++ b/docs/TESTING.md @@ -6,7 +6,9 @@ Run `pnpm test` to run unit tests locally. These tests are run automatically on ## End-to-end Tests -To run end-to-end tests with chromium, run `pnpm test:e2e` in terminal. +To run end-to-end tests, run `pnpm test:e2e` in terminal. To run tests with Chrome only, run `pnpm test:e2e:chrome`. + +Make sure you run `pnpm build chrome` before running tests. **Before you begin**, you need to setup some environment variables/secrets in `tests/.env`. diff --git a/package.json b/package.json index 005f2605..9e1aa3ee 100644 --- a/package.json +++ b/package.json @@ -17,9 +17,10 @@ "format:fix": "prettier . --write --cache --cache-location='node_modules/.cache/prettiercache' --log-level=warn", "typecheck": "tsc --noEmit", "test": "jest --maxWorkers=2 --passWithNoTests", - "test:e2e": "pnpm test:e2e:chrome", + "test:e2e": "playwright test", "test:e2e:chrome": "playwright test --project=chrome", "test:e2e:msedge": "playwright test --project=msedge", + "test:e2e:report": "playwright show-report tests/e2e/playwright-report", "test:ci": "pnpm test -- --reporters=default --reporters=github-actions" }, "dependencies": { diff --git a/tests/e2e/.env.example b/tests/e2e/.env.example index f65a8766..99ba600c 100644 --- a/tests/e2e/.env.example +++ b/tests/e2e/.env.example @@ -1,5 +1,6 @@ # Used when running tests locally. # In CI, we pass these in via the environment variables directly. +PW_EXPERIMENTAL_SERVICE_WORKER_NETWORK_EVENTS=1 # Can replace with a localhost instance if needed. Ensure doesn't end with / WALLET_URL_ORIGIN=https://rafiki.money diff --git a/tests/e2e/fixtures/helpers.ts b/tests/e2e/fixtures/helpers.ts index 32b74d6b..327dd51b 100644 --- a/tests/e2e/fixtures/helpers.ts +++ b/tests/e2e/fixtures/helpers.ts @@ -146,9 +146,10 @@ export async function loadContext( let context: BrowserContext | undefined; if (browserName === 'chromium') { context = await chromium.launchPersistentContext('', { - headless: false, // headless isn't well supported with extensions + headless: true, channel, args: [ + `--headless=true`, `--disable-extensions-except=${pathToExtension}`, `--load-extension=${pathToExtension}`, ],