From 560a62d6490e9d592dbb6a5e2378173af870591f Mon Sep 17 00:00:00 2001 From: Dario Piotrowicz Date: Tue, 27 May 2025 13:33:24 +0100 Subject: [PATCH 1/8] feat(test): replace cloudflare open-next build test with playwright tests --- ...ml => playwright-cloudflare-open-next.yml} | 50 +++++++++++++------ apps/site/playwright.config.ts | 32 ++++++++++-- 2 files changed, 63 insertions(+), 19 deletions(-) rename .github/workflows/{cloudflare-open-next-build.yml => playwright-cloudflare-open-next.yml} (53%) diff --git a/.github/workflows/cloudflare-open-next-build.yml b/.github/workflows/playwright-cloudflare-open-next.yml similarity index 53% rename from .github/workflows/cloudflare-open-next-build.yml rename to .github/workflows/playwright-cloudflare-open-next.yml index 67df12fd7103c..8e911598f9482 100644 --- a/.github/workflows/cloudflare-open-next-build.yml +++ b/.github/workflows/playwright-cloudflare-open-next.yml @@ -4,7 +4,7 @@ # REVIEWERS, please always double-check security practices before merging a PR that contains Workflow changes!! # AUTHORS, please only use actions with explicit SHA references, and avoid using `@master` or `@main` references or `@version` tags. -name: Cloudflare OpenNext Build +name: Playwright Tests on Cloudflare Open-Next on: push: @@ -14,24 +14,17 @@ on: branches: - main -defaults: - run: - # This ensures that the working directory is the root of the repository - working-directory: ./ +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true permissions: contents: read actions: read -env: - # See https://turbo.build/repo/docs/reference/command-line-reference/run#--cache-dir - TURBO_ARGS: --cache-dir=.turbo/cache - # See https://turbo.build/repo/docs/reference/command-line-reference/run#--force - TURBO_FORCE: true - jobs: - build-cloudflare-worker: - name: Build Cloudflare Worker + playwright: + name: Playwright Tests runs-on: ubuntu-latest steps: @@ -58,5 +51,32 @@ jobs: - name: Install packages run: pnpm install --frozen-lockfile - - name: Build Cloudflare Worker - run: pnpm exec turbo run cloudflare:build:worker ${{ env.TURBO_ARGS }} + - name: Get Playwright version + id: playwright-version + working-directory: apps/site + run: echo "version=$(pnpm exec playwright --version | awk '{print $2}')" >> $GITHUB_OUTPUT + + - name: Cache Playwright browsers + id: playwright-cache + uses: actions/cache@5a3ec84eff668545956fd18022155c47e93e2684 # v4.2.3 + with: + path: ~/.cache/ms-playwright + key: playwright-${{ runner.os }}-${{ steps.playwright-version.outputs.version }} + + - name: Install Playwright Browsers + working-directory: apps/site + run: pnpm exec playwright install --with-deps + + - name: Run Playwright tests + working-directory: apps/site + run: pnpm playwright + env: + PLAYWRIGHT_WEB_SERVER_COMMAND: pnpm turbo run cloudflare:preview + PLAYWRIGHT_WEB_SERVER_PORT: 8787 + + - name: Upload Playwright test results + if: always() + uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2 + with: + name: playwright-report + path: apps/site/playwright-report/ diff --git a/apps/site/playwright.config.ts b/apps/site/playwright.config.ts index da8afcedde794..bbd056332c2ef 100644 --- a/apps/site/playwright.config.ts +++ b/apps/site/playwright.config.ts @@ -1,4 +1,5 @@ import { defineConfig, devices } from '@playwright/test'; +import type { PlaywrightTestConfig } from '@playwright/test'; const isCI = !!process.env.CI; @@ -10,11 +11,34 @@ export default defineConfig({ retries: isCI ? 2 : 0, workers: isCI ? 1 : undefined, reporter: isCI ? [['html'], ['github']] : [['html']], - use: { - baseURL: process.env.VERCEL_PREVIEW_URL || 'http://127.0.0.1:3000', - trace: 'on-first-retry', - }, + ...(() => { + const use: PlaywrightTestConfig['use'] = { + baseURL: process.env.PLAYWRIGHT_BASE_URL || 'http://127.0.0.1:3000', + trace: 'on-first-retry', + }; + const webServerCommand = process.env.PLAYWRIGHT_WEB_SERVER_COMMAND; + const webServerPort = parseInt( + process.env.PLAYWRIGHT_WEB_SERVER_PORT ?? '' + ); + if (webServerCommand && !isNaN(webServerPort)) { + use.baseURL = `http://127.0.0.1:${webServerPort}`; + return { + webServer: { + command: webServerCommand, + port: webServerPort, + stdout: 'pipe', + stderr: 'pipe', + timeout: 60_000 * 3, + }, + use, + }; + } + + return { + use, + }; + })(), projects: [ { name: 'chromium', From 0f84544f1b6dfbe790f70ff7c4d865a17d6aa5c7 Mon Sep 17 00:00:00 2001 From: Dario Piotrowicz Date: Tue, 27 May 2025 19:46:37 +0100 Subject: [PATCH 2/8] fixup! feat(test): replace cloudflare open-next build test with playwright tests simplify logic as suggested --- .../playwright-cloudflare-open-next.yml | 2 +- apps/site/playwright.config.ts | 36 ++++++------------- 2 files changed, 11 insertions(+), 27 deletions(-) diff --git a/.github/workflows/playwright-cloudflare-open-next.yml b/.github/workflows/playwright-cloudflare-open-next.yml index 8e911598f9482..9da96a703136e 100644 --- a/.github/workflows/playwright-cloudflare-open-next.yml +++ b/.github/workflows/playwright-cloudflare-open-next.yml @@ -72,7 +72,7 @@ jobs: run: pnpm playwright env: PLAYWRIGHT_WEB_SERVER_COMMAND: pnpm turbo run cloudflare:preview - PLAYWRIGHT_WEB_SERVER_PORT: 8787 + PLAYWRIGHT_BASE_URL: http://127.0.0.1:8787 - name: Upload Playwright test results if: always() diff --git a/apps/site/playwright.config.ts b/apps/site/playwright.config.ts index bbd056332c2ef..3c7802d22d175 100644 --- a/apps/site/playwright.config.ts +++ b/apps/site/playwright.config.ts @@ -1,5 +1,4 @@ import { defineConfig, devices } from '@playwright/test'; -import type { PlaywrightTestConfig } from '@playwright/test'; const isCI = !!process.env.CI; @@ -11,34 +10,19 @@ export default defineConfig({ retries: isCI ? 2 : 0, workers: isCI ? 1 : undefined, reporter: isCI ? [['html'], ['github']] : [['html']], - ...(() => { - const use: PlaywrightTestConfig['use'] = { - baseURL: process.env.PLAYWRIGHT_BASE_URL || 'http://127.0.0.1:3000', - trace: 'on-first-retry', - }; - - const webServerCommand = process.env.PLAYWRIGHT_WEB_SERVER_COMMAND; - const webServerPort = parseInt( - process.env.PLAYWRIGHT_WEB_SERVER_PORT ?? '' - ); - if (webServerCommand && !isNaN(webServerPort)) { - use.baseURL = `http://127.0.0.1:${webServerPort}`; - return { + ...(process.env.PLAYWRIGHT_WEB_SERVER_COMMAND + ? { webServer: { - command: webServerCommand, - port: webServerPort, - stdout: 'pipe', - stderr: 'pipe', + command: process.env.PLAYWRIGHT_WEB_SERVER_COMMAND, + url: process.env.PLAYWRIGHT_BASE_URL || 'http://127.0.0.1:3000', timeout: 60_000 * 3, }, - use, - }; - } - - return { - use, - }; - })(), + } + : {}), + use: { + baseURL: process.env.PLAYWRIGHT_BASE_URL || 'http://127.0.0.1:3000', + trace: 'on-first-retry', + }, projects: [ { name: 'chromium', From 1403dde329d37677b46d2dcb40319dfb6bbbc123 Mon Sep 17 00:00:00 2001 From: Dario Piotrowicz Date: Tue, 27 May 2025 19:48:48 +0100 Subject: [PATCH 3/8] fixup! feat(test): replace cloudflare open-next build test with playwright tests update forgotten env variable name in playwright.yml --- .github/workflows/playwright.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/playwright.yml b/.github/workflows/playwright.yml index bbc1cb3353d53..c7bb1bd13be8a 100644 --- a/.github/workflows/playwright.yml +++ b/.github/workflows/playwright.yml @@ -97,7 +97,7 @@ jobs: working-directory: apps/site run: pnpm playwright env: - VERCEL_PREVIEW_URL: ${{ needs.get-vercel-preview.outputs.url }} + PLAYWRIGHT_BASE_URL: ${{ needs.get-vercel-preview.outputs.url }} - name: Upload Playwright test results if: always() From 81b0bdeffd2a86d80408354c4ea0cd0d5d79906e Mon Sep 17 00:00:00 2001 From: Dario Piotrowicz Date: Tue, 27 May 2025 19:49:15 +0100 Subject: [PATCH 4/8] fixup! feat(test): replace cloudflare open-next build test with playwright tests still accept VERCEL_PREVIEW_URL to make PR go green --- apps/site/playwright.config.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/apps/site/playwright.config.ts b/apps/site/playwright.config.ts index 3c7802d22d175..424ab9b9b04d1 100644 --- a/apps/site/playwright.config.ts +++ b/apps/site/playwright.config.ts @@ -14,7 +14,12 @@ export default defineConfig({ ? { webServer: { command: process.env.PLAYWRIGHT_WEB_SERVER_COMMAND, - url: process.env.PLAYWRIGHT_BASE_URL || 'http://127.0.0.1:3000', + url: + // TODO: remove the VERCEL_PREVIEW_URL option once + // https://github.com/nodejs/nodejs.org/pull/7782 is merged + process.env.VERCEL_PREVIEW_URL || + process.env.PLAYWRIGHT_BASE_URL || + 'http://127.0.0.1:3000', timeout: 60_000 * 3, }, } From 7a128dd3be274003dc98ec0147535573eab6ff52 Mon Sep 17 00:00:00 2001 From: Dario Piotrowicz Date: Tue, 27 May 2025 22:33:36 +0100 Subject: [PATCH 5/8] fixup! feat(test): replace cloudflare open-next build test with playwright tests remove VERCEL_PREVIEW_URL --- apps/site/playwright.config.ts | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/apps/site/playwright.config.ts b/apps/site/playwright.config.ts index 424ab9b9b04d1..3c7802d22d175 100644 --- a/apps/site/playwright.config.ts +++ b/apps/site/playwright.config.ts @@ -14,12 +14,7 @@ export default defineConfig({ ? { webServer: { command: process.env.PLAYWRIGHT_WEB_SERVER_COMMAND, - url: - // TODO: remove the VERCEL_PREVIEW_URL option once - // https://github.com/nodejs/nodejs.org/pull/7782 is merged - process.env.VERCEL_PREVIEW_URL || - process.env.PLAYWRIGHT_BASE_URL || - 'http://127.0.0.1:3000', + url: process.env.PLAYWRIGHT_BASE_URL || 'http://127.0.0.1:3000', timeout: 60_000 * 3, }, } From 40eb3e189570b6a4606a8b16d19073fef3b7408d Mon Sep 17 00:00:00 2001 From: Dario Piotrowicz Date: Fri, 30 May 2025 19:29:35 +0100 Subject: [PATCH 6/8] fixup! feat(test): replace cloudflare open-next build test with playwright tests avoid running a script taken from process.env --- .github/workflows/playwright-cloudflare-open-next.yml | 2 +- apps/site/playwright.config.ts | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/playwright-cloudflare-open-next.yml b/.github/workflows/playwright-cloudflare-open-next.yml index 9da96a703136e..4c8ebb70659c0 100644 --- a/.github/workflows/playwright-cloudflare-open-next.yml +++ b/.github/workflows/playwright-cloudflare-open-next.yml @@ -71,7 +71,7 @@ jobs: working-directory: apps/site run: pnpm playwright env: - PLAYWRIGHT_WEB_SERVER_COMMAND: pnpm turbo run cloudflare:preview + PLAYWRIGHT_RUN_CLOUDFLARE_PREVIEW: true PLAYWRIGHT_BASE_URL: http://127.0.0.1:8787 - name: Upload Playwright test results diff --git a/apps/site/playwright.config.ts b/apps/site/playwright.config.ts index 3c7802d22d175..efa0b7d4d78ce 100644 --- a/apps/site/playwright.config.ts +++ b/apps/site/playwright.config.ts @@ -10,10 +10,10 @@ export default defineConfig({ retries: isCI ? 2 : 0, workers: isCI ? 1 : undefined, reporter: isCI ? [['html'], ['github']] : [['html']], - ...(process.env.PLAYWRIGHT_WEB_SERVER_COMMAND + ...(process.env.PLAYWRIGHT_RUN_CLOUDFLARE_PREVIEW ? { webServer: { - command: process.env.PLAYWRIGHT_WEB_SERVER_COMMAND, + command: 'pnpm turbo run cloudflare:preview', url: process.env.PLAYWRIGHT_BASE_URL || 'http://127.0.0.1:3000', timeout: 60_000 * 3, }, From 0b0cb33ee92b00fb08aa5e73c738e6962ad518e6 Mon Sep 17 00:00:00 2001 From: Dario Piotrowicz Date: Fri, 30 May 2025 19:35:45 +0100 Subject: [PATCH 7/8] fixup! feat(test): replace cloudflare open-next build test with playwright tests add new getWebServerConfig function instead of using a ternary --- apps/site/playwright.config.ts | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/apps/site/playwright.config.ts b/apps/site/playwright.config.ts index efa0b7d4d78ce..2f359df572ce1 100644 --- a/apps/site/playwright.config.ts +++ b/apps/site/playwright.config.ts @@ -1,4 +1,4 @@ -import { defineConfig, devices } from '@playwright/test'; +import { defineConfig, devices, type Config } from '@playwright/test'; const isCI = !!process.env.CI; @@ -10,15 +10,7 @@ export default defineConfig({ retries: isCI ? 2 : 0, workers: isCI ? 1 : undefined, reporter: isCI ? [['html'], ['github']] : [['html']], - ...(process.env.PLAYWRIGHT_RUN_CLOUDFLARE_PREVIEW - ? { - webServer: { - command: 'pnpm turbo run cloudflare:preview', - url: process.env.PLAYWRIGHT_BASE_URL || 'http://127.0.0.1:3000', - timeout: 60_000 * 3, - }, - } - : {}), + ...getWebServerConfig(), use: { baseURL: process.env.PLAYWRIGHT_BASE_URL || 'http://127.0.0.1:3000', trace: 'on-first-retry', @@ -38,3 +30,17 @@ export default defineConfig({ }, ], }); + +function getWebServerConfig(): Pick { + if (process.env.PLAYWRIGHT_RUN_CLOUDFLARE_PREVIEW) { + return { + webServer: { + command: 'pnpm turbo run cloudflare:preview', + url: process.env.PLAYWRIGHT_BASE_URL || 'http://127.0.0.1:3000', + timeout: 60_000 * 3, + }, + }; + } + + return {}; +} From daeddefd5db38a92e4ef636f46be3ec2fa737c55 Mon Sep 17 00:00:00 2001 From: Dario Piotrowicz Date: Fri, 30 May 2025 21:48:09 +0100 Subject: [PATCH 8/8] assert that the cloudflare:preview script is defined --- apps/site/playwright.config.ts | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/apps/site/playwright.config.ts b/apps/site/playwright.config.ts index 2f359df572ce1..fa3790f8d58cb 100644 --- a/apps/site/playwright.config.ts +++ b/apps/site/playwright.config.ts @@ -1,5 +1,7 @@ import { defineConfig, devices, type Config } from '@playwright/test'; +import json from './package.json' with { type: 'json' }; + const isCI = !!process.env.CI; // https://playwright.dev/docs/test-configuration @@ -32,6 +34,10 @@ export default defineConfig({ }); function getWebServerConfig(): Pick { + if (!json.scripts['cloudflare:preview']) { + throw new Error('cloudflare:preview script not defined'); + } + if (process.env.PLAYWRIGHT_RUN_CLOUDFLARE_PREVIEW) { return { webServer: {