From f41276c860433020f47a77a91dc39ad4c960df62 Mon Sep 17 00:00:00 2001 From: Peter Bacon Darwin Date: Fri, 13 Sep 2024 19:07:30 +0100 Subject: [PATCH] fix parallel e2e runs --- .github/workflows/playwright.yml | 12 ++++-------- examples/api/e2e-tests/base.spec.ts | 6 +++--- examples/api/package.json | 1 - examples/api/playwright.config.ts | 2 +- examples/create-next-app/e2e/base.spec.ts | 2 +- examples/create-next-app/e2e/playwright.config.ts | 4 ++-- examples/create-next-app/package.json | 3 +-- 7 files changed, 12 insertions(+), 18 deletions(-) diff --git a/.github/workflows/playwright.yml b/.github/workflows/playwright.yml index ce398a6..3c20c4f 100644 --- a/.github/workflows/playwright.yml +++ b/.github/workflows/playwright.yml @@ -17,11 +17,7 @@ jobs: run: npm install -g pnpm && pnpm install - name: Install Playwright browsers run: pnpm run install-playwright - - name: Run Playwright tests - run: pnpm run e2e - # - uses: actions/upload-artifact@v4 - # if: always() - # with: - # name: api-playwright-report - # path: next-apps/*/playwright-report/ - # retention-days: 30 + - name: Run playwright tests (api) + run: pnpm -F api run e2e + - name: Run playwright tests (create-next-app) + run: pnpm -F create-next-app run e2e diff --git a/examples/api/e2e-tests/base.spec.ts b/examples/api/e2e-tests/base.spec.ts index 8b78bc0..31d488f 100644 --- a/examples/api/e2e-tests/base.spec.ts +++ b/examples/api/e2e-tests/base.spec.ts @@ -3,14 +3,14 @@ import { test, expect } from "@playwright/test"; test("the application's noop index page is visible and it allows navigating to the hello-world api route", async ({ page, }) => { - await page.goto("http://localhost:8770/"); + await page.goto("/"); await expect(page.getByText("This application doesn't have")).toBeVisible(); await page.getByRole("link", { name: "/api/hello" }).click(); await expect(page.getByText("Hello World!")).toBeVisible(); }); test("the hello-world api route works as intended", async ({ page }) => { - const res = await fetch("http://localhost:8770/api/hello"); - expect(res.headers.get("content-type")).toContain("text/plain"); + const res = await page.request.get("/api/hello"); + expect(res.headers()["content-type"]).toContain("text/plain"); expect(await res.text()).toEqual("Hello World!"); }); diff --git a/examples/api/package.json b/examples/api/package.json index eb6fec0..a805484 100644 --- a/examples/api/package.json +++ b/examples/api/package.json @@ -10,7 +10,6 @@ "build:worker": "builder", "dev:worker": "wrangler dev --port 8770", "preview:worker": "pnpm build:worker && pnpm dev:worker", - "pree2e": "playwright install --with-deps", "e2e": "playwright test" }, "dependencies": { diff --git a/examples/api/playwright.config.ts b/examples/api/playwright.config.ts index 22099d1..3186acd 100644 --- a/examples/api/playwright.config.ts +++ b/examples/api/playwright.config.ts @@ -27,7 +27,7 @@ export default defineConfig({ /* 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:3000', + baseURL: "http://localhost:8770", /* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */ trace: "on-first-retry", diff --git a/examples/create-next-app/e2e/base.spec.ts b/examples/create-next-app/e2e/base.spec.ts index 53e4abe..e7d6428 100644 --- a/examples/create-next-app/e2e/base.spec.ts +++ b/examples/create-next-app/e2e/base.spec.ts @@ -3,6 +3,6 @@ import { test, expect } from "@playwright/test"; test("the index page of the application shows the Next.js logo", async ({ page, }) => { - await page.goto("http://localhost:8770/"); + await page.goto("/"); await expect(page.getByAltText("Next.js logo")).toBeVisible(); }); diff --git a/examples/create-next-app/e2e/playwright.config.ts b/examples/create-next-app/e2e/playwright.config.ts index e1912f8..e468608 100644 --- a/examples/create-next-app/e2e/playwright.config.ts +++ b/examples/create-next-app/e2e/playwright.config.ts @@ -27,7 +27,7 @@ export default defineConfig({ /* 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:3000', + baseURL: "http://localhost:8771", /* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */ trace: "on-first-retry", @@ -74,7 +74,7 @@ export default defineConfig({ /* Run your local dev server before starting the tests */ webServer: { command: "pnpm preview:worker", - url: "http://localhost:8770", + url: "http://localhost:8771", reuseExistingServer: !process.env.CI, }, }); diff --git a/examples/create-next-app/package.json b/examples/create-next-app/package.json index 7baafb5..e9dfbd6 100644 --- a/examples/create-next-app/package.json +++ b/examples/create-next-app/package.json @@ -8,9 +8,8 @@ "start": "next start", "lint": "next lint", "build:worker": "builder", - "dev:worker": "wrangler dev --port 8770", + "dev:worker": "wrangler dev --port 8771", "preview:worker": "pnpm build:worker && pnpm dev:worker", - "pree2e": "playwright install --with-deps", "e2e": "playwright test -c e2e/playwright.config.ts" }, "dependencies": {