@@ -57,6 +57,9 @@ describe('sveltekitRoutingInstrumentation', () => {
57
57
tags : {
58
58
'routing.instrumentation' : '@sentry/sveltekit' ,
59
59
} ,
60
+ metadata : {
61
+ source : 'url' ,
62
+ } ,
60
63
} ) ;
61
64
62
65
// We emit an update to the `page` store to simulate the SvelteKit router lifecycle
@@ -73,15 +76,15 @@ describe('sveltekitRoutingInstrumentation', () => {
73
76
expect ( mockedStartTransaction ) . toHaveBeenCalledTimes ( 0 ) ;
74
77
} ) ;
75
78
76
- it ( "doesn't starts a navigation transaction when `startTransactionOnLocationChange` is false" , ( ) => {
79
+ it ( "doesn't start a navigation transaction when `startTransactionOnLocationChange` is false" , ( ) => {
77
80
svelteKitRoutingInstrumentation ( mockedStartTransaction , false , false ) ;
78
81
79
82
// We emit an update to the `navigating` store to simulate the SvelteKit navigation lifecycle
80
83
// @ts -ignore This is fine because we testUtils/stores.ts defines `navigating` as a writable store
81
- navigating . set (
82
- { from : { route : { id : 'testNavigationOrigin ' } } } ,
83
- { to : { route : { id : 'testNavigationDestination ' } } } ,
84
- ) ;
84
+ navigating . set ( {
85
+ from : { route : { id : '/users ' } , url : { pathname : '/users' } } ,
86
+ to : { route : { id : '/users/[id] ' } , url : { pathname : '/users/7762' } } ,
87
+ } ) ;
85
88
86
89
// This should update the transaction name with the parameterized route:
87
90
expect ( mockedStartTransaction ) . toHaveBeenCalledTimes ( 0 ) ;
@@ -93,14 +96,14 @@ describe('sveltekitRoutingInstrumentation', () => {
93
96
// We emit an update to the `navigating` store to simulate the SvelteKit navigation lifecycle
94
97
// @ts -ignore This is fine because we testUtils/stores.ts defines `navigating` as a writable store
95
98
navigating . set ( {
96
- from : { route : { id : 'testNavigationOrigin ' } } ,
97
- to : { route : { id : 'testNavigationDestination ' } } ,
99
+ from : { route : { id : '/users' } , url : { pathname : '/users ' } } ,
100
+ to : { route : { id : '/users/[id]' } , url : { pathname : '/users/7762 ' } } ,
98
101
} ) ;
99
102
100
103
// This should update the transaction name with the parameterized route:
101
104
expect ( mockedStartTransaction ) . toHaveBeenCalledTimes ( 1 ) ;
102
105
expect ( mockedStartTransaction ) . toHaveBeenCalledWith ( {
103
- name : 'testNavigationDestination ' ,
106
+ name : '/users/[id] ' ,
104
107
op : 'navigation' ,
105
108
metadata : {
106
109
source : 'route' ,
@@ -115,7 +118,7 @@ describe('sveltekitRoutingInstrumentation', () => {
115
118
description : 'SvelteKit Route Change' ,
116
119
} ) ;
117
120
118
- expect ( returnedTransaction ?. setTag ) . toHaveBeenCalledWith ( 'from' , 'testNavigationOrigin ' ) ;
121
+ expect ( returnedTransaction ?. setTag ) . toHaveBeenCalledWith ( 'from' , '/users ' ) ;
119
122
120
123
// We emit `null` here to simulate the end of the navigation lifecycle
121
124
// @ts -ignore this is fine
@@ -124,16 +127,60 @@ describe('sveltekitRoutingInstrumentation', () => {
124
127
expect ( routingSpanFinishSpy ) . toHaveBeenCalledTimes ( 1 ) ;
125
128
} ) ;
126
129
127
- it ( "doesn't start a navigation transaction if navigation origin and destination are equal" , ( ) => {
128
- svelteKitRoutingInstrumentation ( mockedStartTransaction , false , true ) ;
130
+ describe ( 'handling same origin and destination navigations' , ( ) => {
131
+ it ( "doesn't start a navigation transaction if the raw navigation origin and destination are equal" , ( ) => {
132
+ svelteKitRoutingInstrumentation ( mockedStartTransaction , false , true ) ;
129
133
130
- // We emit an update to the `navigating` store to simulate the SvelteKit navigation lifecycle
131
- // @ts -ignore This is fine because we testUtils/stores.ts defines `navigating` as a writable store
132
- navigating . set ( {
133
- from : { route : { id : 'testRoute' } } ,
134
- to : { route : { id : 'testRoute' } } ,
134
+ // We emit an update to the `navigating` store to simulate the SvelteKit navigation lifecycle
135
+ // @ts -ignore This is fine because we testUtils/stores.ts defines `navigating` as a writable store
136
+ navigating . set ( {
137
+ from : { route : { id : '/users/[id]' } , url : { pathname : '/users/7762' } } ,
138
+ to : { route : { id : '/users/[id]' } , url : { pathname : '/users/7762' } } ,
139
+ } ) ;
140
+
141
+ expect ( mockedStartTransaction ) . toHaveBeenCalledTimes ( 0 ) ;
135
142
} ) ;
136
143
137
- expect ( mockedStartTransaction ) . toHaveBeenCalledTimes ( 0 ) ;
144
+ it ( 'starts a navigation transaction if the raw navigation origin and destination are not equal' , ( ) => {
145
+ svelteKitRoutingInstrumentation ( mockedStartTransaction , false , true ) ;
146
+
147
+ // @ts -ignore This is fine
148
+ navigating . set ( {
149
+ from : { route : { id : '/users/[id]' } , url : { pathname : '/users/7762' } } ,
150
+ to : { route : { id : '/users/[id]' } , url : { pathname : '/users/223412' } } ,
151
+ } ) ;
152
+
153
+ expect ( mockedStartTransaction ) . toHaveBeenCalledTimes ( 1 ) ;
154
+ expect ( mockedStartTransaction ) . toHaveBeenCalledWith ( {
155
+ name : '/users/[id]' ,
156
+ op : 'navigation' ,
157
+ metadata : {
158
+ source : 'route' ,
159
+ } ,
160
+ tags : {
161
+ 'routing.instrumentation' : '@sentry/sveltekit' ,
162
+ } ,
163
+ } ) ;
164
+
165
+ expect ( returnedTransaction ?. startChild ) . toHaveBeenCalledWith ( {
166
+ op : 'ui.sveltekit.routing' ,
167
+ description : 'SvelteKit Route Change' ,
168
+ } ) ;
169
+
170
+ expect ( returnedTransaction ?. setTag ) . toHaveBeenCalledWith ( 'from' , '/users/[id]' ) ;
171
+ } ) ;
172
+
173
+ it ( 'falls back to `window.location.pathname` to determine the raw origin' , ( ) => {
174
+ svelteKitRoutingInstrumentation ( mockedStartTransaction , false , true ) ;
175
+
176
+ // window.location.pathame is "/" in tests
177
+
178
+ // @ts -ignore This is fine
179
+ navigating . set ( {
180
+ to : { route : { } , url : { pathname : '/' } } ,
181
+ } ) ;
182
+
183
+ expect ( mockedStartTransaction ) . toHaveBeenCalledTimes ( 0 ) ;
184
+ } ) ;
138
185
} ) ;
139
186
} ) ;
0 commit comments