Skip to content

Commit 5b2c9fb

Browse files
feat(test): replace cloudflare open-next build test with playwright tests (#7782)
* feat(test): replace cloudflare open-next build test with playwright tests * fixup! feat(test): replace cloudflare open-next build test with playwright tests simplify logic as suggested * fixup! feat(test): replace cloudflare open-next build test with playwright tests update forgotten env variable name in playwright.yml * fixup! feat(test): replace cloudflare open-next build test with playwright tests still accept VERCEL_PREVIEW_URL to make PR go green * fixup! feat(test): replace cloudflare open-next build test with playwright tests remove VERCEL_PREVIEW_URL * fixup! feat(test): replace cloudflare open-next build test with playwright tests avoid running a script taken from process.env * fixup! feat(test): replace cloudflare open-next build test with playwright tests add new getWebServerConfig function instead of using a ternary * assert that the cloudflare:preview script is defined
1 parent df203d0 commit 5b2c9fb

File tree

3 files changed

+59
-19
lines changed

3 files changed

+59
-19
lines changed

.github/workflows/cloudflare-open-next-build.yml renamed to .github/workflows/playwright-cloudflare-open-next.yml

Lines changed: 35 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
# REVIEWERS, please always double-check security practices before merging a PR that contains Workflow changes!!
55
# AUTHORS, please only use actions with explicit SHA references, and avoid using `@master` or `@main` references or `@version` tags.
66

7-
name: Cloudflare OpenNext Build
7+
name: Playwright Tests on Cloudflare Open-Next
88

99
on:
1010
push:
@@ -14,24 +14,17 @@ on:
1414
branches:
1515
- main
1616

17-
defaults:
18-
run:
19-
# This ensures that the working directory is the root of the repository
20-
working-directory: ./
17+
concurrency:
18+
group: ${{ github.workflow }}-${{ github.ref }}
19+
cancel-in-progress: true
2120

2221
permissions:
2322
contents: read
2423
actions: read
2524

26-
env:
27-
# See https://turbo.build/repo/docs/reference/command-line-reference/run#--cache-dir
28-
TURBO_ARGS: --cache-dir=.turbo/cache
29-
# See https://turbo.build/repo/docs/reference/command-line-reference/run#--force
30-
TURBO_FORCE: true
31-
3225
jobs:
33-
build-cloudflare-worker:
34-
name: Build Cloudflare Worker
26+
playwright:
27+
name: Playwright Tests
3528
runs-on: ubuntu-latest
3629

3730
steps:
@@ -58,5 +51,32 @@ jobs:
5851
- name: Install packages
5952
run: pnpm install --frozen-lockfile
6053

61-
- name: Build Cloudflare Worker
62-
run: pnpm exec turbo run cloudflare:build:worker ${{ env.TURBO_ARGS }}
54+
- name: Get Playwright version
55+
id: playwright-version
56+
working-directory: apps/site
57+
run: echo "version=$(pnpm exec playwright --version | awk '{print $2}')" >> $GITHUB_OUTPUT
58+
59+
- name: Cache Playwright browsers
60+
id: playwright-cache
61+
uses: actions/cache@5a3ec84eff668545956fd18022155c47e93e2684 # v4.2.3
62+
with:
63+
path: ~/.cache/ms-playwright
64+
key: playwright-${{ runner.os }}-${{ steps.playwright-version.outputs.version }}
65+
66+
- name: Install Playwright Browsers
67+
working-directory: apps/site
68+
run: pnpm exec playwright install --with-deps
69+
70+
- name: Run Playwright tests
71+
working-directory: apps/site
72+
run: pnpm playwright
73+
env:
74+
PLAYWRIGHT_RUN_CLOUDFLARE_PREVIEW: true
75+
PLAYWRIGHT_BASE_URL: http://127.0.0.1:8787
76+
77+
- name: Upload Playwright test results
78+
if: always()
79+
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
80+
with:
81+
name: playwright-report
82+
path: apps/site/playwright-report/

.github/workflows/playwright.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ jobs:
9797
working-directory: apps/site
9898
run: pnpm playwright
9999
env:
100-
VERCEL_PREVIEW_URL: ${{ needs.get-vercel-preview.outputs.url }}
100+
PLAYWRIGHT_BASE_URL: ${{ needs.get-vercel-preview.outputs.url }}
101101

102102
- name: Upload Playwright test results
103103
if: always()

apps/site/playwright.config.ts

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
import { defineConfig, devices } from '@playwright/test';
1+
import { defineConfig, devices, type Config } from '@playwright/test';
2+
3+
import json from './package.json' with { type: 'json' };
24

35
const isCI = !!process.env.CI;
46

@@ -10,11 +12,11 @@ export default defineConfig({
1012
retries: isCI ? 2 : 0,
1113
workers: isCI ? 1 : undefined,
1214
reporter: isCI ? [['html'], ['github']] : [['html']],
15+
...getWebServerConfig(),
1316
use: {
14-
baseURL: process.env.VERCEL_PREVIEW_URL || 'http://127.0.0.1:3000',
17+
baseURL: process.env.PLAYWRIGHT_BASE_URL || 'http://127.0.0.1:3000',
1518
trace: 'on-first-retry',
1619
},
17-
1820
projects: [
1921
{
2022
name: 'chromium',
@@ -30,3 +32,21 @@ export default defineConfig({
3032
},
3133
],
3234
});
35+
36+
function getWebServerConfig(): Pick<Config, 'webServer'> {
37+
if (!json.scripts['cloudflare:preview']) {
38+
throw new Error('cloudflare:preview script not defined');
39+
}
40+
41+
if (process.env.PLAYWRIGHT_RUN_CLOUDFLARE_PREVIEW) {
42+
return {
43+
webServer: {
44+
command: 'pnpm turbo run cloudflare:preview',
45+
url: process.env.PLAYWRIGHT_BASE_URL || 'http://127.0.0.1:3000',
46+
timeout: 60_000 * 3,
47+
},
48+
};
49+
}
50+
51+
return {};
52+
}

0 commit comments

Comments
 (0)