Skip to content

Commit

Permalink
Test production builds with playwright on CI
Browse files Browse the repository at this point in the history
  • Loading branch information
lukaw3d committed Nov 1, 2022
1 parent fce5fb6 commit 81d9940
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 7 deletions.
7 changes: 4 additions & 3 deletions .github/workflows/build-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@ jobs:
node-version: 14.x
cache: 'yarn'
- run: yarn install --frozen-lockfile
- run: yarn start &
- run: yarn build:ext
- run: yarn start:prod &
- name: Install playwright's npm dependencies
working-directory: ./playwright/
run: yarn install --frozen-lockfile
Expand All @@ -74,10 +75,10 @@ jobs:
run: npx playwright install --with-deps
- uses: emilioschepis/[email protected]
with:
url: 'http://localhost:3000/'
url: 'http://localhost:5000/'
- name: Run playwright tests (with xvfb-run to support headed extension test)
working-directory: ./playwright/
run: xvfb-run yarn test
run: BASE_URL=http://localhost:5000 EXTENSION_PATH=../build-ext/ xvfb-run yarn test

cypress:
needs: [yarn_cache]
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ yarn test
yarn start
(cd playwright; yarn; npx playwright install --with-deps)
(cd playwright; yarn test)
# Or set BASE_URL and EXTENSION_PATH to test production builds.

# Run cypress tests
docker-compose up -d
Expand Down
3 changes: 2 additions & 1 deletion playwright/playwright.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ const config: PlaywrightTestConfig = {
/* Maximum time each action such as `click()` can take. Defaults to 0 (no limit). */
actionTimeout: 8000,
/* Base URL to use in actions like `await page.goto('/')`. */
baseURL: 'http://localhost:3000',
/* Test dev server by default, but also allow testing `start:prod`. */
baseURL: process.env.BASE_URL ?? 'http://localhost:3000',

/* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */
trace: 'on-first-retry',
Expand Down
9 changes: 6 additions & 3 deletions playwright/tests/extension.spec.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import { test as base, expect, BrowserContext, chromium } from '@playwright/test'
import path from 'path'

import extensionManifest from '../../build-dev/manifest.json'
const pathToExtension = path.join(__dirname, '../../build-dev')
// Test dev build by default, but also allow testing production
const extensionPath = path.join(__dirname, '..', process.env.EXTENSION_PATH ?? '../build-dev/')

// eslint-disable-next-line @typescript-eslint/no-var-requires
const extensionManifest = require(path.join(extensionPath, '/manifest.json'))
const popupFile = extensionManifest.browser_action.default_popup

// From https://playwright.dev/docs/chrome-extensions
Expand All @@ -14,7 +17,7 @@ export const test = base.extend<{
context: async ({}, use) => {
const context = await chromium.launchPersistentContext('', {
headless: false,
args: [`--disable-extensions-except=${pathToExtension}`, `--load-extension=${pathToExtension}`],
args: [`--disable-extensions-except=${extensionPath}`, `--load-extension=${extensionPath}`],
})
await use(context)
await context.close()
Expand Down

0 comments on commit 81d9940

Please sign in to comment.