Skip to content

Commit b332e39

Browse files
committed
qef: use env for tests instead
1 parent 4171eca commit b332e39

File tree

5 files changed

+19
-27
lines changed

5 files changed

+19
-27
lines changed

dev-packages/e2e-tests/test-applications/nextjs-16-tunnel/next.config.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,4 @@ const nextConfig: NextConfig = {};
66
export default withSentryConfig(nextConfig, {
77
silent: true,
88
tunnelRoute: true,
9-
_tunnelRouteDestinationOverride: 'http://localhost:3031/',
109
});

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,16 @@
33
"version": "0.1.0",
44
"private": true,
55
"scripts": {
6-
"dev": "next dev",
7-
"build": "next build > .tmp_build_stdout 2> .tmp_build_stderr || (cat .tmp_build_stdout && cat .tmp_build_stderr && exit 1)",
6+
"dev": " next dev",
7+
"build": "_SENTRY_TUNNEL_DESTINATION_OVERRIDE=http://localhost:3031/ next build > .tmp_build_stdout 2> .tmp_build_stderr || (cat .tmp_build_stdout && cat .tmp_build_stderr && exit 1)",
88
"clean": "npx rimraf node_modules pnpm-lock.yaml .tmp_dev_server_logs",
9-
"dev:webpack": "next dev --webpack",
10-
"build-webpack": "next build --webpack > .tmp_build_stdout 2> .tmp_build_stderr || (cat .tmp_build_stdout && cat .tmp_build_stderr && exit 1)",
11-
"start": "next start",
9+
"dev:webpack": "_SENTRY_TUNNEL_DESTINATION_OVERRIDE=http://localhost:3031/ next dev --webpack",
10+
"build-webpack": "_SENTRY_TUNNEL_DESTINATION_OVERRIDE=http://localhost:3031/ next build --webpack > .tmp_build_stdout 2> .tmp_build_stderr || (cat .tmp_build_stdout && cat .tmp_build_stderr && exit 1)",
11+
"start": "_SENTRY_TUNNEL_DESTINATION_OVERRIDE=http://localhost:3031/ next start",
1212
"lint": "eslint",
1313
"test:prod": "TEST_ENV=production playwright test",
14-
"test:dev": "TEST_ENV=development playwright test",
15-
"test:dev-webpack": "TEST_ENV=development-webpack playwright test",
14+
"test:dev": "TEST_ENV=development _SENTRY_TUNNEL_DESTINATION_OVERRIDE=http://localhost:3031/ playwright test",
15+
"test:dev-webpack": "TEST_ENV=development-webpack _SENTRY_TUNNEL_DESTINATION_OVERRIDE=http://localhost:3031/ playwright test",
1616
"test:build": "pnpm install && pnpm build",
1717
"test:build-webpack": "pnpm install && pnpm build-webpack",
1818
"test:build-canary": "pnpm install && pnpm add next@canary && pnpm build",

packages/nextjs/src/common/utils/dropMiddlewareTunnelRequests.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ function isTunnelRouteSpan(spanAttributes: Record<string, unknown>): boolean {
4949

5050
// Check both http.target (older) and url.query (newer) attributes
5151
// eslint-disable-next-line deprecation/deprecation
52-
const httpTarget = spanAttributes[SEMATTRS_HTTP_TARGET] || spanAttributes[ATTR_URL_QUERY];
52+
const httpTarget = spanAttributes[SEMATTRS_HTTP_TARGET];
5353

5454
if (typeof httpTarget === 'string') {
5555
// Extract pathname from the target (e.g., "/tunnel?o=123&p=456" -> "/tunnel")

packages/nextjs/src/config/types.ts

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -437,12 +437,6 @@ export type SentryBuildOptions = {
437437
*/
438438
tunnelRoute?: string | boolean;
439439

440-
/**
441-
* @internal
442-
* Override the destination URL for tunnel rewrites (for E2E testing only)
443-
*/
444-
_tunnelRouteDestinationOverride?: string;
445-
446440
/**
447441
* Tree shakes Sentry SDK logger statements from the bundle.
448442
*/

packages/nextjs/src/config/withSentryConfig.ts

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -125,11 +125,7 @@ function getFinalConfigObject(
125125
const resolvedTunnelRoute = resolveTunnelRoute(userSentryOptions.tunnelRoute);
126126
userSentryOptions.tunnelRoute = resolvedTunnelRoute || undefined;
127127

128-
setUpTunnelRewriteRules(
129-
incomingUserNextConfigObject,
130-
resolvedTunnelRoute,
131-
userSentryOptions._tunnelRouteDestinationOverride,
132-
);
128+
setUpTunnelRewriteRules(incomingUserNextConfigObject, resolvedTunnelRoute);
133129
}
134130
}
135131

@@ -393,12 +389,15 @@ function getFinalConfigObject(
393389
*
394390
* See https://nextjs.org/docs/api-reference/next.config.js/rewrites.
395391
*/
396-
function setUpTunnelRewriteRules(
397-
userNextConfig: NextConfigObject,
398-
tunnelPath: string,
399-
destinationOverride?: string,
400-
): void {
392+
function setUpTunnelRewriteRules(userNextConfig: NextConfigObject, tunnelPath: string): void {
401393
const originalRewrites = userNextConfig.rewrites;
394+
// Allow overriding the tunnel destination for E2E tests via environment variable
395+
const destinationOverride = process.env._SENTRY_TUNNEL_DESTINATION_OVERRIDE;
396+
397+
// Make sure destinations are statically defined at build time
398+
const destination = destinationOverride || 'https://o:orgid.ingest.sentry.io/api/:projectid/envelope/?hsts=0';
399+
const destinationWithRegion =
400+
destinationOverride || 'https://o:orgid.ingest.:region.sentry.io/api/:projectid/envelope/?hsts=0';
402401

403402
// This function doesn't take any arguments at the time of writing but we future-proof
404403
// here in case Next.js ever decides to pass some
@@ -419,7 +418,7 @@ function setUpTunnelRewriteRules(
419418
value: '(?<projectid>\\d*)',
420419
},
421420
],
422-
destination: destinationOverride || 'https://o:orgid.ingest.sentry.io/api/:projectid/envelope/?hsts=0',
421+
destination,
423422
};
424423

425424
const tunnelRouteRewriteWithRegion = {
@@ -443,7 +442,7 @@ function setUpTunnelRewriteRules(
443442
value: '(?<region>[a-z]{2})',
444443
},
445444
],
446-
destination: destinationOverride || 'https://o:orgid.ingest.:region.sentry.io/api/:projectid/envelope/?hsts=0',
445+
destination: destinationWithRegion,
447446
};
448447

449448
// Order of these is important, they get applied first to last.

0 commit comments

Comments
 (0)