diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 2fb6dacb..87728006 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -25,8 +25,8 @@ Any contributions you make will be via [Pull Requests](https://docs.github.com/e ```sh > git remote -v - origin https://github.com//opennextjs-cloudflare (fetch) - origin https://github.com//opennextjs-cloudflare (push) + origin https://github.com//opennextjs-cloudflare (fetch) + origin https://github.com//opennextjs-cloudflare (push) ``` - Add `opennextjs/opennextjs-cloudflare` as the `upstream` remote repository. @@ -34,10 +34,10 @@ Any contributions you make will be via [Pull Requests](https://docs.github.com/e ```sh > git remote add upstream https://github.com/opennextjs/opennextjs-cloudflare > git remote -v - origin https://github.com//opennextjs-cloudflare (fetch) - origin https://github.com//opennextjs-cloudflare (push) - upstream https://github.com/opennextjs/opennextjs-cloudflare (fetch) - upstream https://github.com/opennextjs/opennextjs-cloudflare (push) + origin https://github.com//opennextjs-cloudflare (fetch) + origin https://github.com//opennextjs-cloudflare (push) + upstream https://github.com/opennextjs/opennextjs-cloudflare (fetch) + upstream https://github.com/opennextjs/opennextjs-cloudflare (push) ``` - You should regularly pull from the `main` branch of the `upstream` repository to keep up to date with the latest changes to the project. @@ -82,13 +82,13 @@ pnpm --filter cloudflare build:watch Build and preview a Next.js sample application. For example, the `api` application: ```sh -pnpm --filter api preview:worker +pnpm --filter api preview ``` You can skip building the Next.js app when it has not been modified, and only run the Cloudflare adaptor tool: ```sh -SKIP_NEXT_APP_BUILD=true pnpm --filter api preview:worker +SKIP_NEXT_APP_BUILD=true pnpm --filter api preview ``` ## Checking the code @@ -102,7 +102,7 @@ pnpm run code:checks Attempt to auto-fix any issues with the format, lint and type checks: ```sh -pnpm run code:fixes +pnpm run fix ``` ## Testing the code @@ -117,6 +117,7 @@ Run all the e2e tests, via Playwright: ```sh pnpm run e2e +pnpm run e2e:dev ``` ## Changesets @@ -127,7 +128,7 @@ We use the [`changesets`](https://github.com/changesets/changesets/blob/main/REA - Create a changeset for the current change. ```sh - > pnpm changeset + pnpm changeset ``` - Select which workspaces are affected by the change and whether the version requires a major, minor or patch release. @@ -135,7 +136,7 @@ We use the [`changesets`](https://github.com/changesets/changesets/blob/main/REA - Include the generate changeset in the current commit. ```sh - > git add ./changeset/*.md + git add ./changeset/*.md ``` ### Changeset message format diff --git a/examples/api/e2e/playwright.config.ts b/examples/api/e2e/playwright.config.ts index 6ad3832f..2eba40fe 100644 --- a/examples/api/e2e/playwright.config.ts +++ b/examples/api/e2e/playwright.config.ts @@ -1,55 +1,3 @@ -import { defineConfig, devices } from "@playwright/test"; -import type nodeProcess from "node:process"; +import { configurePlaywright } from "../../common/config-e2e"; -declare const process: typeof nodeProcess; - -/** - * See https://playwright.dev/docs/test-configuration. - */ -export default defineConfig({ - testDir: "./", - /* Run tests in files in parallel */ - fullyParallel: true, - /* Fail the build on CI if you accidentally left test.only in the source code. */ - forbidOnly: !!process.env.CI, - /* Retry on CI only */ - retries: process.env.CI ? 2 : 0, - /* Opt out of parallel tests on CI. */ - workers: process.env.CI ? 1 : undefined, - /* Reporter to use. See https://playwright.dev/docs/test-reporters */ - reporter: "html", - /* 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://localhost:8770", - - /* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */ - trace: "on-first-retry", - }, - - /* Configure projects for major browsers */ - projects: [ - { - name: "chromium", - use: { ...devices["Desktop Chrome"] }, - }, - - { - name: "firefox", - use: { ...devices["Desktop Firefox"] }, - }, - - { - name: "webkit", - use: { ...devices["Desktop Safari"] }, - }, - ], - - /* Run your local dev server before starting the tests */ - webServer: { - command: "pnpm preview:worker", - url: "http://localhost:8770", - reuseExistingServer: !process.env.CI, - timeout: 500_000, - }, -}); +export default configurePlaywright("api", { isCI: !!process.env.CI }); diff --git a/examples/api/e2e/playwright.dev.config.ts b/examples/api/e2e/playwright.dev.config.ts index e1675b2f..5e263df0 100644 --- a/examples/api/e2e/playwright.dev.config.ts +++ b/examples/api/e2e/playwright.dev.config.ts @@ -1,55 +1,7 @@ -import { defineConfig, devices } from "@playwright/test"; -import type nodeProcess from "node:process"; +import { configurePlaywright } from "../../common/config-e2e"; -declare const process: typeof nodeProcess; - -/** - * See https://playwright.dev/docs/test-configuration. - */ -export default defineConfig({ - testDir: "./", - testIgnore: "cloudflare.spec.ts", - /* Run tests in files in parallel */ - fullyParallel: true, - /* Fail the build on CI if you accidentally left test.only in the source code. */ - forbidOnly: !!process.env.CI, - /* Retry on CI only */ - retries: process.env.CI ? 2 : 0, - /* Opt out of parallel tests on CI. */ - workers: process.env.CI ? 1 : undefined, - /* Reporter to use. See https://playwright.dev/docs/test-reporters */ - reporter: "html", - /* 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://localhost:3333", - - /* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */ - trace: "on-first-retry", - }, - - /* Configure projects for major browsers */ - projects: [ - { - name: "chromium", - use: { ...devices["Desktop Chrome"] }, - }, - - { - name: "firefox", - use: { ...devices["Desktop Firefox"] }, - }, - - { - name: "webkit", - use: { ...devices["Desktop Safari"] }, - }, - ], - - /* Run your local dev server before starting the tests */ - webServer: { - command: "pnpm dev --port 3333", - url: "http://localhost:3333", - reuseExistingServer: !process.env.CI, - }, +export default configurePlaywright("api", { + isCI: !!process.env.CI, + isWorker: false, + multipleBrowsers: false, }); diff --git a/examples/api/package.json b/examples/api/package.json index 43c4b05f..3f22a4d9 100644 --- a/examples/api/package.json +++ b/examples/api/package.json @@ -9,8 +9,7 @@ "start": "next start", "lint": "next lint", "build:worker": "pnpm opennextjs-cloudflare", - "dev:worker": "wrangler dev --port 8770 --inspector-port 9330", - "preview:worker": "pnpm build:worker && pnpm dev:worker", + "preview": "pnpm build:worker && pnpm wrangler dev", "e2e": "playwright test -c e2e/playwright.config.ts", "e2e:dev": "playwright test -c e2e/playwright.dev.config.ts", "cf-typegen": "wrangler types --env-interface CloudflareEnv" diff --git a/examples/bugs/gh-119/e2e/playwright.config.ts b/examples/bugs/gh-119/e2e/playwright.config.ts index a4699d1e..d2087263 100644 --- a/examples/bugs/gh-119/e2e/playwright.config.ts +++ b/examples/bugs/gh-119/e2e/playwright.config.ts @@ -1,45 +1,3 @@ -import { defineConfig, devices } from "@playwright/test"; -import type nodeProcess from "node:process"; +import { configurePlaywright } from "../../../common/config-e2e"; -declare const process: typeof nodeProcess; - -/** - * See https://playwright.dev/docs/test-configuration. - */ -export default defineConfig({ - testDir: "./", - /* Run tests in files in parallel */ - fullyParallel: true, - /* Fail the build on CI if you accidentally left test.only in the source code. */ - forbidOnly: !!process.env.CI, - /* Retry on CI only */ - retries: process.env.CI ? 2 : 0, - /* Opt out of parallel tests on CI. */ - workers: process.env.CI ? 1 : undefined, - /* Reporter to use. See https://playwright.dev/docs/test-reporters */ - reporter: "html", - /* 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://localhost:8750", - - /* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */ - trace: "on-first-retry", - }, - - /* Configure projects for major browsers */ - projects: [ - { - name: "chromium", - use: { ...devices["Desktop Chrome"] }, - }, - ], - - /* Run your local dev server before starting the tests */ - webServer: { - command: "pnpm preview", - url: "http://localhost:8750", - reuseExistingServer: !process.env.CI, - timeout: 500_000, - }, -}); +export default configurePlaywright("gh-119", { isCI: !!process.env.CI, multipleBrowsers: false }); diff --git a/examples/bugs/gh-119/package.json b/examples/bugs/gh-119/package.json index fa3059c5..d5ce0213 100644 --- a/examples/bugs/gh-119/package.json +++ b/examples/bugs/gh-119/package.json @@ -8,8 +8,7 @@ "start": "next start", "lint": "next lint", "build:worker": "pnpm opennextjs-cloudflare", - "dev:worker": "wrangler dev --port 8750 --inspector-port 9370", - "preview": "pnpm build:worker && pnpm dev:worker", + "preview": "pnpm build:worker && pnpm wrangler dev", "e2e": "playwright test -c e2e/playwright.config.ts", "cf-typegen": "wrangler types --env-interface CloudflareEnv" }, diff --git a/examples/bugs/gh-219/e2e/playwright.config.ts b/examples/bugs/gh-219/e2e/playwright.config.ts index bb51d83c..2d9161b7 100644 --- a/examples/bugs/gh-219/e2e/playwright.config.ts +++ b/examples/bugs/gh-219/e2e/playwright.config.ts @@ -1,45 +1,3 @@ -import { defineConfig, devices } from "@playwright/test"; -import type nodeProcess from "node:process"; +import { configurePlaywright } from "../../../common/config-e2e"; -declare const process: typeof nodeProcess; - -/** - * See https://playwright.dev/docs/test-configuration. - */ -export default defineConfig({ - testDir: "./", - /* Run tests in files in parallel */ - fullyParallel: true, - /* Fail the build on CI if you accidentally left test.only in the source code. */ - forbidOnly: !!process.env.CI, - /* Retry on CI only */ - retries: process.env.CI ? 2 : 0, - /* Opt out of parallel tests on CI. */ - workers: process.env.CI ? 1 : undefined, - /* Reporter to use. See https://playwright.dev/docs/test-reporters */ - reporter: "html", - /* 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://localhost:8751", - - /* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */ - trace: "on-first-retry", - }, - - /* Configure projects for major browsers */ - projects: [ - { - name: "chromium", - use: { ...devices["Desktop Chrome"] }, - }, - ], - - /* Run your local dev server before starting the tests */ - webServer: { - command: "pnpm preview", - url: "http://localhost:8751", - reuseExistingServer: !process.env.CI, - timeout: 500_000, - }, -}); +export default configurePlaywright("gh-219", { isCI: !!process.env.CI, multipleBrowsers: false }); diff --git a/examples/bugs/gh-219/package.json b/examples/bugs/gh-219/package.json index 8c9a6029..b1307eb7 100644 --- a/examples/bugs/gh-219/package.json +++ b/examples/bugs/gh-219/package.json @@ -8,8 +8,7 @@ "start": "next start", "lint": "next lint", "build:worker": "opennextjs-cloudflare", - "dev:worker": "wrangler dev --port 8751 --inspector-port 9371", - "preview": "npm run build:worker && npm run dev:worker", + "preview": "npm run build:worker && npx wrangler dev", "e2e": "playwright test -c e2e/playwright.config.ts", "deploy:worker": "npm run build:worker && wrangler deploy" }, diff --git a/examples/bugs/gh-223/e2e/playwright.config.ts b/examples/bugs/gh-223/e2e/playwright.config.ts index 38139f79..33181e3e 100644 --- a/examples/bugs/gh-223/e2e/playwright.config.ts +++ b/examples/bugs/gh-223/e2e/playwright.config.ts @@ -1,45 +1,3 @@ -import { defineConfig, devices } from "@playwright/test"; -import type nodeProcess from "node:process"; +import { configurePlaywright } from "../../../common/config-e2e"; -declare const process: typeof nodeProcess; - -/** - * See https://playwright.dev/docs/test-configuration. - */ -export default defineConfig({ - testDir: "./", - /* Run tests in files in parallel */ - fullyParallel: true, - /* Fail the build on CI if you accidentally left test.only in the source code. */ - forbidOnly: !!process.env.CI, - /* Retry on CI only */ - retries: process.env.CI ? 2 : 0, - /* Opt out of parallel tests on CI. */ - workers: process.env.CI ? 1 : undefined, - /* Reporter to use. See https://playwright.dev/docs/test-reporters */ - reporter: "html", - /* 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://localhost:8752", - - /* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */ - trace: "on-first-retry", - }, - - /* Configure projects for major browsers */ - projects: [ - { - name: "chromium", - use: { ...devices["Desktop Chrome"] }, - }, - ], - - /* Run your local dev server before starting the tests */ - webServer: { - command: "pnpm preview", - url: "http://localhost:8752", - reuseExistingServer: !process.env.CI, - timeout: 500_000, - }, -}); +export default configurePlaywright("gh-223", { isCI: !!process.env.CI, multipleBrowsers: false }); diff --git a/examples/bugs/gh-223/package.json b/examples/bugs/gh-223/package.json index 19c9f79a..4d3bd0b4 100644 --- a/examples/bugs/gh-223/package.json +++ b/examples/bugs/gh-223/package.json @@ -8,8 +8,7 @@ "start": "next start", "lint": "next lint", "build:worker": "opennextjs-cloudflare", - "dev:worker": "wrangler dev --port 8752 --inspector-port 9372", - "preview": "npm run build:worker && npm run dev:worker", + "preview": "npm run build:worker && npx wrangler dev", "e2e": "playwright test -c e2e/playwright.config.ts", "deploy:worker": "npm run build:worker && wrangler deploy" }, diff --git a/examples/common/apps.ts b/examples/common/apps.ts new file mode 100644 index 00000000..a9ed13d3 --- /dev/null +++ b/examples/common/apps.ts @@ -0,0 +1,44 @@ +// List of all e2e tested apps +const apps = [ + // examples + "api", + "create-next-app", + "middleware", + "vercel-blog-starter", + "vercel-commerce", + // e2e + "app-pages-router", + "app-router", + "pages-router", + // bugs + "gh-119", + "gh-219", + "gh-223", +] as const; + +export type AppName = (typeof apps)[number]; + +const BASE_WRANGLER_PORT = 8770; +const BASE_NEXT_PORT = 3100; + +/** + * Returns a distinct port for each application so they can run in parallel. + */ +export function getAppPort(app: AppName, { isWorker = true } = {}) { + const index = apps.indexOf(app); + if (index === -1) { + throw new Error(`Unknown app: ${app}`); + } + return isWorker ? BASE_WRANGLER_PORT + index : BASE_NEXT_PORT + index; +} + +/** + * Returns a distinct port for each application so they can run in parallel. + */ +export function getInspectorPort(app: AppName) { + const index = apps.indexOf(app); + if (index === -1) { + throw new Error(`Unknown app: ${app}`); + } + return 9300 + index; +} diff --git a/examples/common/config-e2e.ts b/examples/common/config-e2e.ts new file mode 100644 index 00000000..5347c5e6 --- /dev/null +++ b/examples/common/config-e2e.ts @@ -0,0 +1,90 @@ +import { defineConfig, devices } from "@playwright/test"; +import type nodeProcess from "node:process"; +import { getAppPort, getInspectorPort, type AppName } from "./apps"; + +declare const process: typeof nodeProcess; + +export function configurePlaywright( + app: AppName, + { + // Do we run on CI? + isCI = false, + // Do we run on workers (`wrangler dev`) or on Node (`next dev`) + isWorker = true, + // Tests with multiple browsers + multipleBrowsers = true, + } = {} +) { + const port = getAppPort(app, { isWorker }); + const inspectorPort = getInspectorPort(app); + const baseURL = `http://localhost:${port}`; + let command: string; + let timeout: number; + if (isWorker) { + if (isCI) { + // Do not build on CI - there is a preceding build step + command = `pnpm wrangler dev --port ${port} --inspector-port ${inspectorPort}`; + timeout = 100_000; + } else { + timeout = 500_000; + command = `pnpm preview --port ${port}`; + } + } else { + timeout = 100_000; + command = `pnpm dev --port ${port}`; + } + + const projects = [ + { + name: "chromium", + use: { ...devices["Desktop Chrome"] }, + }, + { + name: "firefox", + use: { ...devices["Desktop Firefox"] }, + }, + { + name: "webkit", + use: { ...devices["Desktop Safari"] }, + }, + ]; + if (!multipleBrowsers) { + projects.length = 1; + } + + /** + * See https://playwright.dev/docs/test-configuration. + */ + return defineConfig({ + testDir: "./", + /* ignore runtime specific tests */ + testIgnore: isWorker ? "*next.spec.ts" : "*cloudflare.spec.ts", + /* Run tests in files in parallel */ + fullyParallel: true, + /* Fail the build on CI if you accidentally left test.only in the source code. */ + forbidOnly: isCI, + /* Retry on CI only */ + retries: isCI ? 2 : 0, + /* Opt out of parallel tests on CI. */ + workers: isCI ? 1 : undefined, + /* Reporter to use. See https://playwright.dev/docs/test-reporters */ + reporter: "html", + /* 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, + /* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */ + trace: "on-first-retry", + }, + + projects, + + /* Run your local dev server before starting the tests */ + webServer: { + command, + url: baseURL, + reuseExistingServer: !isCI, + timeout, + }, + }); +} diff --git a/examples/common/package.json b/examples/common/package.json new file mode 100644 index 00000000..c8312cbb --- /dev/null +++ b/examples/common/package.json @@ -0,0 +1,5 @@ +{ + "name": "common", + "private": true, + "type": "module" +} diff --git a/examples/common/tsconfig.json b/examples/common/tsconfig.json new file mode 100644 index 00000000..87d34ab2 --- /dev/null +++ b/examples/common/tsconfig.json @@ -0,0 +1,15 @@ +{ + "compilerOptions": { + "lib": ["esnext"], + "allowJs": true, + "skipLibCheck": true, + "strict": false, + "noEmit": true, + "incremental": true, + "module": "esnext", + "esModuleInterop": true, + "moduleResolution": "node", + "resolveJsonModule": true, + "isolatedModules": true + } +} diff --git a/examples/create-next-app/e2e/playwright.config.ts b/examples/create-next-app/e2e/playwright.config.ts index b8de1868..d3779878 100644 --- a/examples/create-next-app/e2e/playwright.config.ts +++ b/examples/create-next-app/e2e/playwright.config.ts @@ -1,55 +1,3 @@ -import { defineConfig, devices } from "@playwright/test"; -import type nodeProcess from "node:process"; +import { configurePlaywright } from "../../common/config-e2e"; -declare const process: typeof nodeProcess; - -/** - * See https://playwright.dev/docs/test-configuration. - */ -export default defineConfig({ - testDir: "./", - /* Run tests in files in parallel */ - fullyParallel: true, - /* Fail the build on CI if you accidentally left test.only in the source code. */ - forbidOnly: !!process.env.CI, - /* Retry on CI only */ - retries: process.env.CI ? 2 : 0, - /* Opt out of parallel tests on CI. */ - workers: process.env.CI ? 1 : undefined, - /* Reporter to use. See https://playwright.dev/docs/test-reporters */ - reporter: "html", - /* 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://localhost:8771", - - /* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */ - trace: "on-first-retry", - }, - - /* Configure projects for major browsers */ - projects: [ - { - name: "chromium", - use: { ...devices["Desktop Chrome"] }, - }, - - { - name: "firefox", - use: { ...devices["Desktop Firefox"] }, - }, - - { - name: "webkit", - use: { ...devices["Desktop Safari"] }, - }, - ], - - /* Run your local dev server before starting the tests */ - webServer: { - command: "pnpm preview:worker", - url: "http://localhost:8771", - reuseExistingServer: !process.env.CI, - timeout: 500_000, - }, -}); +export default configurePlaywright("create-next-app", { isCI: !!process.env.CI }); diff --git a/examples/create-next-app/package.json b/examples/create-next-app/package.json index d8cea2b0..53062ea5 100644 --- a/examples/create-next-app/package.json +++ b/examples/create-next-app/package.json @@ -8,8 +8,7 @@ "start": "next start", "lint": "next lint", "build:worker": "opennextjs-cloudflare", - "dev:worker": "wrangler dev --port 8771 --inspector-port 9331", - "preview:worker": "pnpm build:worker && pnpm dev:worker", + "preview": "pnpm build:worker && pnpm wrangler dev", "e2e": "playwright test -c e2e/playwright.config.ts" }, "dependencies": { diff --git a/examples/e2e/app-pages-router/e2e/playwright.config.ts b/examples/e2e/app-pages-router/e2e/playwright.config.ts index 2e258e25..c2486dc8 100644 --- a/examples/e2e/app-pages-router/e2e/playwright.config.ts +++ b/examples/e2e/app-pages-router/e2e/playwright.config.ts @@ -1,54 +1,3 @@ -import { defineConfig, devices } from "@playwright/test"; -import type nodeProcess from "node:process"; +import { configurePlaywright } from "../../../common/config-e2e"; -declare const process: typeof nodeProcess; - -/** - * See https://playwright.dev/docs/test-configuration. - */ -export default defineConfig({ - testDir: "./", - /* Run tests in files in parallel */ - fullyParallel: true, - /* Fail the build on CI if you accidentally left test.only in the source code. */ - forbidOnly: !!process.env.CI, - /* Retry on CI only */ - retries: process.env.CI ? 2 : 0, - /* Opt out of parallel tests on CI. */ - workers: process.env.CI ? 1 : undefined, - /* Reporter to use. See https://playwright.dev/docs/test-reporters */ - reporter: "html", - /* 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://localhost:8792", - - /* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */ - trace: "on-first-retry", - }, - - /* Configure projects for major browsers */ - projects: [ - { - name: "chromium", - use: { ...devices["Desktop Chrome"] }, - }, - // TODO(vicb): enable all browsers - // { - // name: "firefox", - // use: { ...devices["Desktop Firefox"] }, - // }, - // { - // name: "webkit", - // use: { ...devices["Desktop Safari"] }, - // }, - ], - - /* Run your local dev server before starting the tests */ - webServer: { - command: "pnpm preview", - url: "http://localhost:8792", - reuseExistingServer: !process.env.CI, - timeout: 500_000, - }, -}); +export default configurePlaywright("app-pages-router", { isCI: !!process.env.CI, multipleBrowsers: false }); diff --git a/examples/e2e/app-pages-router/package.json b/examples/e2e/app-pages-router/package.json index 3b6c94f6..5e0eec36 100644 --- a/examples/e2e/app-pages-router/package.json +++ b/examples/e2e/app-pages-router/package.json @@ -10,8 +10,7 @@ "lint": "next lint", "clean": "rm -rf .turbo node_modules .next .open-next", "build:worker": "pnpm opennextjs-cloudflare", - "dev:worker": "wrangler dev --port 8792 --inspector-port 9352", - "preview": "pnpm build:worker && pnpm dev:worker", + "preview": "pnpm build:worker && pnpm wrangler dev", "e2e": "playwright test -c e2e/playwright.config.ts" }, "dependencies": { diff --git a/examples/e2e/app-router/e2e/playwright.config.ts b/examples/e2e/app-router/e2e/playwright.config.ts index 50ef7191..c3e8b9ff 100644 --- a/examples/e2e/app-router/e2e/playwright.config.ts +++ b/examples/e2e/app-router/e2e/playwright.config.ts @@ -1,54 +1,3 @@ -import { defineConfig, devices } from "@playwright/test"; -import type nodeProcess from "node:process"; +import { configurePlaywright } from "../../../common/config-e2e"; -declare const process: typeof nodeProcess; - -/** - * See https://playwright.dev/docs/test-configuration. - */ -export default defineConfig({ - testDir: "./", - /* Run tests in files in parallel */ - fullyParallel: true, - /* Fail the build on CI if you accidentally left test.only in the source code. */ - forbidOnly: !!process.env.CI, - /* Retry on CI only */ - retries: process.env.CI ? 2 : 0, - /* Opt out of parallel tests on CI. */ - workers: process.env.CI ? 1 : undefined, - /* Reporter to use. See https://playwright.dev/docs/test-reporters */ - reporter: "html", - /* 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://localhost:8790", - - /* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */ - trace: "on-first-retry", - }, - - /* Configure projects for major browsers */ - projects: [ - { - name: "chromium", - use: { ...devices["Desktop Chrome"] }, - }, - // TODO(vicb): enable all browsers - // { - // name: "firefox", - // use: { ...devices["Desktop Firefox"] }, - // }, - // { - // name: "webkit", - // use: { ...devices["Desktop Safari"] }, - // }, - ], - - /* Run your local dev server before starting the tests */ - webServer: { - command: "pnpm preview", - url: "http://localhost:8790", - reuseExistingServer: !process.env.CI, - timeout: 500_000, - }, -}); +export default configurePlaywright("app-router", { isCI: !!process.env.CI, multipleBrowsers: false }); diff --git a/examples/e2e/app-router/package.json b/examples/e2e/app-router/package.json index 15fd54f1..d6fa9adb 100644 --- a/examples/e2e/app-router/package.json +++ b/examples/e2e/app-router/package.json @@ -10,8 +10,7 @@ "lint": "next lint", "clean": "rm -rf .turbo node_modules .next .open-next", "build:worker": "pnpm opennextjs-cloudflare", - "dev:worker": "wrangler dev --port 8790 --inspector-port 9350", - "preview": "pnpm build:worker && pnpm dev:worker", + "preview": "pnpm build:worker && pnpm wrangler dev", "e2e": "playwright test -c e2e/playwright.config.ts" }, "dependencies": { diff --git a/examples/e2e/pages-router/e2e/playwright.config.ts b/examples/e2e/pages-router/e2e/playwright.config.ts index 365e1adc..b0444563 100644 --- a/examples/e2e/pages-router/e2e/playwright.config.ts +++ b/examples/e2e/pages-router/e2e/playwright.config.ts @@ -1,54 +1,3 @@ -import { defineConfig, devices } from "@playwright/test"; -import type nodeProcess from "node:process"; +import { configurePlaywright } from "../../../common/config-e2e"; -declare const process: typeof nodeProcess; - -/** - * See https://playwright.dev/docs/test-configuration. - */ -export default defineConfig({ - testDir: "./", - /* Run tests in files in parallel */ - fullyParallel: true, - /* Fail the build on CI if you accidentally left test.only in the source code. */ - forbidOnly: !!process.env.CI, - /* Retry on CI only */ - retries: process.env.CI ? 2 : 0, - /* Opt out of parallel tests on CI. */ - workers: process.env.CI ? 1 : undefined, - /* Reporter to use. See https://playwright.dev/docs/test-reporters */ - reporter: "html", - /* 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://localhost:8791", - - /* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */ - trace: "on-first-retry", - }, - - /* Configure projects for major browsers */ - projects: [ - { - name: "chromium", - use: { ...devices["Desktop Chrome"] }, - }, - // TODO(vicb): enable all browsers - // { - // name: "firefox", - // use: { ...devices["Desktop Firefox"] }, - // }, - // { - // name: "webkit", - // use: { ...devices["Desktop Safari"] }, - // }, - ], - - /* Run your local dev server before starting the tests */ - webServer: { - command: "pnpm preview", - url: "http://localhost:8791", - reuseExistingServer: !process.env.CI, - timeout: 500_000, - }, -}); +export default configurePlaywright("pages-router", { isCI: !!process.env.CI, multipleBrowsers: false }); diff --git a/examples/e2e/pages-router/package.json b/examples/e2e/pages-router/package.json index e1baea6f..cfcc5b9f 100644 --- a/examples/e2e/pages-router/package.json +++ b/examples/e2e/pages-router/package.json @@ -10,8 +10,7 @@ "lint": "next lint", "clean": "rm -rf .turbo node_modules .next .open-next", "build:worker": "pnpm opennextjs-cloudflare", - "dev:worker": "wrangler dev --port 8791 --inspector-port 9351", - "preview": "pnpm build:worker && pnpm dev:worker", + "preview": "pnpm build:worker && pnpm wrangler dev", "e2e": "playwright test -c e2e/playwright.config.ts" }, "dependencies": { diff --git a/examples/middleware/e2e/playwright.config.ts b/examples/middleware/e2e/playwright.config.ts index 7e4179db..f0676698 100644 --- a/examples/middleware/e2e/playwright.config.ts +++ b/examples/middleware/e2e/playwright.config.ts @@ -1,55 +1,3 @@ -import { defineConfig, devices } from "@playwright/test"; -import type nodeProcess from "node:process"; +import { configurePlaywright } from "../../common/config-e2e"; -declare const process: typeof nodeProcess; - -/** - * See https://playwright.dev/docs/test-configuration. - */ -export default defineConfig({ - testDir: "./", - /* Run tests in files in parallel */ - fullyParallel: true, - /* Fail the build on CI if you accidentally left test.only in the source code. */ - forbidOnly: !!process.env.CI, - /* Retry on CI only */ - retries: process.env.CI ? 2 : 0, - /* Opt out of parallel tests on CI. */ - workers: process.env.CI ? 1 : undefined, - /* Reporter to use. See https://playwright.dev/docs/test-reporters */ - reporter: "html", - /* 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://localhost:8774", - - /* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */ - trace: "on-first-retry", - }, - - /* Configure projects for major browsers */ - projects: [ - { - name: "chromium", - use: { ...devices["Desktop Chrome"] }, - }, - - { - name: "firefox", - use: { ...devices["Desktop Firefox"] }, - }, - - { - name: "webkit", - use: { ...devices["Desktop Safari"] }, - }, - ], - - /* Run your local dev server before starting the tests */ - webServer: { - command: "pnpm preview:worker", - url: "http://localhost:8774", - reuseExistingServer: !process.env.CI, - timeout: 500_000, - }, -}); +export default configurePlaywright("middleware", { isCI: !!process.env.CI }); diff --git a/examples/middleware/e2e/playwright.dev.config.ts b/examples/middleware/e2e/playwright.dev.config.ts index 6fabd3da..cabdc041 100644 --- a/examples/middleware/e2e/playwright.dev.config.ts +++ b/examples/middleware/e2e/playwright.dev.config.ts @@ -1,54 +1,7 @@ -import { defineConfig, devices } from "@playwright/test"; -import type nodeProcess from "node:process"; +import { configurePlaywright } from "../../common/config-e2e"; -declare const process: typeof nodeProcess; - -/** - * See https://playwright.dev/docs/test-configuration. - */ -export default defineConfig({ - testDir: "./", - /* Run tests in files in parallel */ - fullyParallel: true, - /* Fail the build on CI if you accidentally left test.only in the source code. */ - forbidOnly: !!process.env.CI, - /* Retry on CI only */ - retries: process.env.CI ? 2 : 0, - /* Opt out of parallel tests on CI. */ - workers: process.env.CI ? 1 : undefined, - /* Reporter to use. See https://playwright.dev/docs/test-reporters */ - reporter: "html", - /* 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://localhost:3334", - - /* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */ - trace: "on-first-retry", - }, - - /* Configure projects for major browsers */ - projects: [ - { - name: "chromium", - use: { ...devices["Desktop Chrome"] }, - }, - - { - name: "firefox", - use: { ...devices["Desktop Firefox"] }, - }, - - { - name: "webkit", - use: { ...devices["Desktop Safari"] }, - }, - ], - - /* Run your local dev server before starting the tests */ - webServer: { - command: "pnpm dev --port 3334", - url: "http://localhost:3334", - reuseExistingServer: !process.env.CI, - }, +export default configurePlaywright("middleware", { + isCI: !!process.env.CI, + isWorker: false, + multipleBrowsers: false, }); diff --git a/examples/middleware/package.json b/examples/middleware/package.json index 4b5dc8de..33e62aa8 100644 --- a/examples/middleware/package.json +++ b/examples/middleware/package.json @@ -7,8 +7,7 @@ "start": "next start", "lint": "next lint", "build:worker": "pnpm opennextjs-cloudflare", - "dev:worker": "wrangler dev --port 8774 --inspector-port 9334", - "preview:worker": "pnpm build:worker && pnpm dev:worker", + "preview": "pnpm build:worker && pnpm wrangler dev", "e2e": "playwright test -c e2e/playwright.config.ts", "e2e:dev": "playwright test -c e2e/playwright.dev.config.ts" }, diff --git a/examples/next-partial-prerendering/package.json b/examples/next-partial-prerendering/package.json index 2926ddbd..79582b0e 100644 --- a/examples/next-partial-prerendering/package.json +++ b/examples/next-partial-prerendering/package.json @@ -6,8 +6,7 @@ "dev": "next dev --turbo", "start": "next start", "build:worker": "opennextjs-cloudflare", - "dev:worker": "wrangler dev --port 8771 --inspector-port 9331", - "preview": "pnpm build:worker && pnpm dev:worker" + "preview": "pnpm build:worker && pnpm wrangler dev" }, "dependencies": { "@heroicons/react": "2.1.5", diff --git a/examples/vercel-blog-starter/package.json b/examples/vercel-blog-starter/package.json index df2baee6..7c9a4b8d 100644 --- a/examples/vercel-blog-starter/package.json +++ b/examples/vercel-blog-starter/package.json @@ -6,8 +6,7 @@ "build": "next build", "start": "next start", "build:worker": "opennextjs-cloudflare", - "dev:worker": "wrangler dev --port 8773", - "preview:worker": "pnpm build:worker && pnpm dev:worker" + "preview": "pnpm build:worker && pnpm wrangler dev" }, "dependencies": { "classnames": "^2.5.1", diff --git a/examples/vercel-commerce/package.json b/examples/vercel-commerce/package.json index f0368221..e50d63bc 100644 --- a/examples/vercel-commerce/package.json +++ b/examples/vercel-commerce/package.json @@ -13,8 +13,7 @@ "prettier:check": "prettier --check --ignore-unknown .", "test": "pnpm prettier:check", "tofix-build:worker": "opennextjs-cloudflare", - "tofix-dev:worker": "wrangler dev --port 8772", - "tofix-preview:worker": "pnpm build:worker && pnpm dev:worker" + "tofix-preview": "pnpm build:worker && pnpm wrangler dev" }, "dependencies": { "@headlessui/react": "^2.1.2", diff --git a/package.json b/package.json index 66c00555..02be93cd 100644 --- a/package.json +++ b/package.json @@ -9,20 +9,19 @@ "prettier": "3.3.3" }, "scripts": { + "fix": "pnpm prettier:fix && pnpm lint:fix", + "build": "pnpm --filter cloudflare build", + "test": "pnpm -r test", + "e2e": "pnpm build && pnpm -r e2e", + "e2e:dev": "pnpm build && pnpm -r e2e:dev", "prettier:check": "prettier --check .", "prettier:fix": "prettier --write .", "lint:check": "pnpm -r lint:check", "lint:fix": "pnpm -r lint:fix", - "fix": "pnpm prettier:fix && pnpm lint:fix", "ts:check": "pnpm -r ts:check", - "test": "pnpm -r test", "code:checks": "pnpm prettier:check && pnpm lint:check && pnpm ts:check", - "code:fixes": "pnpm prettier:fix && pnpm lint:fix", "install-playwright": "playwright install --with-deps", "postinstall": "pnpm --filter cloudflare build", - "build": "pnpm --filter cloudflare build", - "e2e": "pnpm build && pnpm -r e2e", - "e2e:dev": "pnpm build && pnpm -r e2e:dev", "benchmark": "pnpm run --filter benchmarking benchmark" } }