Skip to content

Commit

Permalink
ci: use bun sh to get playwright version for cross compat
Browse files Browse the repository at this point in the history
  • Loading branch information
ayuhito committed Aug 1, 2024
1 parent a2f90cf commit e204a51
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 46 deletions.
10 changes: 10 additions & 0 deletions .github/scripts/playwright-version.js
Original file line number Diff line number Diff line change
@@ -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]}`);
4 changes: 2 additions & 2 deletions .github/workflows/tracker-e2e.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions tracker/playwright.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
},
Expand Down
84 changes: 42 additions & 42 deletions tracker/tests/helpers/load.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
});
};

Expand Down

0 comments on commit e204a51

Please sign in to comment.