From e204a51b04a53082a7e4d91224420520786ed2eb Mon Sep 17 00:00:00 2001 From: Ayuhito Date: Thu, 1 Aug 2024 16:36:38 +0300 Subject: [PATCH] ci: use bun sh to get playwright version for cross compat --- .github/scripts/playwright-version.js | 10 ++++ .github/workflows/tracker-e2e.yml | 4 +- tracker/playwright.config.js | 4 +- tracker/tests/helpers/load.js | 84 +++++++++++++-------------- 4 files changed, 56 insertions(+), 46 deletions(-) create mode 100644 .github/scripts/playwright-version.js diff --git a/.github/scripts/playwright-version.js b/.github/scripts/playwright-version.js new file mode 100644 index 00000000..f6f217a3 --- /dev/null +++ b/.github/scripts/playwright-version.js @@ -0,0 +1,10 @@ +// @ts-check +import { $ } from 'bun'; + +const output = await $`npm ls @playwright/test`.text(); +const match = output.match(/@playwright\/test@(\S+)/); +if (!match) { + throw new Error('Could not find @playwright/test version'); +} + +console.log(`PLAYWRIGHT_VERSION=${match[1]}`); diff --git a/.github/workflows/tracker-e2e.yml b/.github/workflows/tracker-e2e.yml index 6ba3d9bd..da6b4002 100644 --- a/.github/workflows/tracker-e2e.yml +++ b/.github/workflows/tracker-e2e.yml @@ -13,6 +13,7 @@ jobs: playwright: timeout-minutes: 10 strategy: + fail-fast: false matrix: os: [ubuntu-latest, windows-latest, macos-latest] runs-on: ${{ matrix.os }} @@ -25,8 +26,7 @@ jobs: token: ${{ secrets.GITHUB_TOKEN }} - name: Get Playwright version - run: echo "PLAYWRIGHT_VERSION=$(npm ls @playwright/test | grep @playwright | sed 's/.*@//')" >> $GITHUB_ENV - working-directory: "./tracker" + run: bun ./github/scripts/playwright-version.js >> $GITHUB_ENV - name: Cache Playwright Browsers id: cache-playwright-browsers diff --git a/tracker/playwright.config.js b/tracker/playwright.config.js index fd04eb10..8ecd4e70 100644 --- a/tracker/playwright.config.js +++ b/tracker/playwright.config.js @@ -71,14 +71,14 @@ module.exports = defineConfig({ webServer: [ { command: 'bun run e2e:serve', - url: 'http://localhost:3000', + port: 3000, reuseExistingServer: !process.env.CI, timeout: 2500, }, { command: 'task start -- start -logger=pretty -level=warn -corsorigins=http://localhost:8080,http://localhost:3000', - url: 'http://localhost:8080', + port: 8080, reuseExistingServer: !process.env.CI, cwd: '../core', }, diff --git a/tracker/tests/helpers/load.js b/tracker/tests/helpers/load.js index 6c0ef7e7..bb48b13d 100644 --- a/tracker/tests/helpers/load.js +++ b/tracker/tests/helpers/load.js @@ -44,55 +44,55 @@ const loadTests = (name) => { await matchRequests(listeners, expectedRequests); }); - }); - test('returning visitor second load event', async ({ page }) => { - const expectedRequests = [ - { - method: 'POST', - url: '/api/event/hit', - status: 204, - postData: { - e: 'unload', + test('returning visitor second load event', async ({ page }) => { + const expectedRequests = [ + { + method: 'POST', + url: '/api/event/hit', + status: 204, + postData: { + e: 'unload', + }, + }, + { + method: 'GET', + url: '/api/event/ping', + status: 200, + responseBody: '1', + }, + { + method: 'GET', + url: '/api/event/ping', + status: 200, + responseBody: '1', }, - }, - { - method: 'GET', - url: '/api/event/ping', - status: 200, - responseBody: '1', - }, - { - method: 'GET', - url: '/api/event/ping', - status: 200, - responseBody: '1', - }, - { - method: 'POST', - url: '/api/event/hit', - status: 204, - postData: { - e: 'load', - u: createURL(name, 'index.html', false), - r: '', - p: false, // Returning visitor - q: false, // Not a new page view + { + method: 'POST', + url: '/api/event/hit', + status: 204, + postData: { + e: 'load', + u: createURL(name, 'index.html', false), + r: '', + p: false, // Returning visitor + q: false, // Not a new page view + }, }, - }, - ]; + ]; - // First load, should be a new visitor - await page.goto(createURL(name, 'index.html'), { - waitUntil: 'networkidle', - }); + // First load, should be a new visitor + await page.goto(createURL(name, 'index.html'), { + waitUntil: 'networkidle', + }); - const listeners = addRequestListeners(page, expectedRequests); + const listeners = addRequestListeners(page, expectedRequests); - // Refresh page for second load - await page.reload({ waitUntil: 'networkidle' }); + // Refresh page for second load + await page.reload({ waitUntil: 'networkidle' }); - await matchRequests(listeners, expectedRequests); + await matchRequests(listeners, expectedRequests); + }); }); };