@@ -13,18 +13,23 @@ import {
1313 Navigate ,
1414 Outlet ,
1515 Route ,
16+ RouterProvider ,
1617 Routes ,
18+ createMemoryRouter ,
1719 createRoutesFromChildren ,
1820 matchRoutes ,
1921 useLocation ,
2022 useNavigationType ,
2123 useRoutes ,
2224} from 'react-router-6' ;
2325
26+ import type { RouteObject } from 'react-router-6' ;
27+
2428import { BrowserClient } from '../src' ;
2529import {
2630 reactRouterV6BrowserTracingIntegration ,
2731 withSentryReactRouterV6Routing ,
32+ wrapCreateBrowserRouterV6 ,
2833 wrapUseRoutesV6 ,
2934} from '../src/reactrouterv6' ;
3035
@@ -79,6 +84,90 @@ describe('reactRouterV6BrowserTracingIntegration', () => {
7984 getCurrentScope ( ) . setClient ( undefined ) ;
8085 } ) ;
8186
87+ describe ( 'wrapCreateBrowserRouterV6 - createMemoryRouter' , ( ) => {
88+ it ( 'starts a pageload transaction' , ( ) => {
89+ const client = createMockBrowserClient ( ) ;
90+ setCurrentClient ( client ) ;
91+
92+ client . addIntegration (
93+ reactRouterV6BrowserTracingIntegration ( {
94+ useEffect : React . useEffect ,
95+ useLocation,
96+ useNavigationType,
97+ createRoutesFromChildren,
98+ matchRoutes,
99+ } ) ,
100+ ) ;
101+
102+ const routes : RouteObject [ ] = [
103+ {
104+ path : '/' ,
105+ element : < div > Home</ div > ,
106+ } ,
107+ {
108+ path : '/about' ,
109+ element : < div > About</ div > ,
110+ } ,
111+ ] ;
112+
113+ const wrappedCreateMemoryRouter = wrapCreateBrowserRouterV6 ( createMemoryRouter ) ;
114+
115+ const router = wrappedCreateMemoryRouter ( routes , {
116+ initialEntries : [ '/' , '/about' ] ,
117+ initialIndex : 1 ,
118+ } ) ;
119+
120+ render ( < RouterProvider router = { router } /> ) ;
121+
122+ expect ( mockStartBrowserTracingPageLoadSpan ) . toHaveBeenCalledTimes ( 1 ) ;
123+ expect ( mockStartBrowserTracingPageLoadSpan ) . toHaveBeenLastCalledWith ( expect . any ( BrowserClient ) , {
124+ name : '/' ,
125+ attributes : {
126+ [ SEMANTIC_ATTRIBUTE_SENTRY_SOURCE ] : 'url' ,
127+ [ SEMANTIC_ATTRIBUTE_SENTRY_OP ] : 'pageload' ,
128+ [ SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN ] : 'auto.pageload.react.reactrouter_v6' ,
129+ } ,
130+ } ) ;
131+ } ) ;
132+
133+ it ( 'updates the transaction name on a pageload' , ( ) => {
134+ const client = createMockBrowserClient ( ) ;
135+ setCurrentClient ( client ) ;
136+
137+ client . addIntegration (
138+ reactRouterV6BrowserTracingIntegration ( {
139+ useEffect : React . useEffect ,
140+ useLocation,
141+ useNavigationType,
142+ createRoutesFromChildren,
143+ matchRoutes,
144+ } ) ,
145+ ) ;
146+
147+ const routes : RouteObject [ ] = [
148+ {
149+ path : '/' ,
150+ element : < div > Home</ div > ,
151+ } ,
152+ {
153+ path : '/about' ,
154+ element : < div > About</ div > ,
155+ } ,
156+ ] ;
157+
158+ const wrappedCreateMemoryRouter = wrapCreateBrowserRouterV6 ( createMemoryRouter ) ;
159+
160+ const router = wrappedCreateMemoryRouter ( routes , {
161+ initialEntries : [ '/' , '/about' ] ,
162+ initialIndex : 2 ,
163+ } ) ;
164+
165+ render ( < RouterProvider router = { router } /> ) ;
166+
167+ expect ( mockRootSpan . updateName ) . toHaveBeenLastCalledWith ( '/about' ) ;
168+ } ) ;
169+ } ) ;
170+
82171 describe ( 'withSentryReactRouterV6Routing' , ( ) => {
83172 it ( 'starts a pageload transaction' , ( ) => {
84173 const client = createMockBrowserClient ( ) ;
0 commit comments