@@ -13,7 +13,13 @@ import type { Integration } from '@sentry/types';
13
13
import { logger } from '@sentry/utils' ;
14
14
import { JSDOM } from 'jsdom' ;
15
15
16
- import { BrowserTracing , breadcrumbsIntegration , init , nextRouterInstrumentation } from '../src/client' ;
16
+ import {
17
+ BrowserTracing ,
18
+ breadcrumbsIntegration ,
19
+ browserTracingIntegration as nextjsBrowserTracingIntegration ,
20
+ init ,
21
+ nextRouterInstrumentation ,
22
+ } from '../src/client' ;
17
23
18
24
const reactInit = jest . spyOn ( SentryReact , 'init' ) ;
19
25
const captureEvent = jest . spyOn ( BaseClient . prototype , 'captureEvent' ) ;
@@ -174,11 +180,7 @@ describe('Client init()', () => {
174
180
// It is a "new" browser tracing integration
175
181
expect ( typeof integration ?. afterAllSetup ) . toBe ( 'function' ) ;
176
182
177
- // This shows that the user-configured options are still here
178
- expect ( integration ?. options ?. finalTimeout ) . toEqual ( 10 ) ;
179
- expect ( integration ?. options . instrumentNavigation ) . toBe ( false ) ;
180
- expect ( integration ?. options . instrumentPageLoad ) . toBe ( true ) ;
181
-
183
+ // the hooks is correctly invoked
182
184
expect ( beforeStartSpan ) . toHaveBeenCalledTimes ( 1 ) ;
183
185
expect ( beforeStartSpan ) . toHaveBeenCalledWith (
184
186
expect . objectContaining ( {
@@ -187,11 +189,49 @@ describe('Client init()', () => {
187
189
} ) ,
188
190
) ;
189
191
190
- // it is the svelte kit variety
192
+ // it correctly starts the page load span
193
+ expect ( getActiveSpan ( ) ) . toBeDefined ( ) ;
194
+ expect ( spanToJSON ( getActiveSpan ( ) ! ) . data ?. [ SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN ] ) . toEqual (
195
+ 'auto.pageload.nextjs.app_router_instrumentation' ,
196
+ ) ;
197
+
198
+ // This shows that the user-configured options are still here
199
+ expect ( integration ?. options . finalTimeout ) . toEqual ( 10 ) ;
200
+ expect ( integration ?. options . instrumentNavigation ) . toBe ( false ) ;
201
+ expect ( integration ?. options . instrumentPageLoad ) . toBe ( true ) ;
202
+ } ) ;
203
+
204
+ it ( 'forces correct router instrumentation if user provides Next.js `browserTracingIntegration` ' , ( ) => {
205
+ init ( {
206
+ dsn : TEST_DSN ,
207
+ integrations : [
208
+ nextjsBrowserTracingIntegration ( {
209
+ finalTimeout : 10 ,
210
+ instrumentNavigation : false ,
211
+ } ) ,
212
+ ] ,
213
+ enableTracing : true ,
214
+ } ) ;
215
+
216
+ const client = getClient < BrowserClient > ( ) ! ;
217
+ // eslint-disable-next-line deprecation/deprecation
218
+ const integration = client . getIntegrationByName < ReturnType < typeof browserTracingIntegration > > ( 'BrowserTracing' ) ;
219
+
220
+ expect ( integration ) . toBeDefined ( ) ;
221
+
222
+ // It is a "new" browser tracing integration
223
+ expect ( typeof integration ?. afterAllSetup ) . toBe ( 'function' ) ;
224
+
225
+ // it correctly starts the pageload span
191
226
expect ( getActiveSpan ( ) ) . toBeDefined ( ) ;
192
227
expect ( spanToJSON ( getActiveSpan ( ) ! ) . data ?. [ SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN ] ) . toEqual (
193
228
'auto.pageload.nextjs.app_router_instrumentation' ,
194
229
) ;
230
+
231
+ // This shows that the user-configured options are still here
232
+ expect ( integration ?. options . finalTimeout ) . toEqual ( 10 ) ;
233
+ expect ( integration ?. options . instrumentNavigation ) . toBe ( false ) ;
234
+ expect ( integration ?. options . instrumentPageLoad ) . toBe ( true ) ;
195
235
} ) ;
196
236
197
237
it ( 'forces correct router instrumentation if user provides `BrowserTracing` in a function' , ( ) => {
0 commit comments