From c9fcf8b8738af7ab064d8fe083c6cea1790d26df Mon Sep 17 00:00:00 2001 From: JPeer264 Date: Thu, 8 Oct 2026 10:57:21 +0200 Subject: [PATCH] test(nextjs): Run nextjs-16-tunnel on Cloudflare nextjs-16-tunnel gets an optional Cloudflare variant that builds with `opennextjs-cloudflare` and wraps the Worker in `worker.ts` with `withSentry` from `@sentry/nextjs/cloudflare`. The tunnel route tests then also run on Workers. The Worker sends its spans to the proxy server through `tunnel`, so the check that tunnel requests create no middleware spans sees the spans of the Worker. Without the tunnel route handling of `withSentry`, a tunnel request is sampled and this check fails. Co-Authored-By: Claude Opus 5.5 --- .../nextjs-16-tunnel/open-next.config.ts | 3 +++ .../nextjs-16-tunnel/package.json | 18 +++++++++++++++--- .../nextjs-16-tunnel/playwright.config.mjs | 4 ++-- .../nextjs-16-tunnel/worker.ts | 14 ++++++++++++++ .../nextjs-16-tunnel/wrangler.jsonc | 11 +++++++++++ 5 files changed, 45 insertions(+), 5 deletions(-) create mode 100644 dev-packages/e2e-tests/test-applications/nextjs-16-tunnel/open-next.config.ts create mode 100644 dev-packages/e2e-tests/test-applications/nextjs-16-tunnel/worker.ts create mode 100644 dev-packages/e2e-tests/test-applications/nextjs-16-tunnel/wrangler.jsonc diff --git a/dev-packages/e2e-tests/test-applications/nextjs-16-tunnel/open-next.config.ts b/dev-packages/e2e-tests/test-applications/nextjs-16-tunnel/open-next.config.ts new file mode 100644 index 000000000000..7a3d17172639 --- /dev/null +++ b/dev-packages/e2e-tests/test-applications/nextjs-16-tunnel/open-next.config.ts @@ -0,0 +1,3 @@ +import { defineCloudflareConfig } from '@opennextjs/cloudflare'; + +export default defineCloudflareConfig(); diff --git a/dev-packages/e2e-tests/test-applications/nextjs-16-tunnel/package.json b/dev-packages/e2e-tests/test-applications/nextjs-16-tunnel/package.json index cf2556fbff27..4c395455e9a2 100644 --- a/dev-packages/e2e-tests/test-applications/nextjs-16-tunnel/package.json +++ b/dev-packages/e2e-tests/test-applications/nextjs-16-tunnel/package.json @@ -20,11 +20,14 @@ "test:build-latest-webpack": "pnpm install && pnpm add next@latest && pnpm build-webpack", "test:build-canary-webpack": "pnpm install && pnpm add next@canary && pnpm build-webpack", "test:assert": "pnpm test:prod && pnpm test:dev", - "test:assert-webpack": "pnpm test:prod && pnpm test:dev-webpack" + "test:assert-webpack": "pnpm test:prod && pnpm test:dev-webpack", + "test:build:cloudflare": "pnpm install && _SENTRY_TUNNEL_DESTINATION_OVERRIDE=http://localhost:3031/ opennextjs-cloudflare build", + "start:cloudflare": "opennextjs-cloudflare preview" }, "dependencies": { - "@sentry/nextjs": "file:../../packed/sentry-nextjs-packed.tgz", + "@opennextjs/cloudflare": "^1.14.9", "@sentry/core": "file:../../packed/sentry-core-packed.tgz", + "@sentry/nextjs": "file:../../packed/sentry-nextjs-packed.tgz", "ai": "^3.0.0", "import-in-the-middle": "^1", "next": "16.2.11", @@ -41,7 +44,8 @@ "@types/react-dom": "^19", "eslint": "^9", "eslint-config-next": "^16", - "typescript": "^5" + "typescript": "^5", + "wrangler": "^4.61.0" }, "volta": { "extends": "../../package.json" @@ -58,6 +62,14 @@ "label": "nextjs-16-tunnel (turbopack)", "assert-command": "pnpm test:assert" } + ], + "optionalVariants": [ + { + "runtime": "cloudflare", + "build-command": "pnpm test:build:cloudflare", + "assert-command": "pnpm test:prod", + "label": "nextjs-16-tunnel (cloudflare)" + } ] } } diff --git a/dev-packages/e2e-tests/test-applications/nextjs-16-tunnel/playwright.config.mjs b/dev-packages/e2e-tests/test-applications/nextjs-16-tunnel/playwright.config.mjs index 797418b8cf7d..4da87c8ca509 100644 --- a/dev-packages/e2e-tests/test-applications/nextjs-16-tunnel/playwright.config.mjs +++ b/dev-packages/e2e-tests/test-applications/nextjs-16-tunnel/playwright.config.mjs @@ -1,4 +1,4 @@ -import { getPlaywrightConfig } from '@sentry-internal/test-utils'; +import { getPlaywrightConfig, getRuntime } from '@sentry-internal/test-utils'; const testEnv = process.env.TEST_ENV; if (!testEnv) { @@ -15,7 +15,7 @@ const getStartCommand = () => { } if (testEnv === 'production') { - return 'pnpm next start -p 3030'; + return getRuntime() === 'cloudflare' ? 'pnpm start:cloudflare --port 3030' : 'pnpm next start -p 3030'; } throw new Error(`Unknown test env: ${testEnv}`); diff --git a/dev-packages/e2e-tests/test-applications/nextjs-16-tunnel/worker.ts b/dev-packages/e2e-tests/test-applications/nextjs-16-tunnel/worker.ts new file mode 100644 index 000000000000..522d8c460dfd --- /dev/null +++ b/dev-packages/e2e-tests/test-applications/nextjs-16-tunnel/worker.ts @@ -0,0 +1,14 @@ +import * as Sentry from '@sentry/nextjs/cloudflare'; +// @ts-ignore the file exists only after `opennextjs-cloudflare build` +import handler from './.open-next/worker.js'; + +export default Sentry.withSentry( + () => ({ + environment: 'qa', // dynamic sampling bias to keep transactions + dsn: 'https://public@o12345.ingest.us.sentry.io/67890', + // Sends the server spans to the proxy server, so the tests see whether a tunnel request was sampled. + tunnel: 'http://localhost:3031/', + tracesSampleRate: 1.0, + }), + handler, +); diff --git a/dev-packages/e2e-tests/test-applications/nextjs-16-tunnel/wrangler.jsonc b/dev-packages/e2e-tests/test-applications/nextjs-16-tunnel/wrangler.jsonc new file mode 100644 index 000000000000..58acae9276b7 --- /dev/null +++ b/dev-packages/e2e-tests/test-applications/nextjs-16-tunnel/wrangler.jsonc @@ -0,0 +1,11 @@ +{ + "$schema": "node_modules/wrangler/config-schema.json", + "name": "nextjs-16-tunnel", + "main": "./worker.ts", + "compatibility_date": "2026-02-19", + "compatibility_flags": ["nodejs_compat"], + "assets": { + "binding": "ASSETS", + "directory": ".open-next/assets", + }, +}