File tree Expand file tree Collapse file tree 4 files changed +38
-7
lines changed
e2e-tests/test-applications/nextjs-15-spotlight Expand file tree Collapse file tree 4 files changed +38
-7
lines changed Original file line number Diff line number Diff line change 11import * as Sentry from '@sentry/nextjs' ;
22
3- // In Next.js 15 Turbopack dev mode, custom loaders aren't applied to instrumentation files.
4- // So we need to explicitly pass the spotlight value from process.env which Next.js DOES replace.
5- // This is a workaround for the valueInjectionLoader not working in Turbopack.
3+ // In Next.js 15, Turbopack is the default dev bundler. Turbopack doesn't replace
4+ // process.env vars in node_modules code, which prevents the SDK's auto-detection
5+ // from working. As a workaround, we explicitly pass the spotlight value from
6+ // process.env which Next.js DOES replace in user code.
7+ //
8+ // Note: Auto-detection DOES work in:
9+ // - Next.js with webpack (older versions or configured to use webpack)
10+ // - Other frameworks like Vite, Create React App, etc.
611const spotlightValue = process . env . NEXT_PUBLIC_SENTRY_SPOTLIGHT === 'true' ;
712
813console . log ( '[Sentry Debug] Spotlight from process.env:' , spotlightValue ) ;
Original file line number Diff line number Diff line change 55 "scripts" : {
66 "dev" : " next dev -p 3030" ,
77 "build" : " next build" ,
8+ "start" : " next start -p 3030" ,
89 "test" : " playwright test" ,
910 "test:build" : " pnpm install" ,
1011 "test:assert" : " pnpm test"
Original file line number Diff line number Diff line change 11import { getPlaywrightConfig } from '@sentry-internal/test-utils' ;
22
33const config = getPlaywrightConfig ( {
4- // Use next dev to test development-mode behavior where Spotlight is auto-enabled
4+ // Use next dev to test development-mode behavior where Spotlight is auto-enabled.
5+ // Note: In Next.js 15, Turbopack is the default dev bundler and doesn't replace
6+ // process.env vars in node_modules code. This prevents the SDK's auto-detection
7+ // from working, so the test explicitly passes the spotlight value.
58 startCommand : 'pnpm dev' ,
69 port : 3030 ,
710 eventProxyFile : 'start-event-proxy.mjs' ,
Original file line number Diff line number Diff line change @@ -82,6 +82,30 @@ export function getPlaywrightConfig(
8282 } ;
8383
8484 if ( startCommand ) {
85+ // Filter environment variables to only include those that are safe and needed
86+ // We avoid passing ALL env vars to prevent unintended side effects in tests
87+ const filteredEnv = Object . fromEntries (
88+ Object . entries ( process . env ) . filter ( ( [ key ] ) => {
89+ // Include E2E test DSN variables (needed by all test apps)
90+ if ( key . includes ( 'E2E_TEST_DSN' ) || key === 'E2E_TEST_SENTRY_ORG_SLUG' || key === 'E2E_TEST_SENTRY_PROJECT' ) {
91+ return true ;
92+ }
93+ // Include Spotlight environment variables (needed for Spotlight tests)
94+ if ( key . includes ( 'SENTRY_SPOTLIGHT' ) ) {
95+ return true ;
96+ }
97+ // Include Node/npm related variables for proper execution
98+ if ( key === 'PATH' || key === 'NODE_ENV' || key === 'HOME' || key === 'USER' ) {
99+ return true ;
100+ }
101+ // Include CI variable for proper test configuration
102+ if ( key === 'CI' ) {
103+ return true ;
104+ }
105+ return false ;
106+ } ) ,
107+ ) ;
108+
85109 // @ts -expect-error - we set `config.webserver` to an array above.
86110 // TS just can't infer that and thinks it could also be undefined or an object.
87111 config . webServer . push ( {
@@ -90,9 +114,7 @@ export function getPlaywrightConfig(
90114 stdout : 'pipe' ,
91115 stderr : 'pipe' ,
92116 env : {
93- // Inherit all environment variables from the parent process
94- // This is needed for env vars like NEXT_PUBLIC_SENTRY_SPOTLIGHT to be passed through
95- ...process . env ,
117+ ...filteredEnv ,
96118 PORT : appPort . toString ( ) ,
97119 } ,
98120 } ) ;
You can’t perform that action at this time.
0 commit comments