@@ -13,18 +13,23 @@ import {
13
13
Navigate ,
14
14
Outlet ,
15
15
Route ,
16
+ RouterProvider ,
16
17
Routes ,
18
+ createMemoryRouter ,
17
19
createRoutesFromChildren ,
18
20
matchRoutes ,
19
21
useLocation ,
20
22
useNavigationType ,
21
23
useRoutes ,
22
24
} from 'react-router-6' ;
23
25
26
+ import type { RouteObject } from 'react-router-6' ;
27
+
24
28
import { BrowserClient } from '../src' ;
25
29
import {
26
30
reactRouterV6BrowserTracingIntegration ,
27
31
withSentryReactRouterV6Routing ,
32
+ wrapCreateBrowserRouterV6 ,
28
33
wrapUseRoutesV6 ,
29
34
} from '../src/reactrouterv6' ;
30
35
@@ -79,6 +84,90 @@ describe('reactRouterV6BrowserTracingIntegration', () => {
79
84
getCurrentScope ( ) . setClient ( undefined ) ;
80
85
} ) ;
81
86
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
+
82
171
describe ( 'withSentryReactRouterV6Routing' , ( ) => {
83
172
it ( 'starts a pageload transaction' , ( ) => {
84
173
const client = createMockBrowserClient ( ) ;
0 commit comments