From 2e28c5073eb3468ec6177da2b75f77b81c23e97f Mon Sep 17 00:00:00 2001 From: Corentin THOMASSET Date: Thu, 29 Jun 2023 20:27:35 +0200 Subject: [PATCH] chore(ci): e2e against vercel deployement (#518) --- .github/workflows/e2e-tests.yml | 13 ++++----- playwright.config.ts | 50 +++++++++++---------------------- 2 files changed, 21 insertions(+), 42 deletions(-) diff --git a/.github/workflows/e2e-tests.yml b/.github/workflows/e2e-tests.yml index d55e7785..ced3bbde 100644 --- a/.github/workflows/e2e-tests.yml +++ b/.github/workflows/e2e-tests.yml @@ -1,13 +1,13 @@ name: E2E tests -on: - pull_request: - push: - branches: - - main +on: [deployment_status] + jobs: test: + if: github.event.deployment_status.state == 'success' timeout-minutes: 60 runs-on: ubuntu-latest + env: + BASE_URL: ${{ github.event.deployment_status.target_url }} strategy: matrix: shard: [1/3, 2/3, 3/3] @@ -28,9 +28,6 @@ jobs: - name: Install dependencies run: pnpm install - - name: Build app - run: pnpm build - - name: Restore Playwright browsers from cache uses: actions/cache@v3 with: diff --git a/playwright.config.ts b/playwright.config.ts index beb9dc65..47fa0cea 100644 --- a/playwright.config.ts +++ b/playwright.config.ts @@ -1,10 +1,7 @@ import { defineConfig, devices } from '@playwright/test'; -/** - * Read environment variables from file. - * https://github.com/motdotla/dotenv - */ -// require('dotenv').config(); +const isCI = !!process.env.CI; +const baseUrl = process.env.BASE_URL || 'http://localhost:5050'; /** * See https://playwright.dev/docs/test-configuration. @@ -15,17 +12,17 @@ export default defineConfig({ /* Run tests in files in parallel */ fullyParallel: true, /* Fail the build on CI if you accidentally left test.only in the source code. */ - forbidOnly: !!process.env.CI, + forbidOnly: isCI, /* Retry on CI only */ - retries: process.env.CI ? 2 : 0, + retries: isCI ? 2 : 0, /* Opt out of parallel tests on CI. */ - workers: process.env.CI ? 1 : undefined, + workers: isCI ? 1 : undefined, /* Reporter to use. See https://playwright.dev/docs/test-reporters */ reporter: 'html', /* 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://127.0.0.1:5050', + baseURL: baseUrl, /* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */ trace: 'on-first-retry', @@ -51,32 +48,17 @@ 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: 'npm run preview', - url: 'http://127.0.0.1:5050', - reuseExistingServer: !process.env.CI, - }, + + ...(isCI + ? {} + : { + webServer: { + command: 'npm run preview', + url: 'http://127.0.0.1:5050', + reuseExistingServer: true, + }, + }), });