Skip to content

Commit 4d3f791

Browse files
JPeer264claude
andcommitted
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 <noreply@anthropic.com>
1 parent 8ead2fc commit 4d3f791

5 files changed

Lines changed: 45 additions & 5 deletions

File tree

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import { defineCloudflareConfig } from '@opennextjs/cloudflare';
2+
3+
export default defineCloudflareConfig();

‎dev-packages/e2e-tests/test-applications/nextjs-16-tunnel/package.json‎

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,14 @@
2020
"test:build-latest-webpack": "pnpm install && pnpm add next@latest && pnpm build-webpack",
2121
"test:build-canary-webpack": "pnpm install && pnpm add next@canary && pnpm build-webpack",
2222
"test:assert": "pnpm test:prod && pnpm test:dev",
23-
"test:assert-webpack": "pnpm test:prod && pnpm test:dev-webpack"
23+
"test:assert-webpack": "pnpm test:prod && pnpm test:dev-webpack",
24+
"test:build:cloudflare": "pnpm install && _SENTRY_TUNNEL_DESTINATION_OVERRIDE=http://localhost:3031/ opennextjs-cloudflare build",
25+
"start:cloudflare": "opennextjs-cloudflare preview"
2426
},
2527
"dependencies": {
26-
"@sentry/nextjs": "file:../../packed/sentry-nextjs-packed.tgz",
28+
"@opennextjs/cloudflare": "^1.14.9",
2729
"@sentry/core": "file:../../packed/sentry-core-packed.tgz",
30+
"@sentry/nextjs": "file:../../packed/sentry-nextjs-packed.tgz",
2831
"ai": "^3.0.0",
2932
"import-in-the-middle": "^1",
3033
"next": "16.2.11",
@@ -41,7 +44,8 @@
4144
"@types/react-dom": "^19",
4245
"eslint": "^9",
4346
"eslint-config-next": "^16",
44-
"typescript": "^5"
47+
"typescript": "^5",
48+
"wrangler": "^4.61.0"
4549
},
4650
"volta": {
4751
"extends": "../../package.json"
@@ -58,6 +62,14 @@
5862
"label": "nextjs-16-tunnel (turbopack)",
5963
"assert-command": "pnpm test:assert"
6064
}
65+
],
66+
"optionalVariants": [
67+
{
68+
"runtime": "cloudflare",
69+
"build-command": "pnpm test:build:cloudflare",
70+
"assert-command": "pnpm test:prod",
71+
"label": "nextjs-16-tunnel (cloudflare)"
72+
}
6173
]
6274
}
6375
}

‎dev-packages/e2e-tests/test-applications/nextjs-16-tunnel/playwright.config.mjs‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { getPlaywrightConfig } from '@sentry-internal/test-utils';
1+
import { getPlaywrightConfig, getRuntime } from '@sentry-internal/test-utils';
22
const testEnv = process.env.TEST_ENV;
33

44
if (!testEnv) {
@@ -15,7 +15,7 @@ const getStartCommand = () => {
1515
}
1616

1717
if (testEnv === 'production') {
18-
return 'pnpm next start -p 3030';
18+
return getRuntime() === 'cloudflare' ? 'pnpm start:cloudflare --port 3030' : 'pnpm next start -p 3030';
1919
}
2020

2121
throw new Error(`Unknown test env: ${testEnv}`);
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import * as Sentry from '@sentry/nextjs/cloudflare';
2+
// @ts-ignore the file exists only after `opennextjs-cloudflare build`
3+
import handler from './.open-next/worker.js';
4+
5+
export default Sentry.withSentry(
6+
() => ({
7+
environment: 'qa', // dynamic sampling bias to keep transactions
8+
dsn: 'https://public@o12345.ingest.us.sentry.io/67890',
9+
// Sends the server spans to the proxy server, so the tests see whether a tunnel request was sampled.
10+
tunnel: 'http://localhost:3031/',
11+
tracesSampleRate: 1.0,
12+
}),
13+
handler,
14+
);
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"$schema": "node_modules/wrangler/config-schema.json",
3+
"name": "nextjs-16-tunnel",
4+
"main": "./worker.ts",
5+
"compatibility_date": "2026-02-19",
6+
"compatibility_flags": ["nodejs_compat"],
7+
"assets": {
8+
"binding": "ASSETS",
9+
"directory": ".open-next/assets",
10+
},
11+
}

0 commit comments

Comments
 (0)