|
1 | 1 | import * as SentryBrowser from '@sentry/browser'; |
2 | 2 | import type { Transaction } from '@sentry/types'; |
| 3 | +import { createApp } from 'vue'; |
3 | 4 |
|
4 | | -import { vueRouterInstrumentation } from '../src'; |
| 5 | +import { init, vueRouterInstrumentation } from '../src'; |
5 | 6 | import type { Route } from '../src/router'; |
6 | 7 | import * as vueTracing from '../src/tracing'; |
7 | 8 |
|
@@ -169,6 +170,51 @@ describe('vueRouterInstrumentation()', () => { |
169 | 170 | }, |
170 | 171 | ); |
171 | 172 |
|
| 173 | + it('allows to configure routeLabel=path', () => { |
| 174 | + // Need to setup a proper client with options etc. |
| 175 | + const app = createApp({ |
| 176 | + template: '<div>hello</div>', |
| 177 | + }); |
| 178 | + const el = document.createElement('div'); |
| 179 | + |
| 180 | + init({ |
| 181 | + app, |
| 182 | + defaultIntegrations: false, |
| 183 | + routeLabel: 'path', |
| 184 | + }); |
| 185 | + |
| 186 | + app.mount(el); |
| 187 | + |
| 188 | + // create instrumentation |
| 189 | + const instrument = vueRouterInstrumentation(mockVueRouter); |
| 190 | + |
| 191 | + // instrument |
| 192 | + instrument(mockStartTransaction, true, true); |
| 193 | + |
| 194 | + // check |
| 195 | + const beforeEachCallback = mockVueRouter.beforeEach.mock.calls[0][0]; |
| 196 | + |
| 197 | + const from = testRoutes.normalRoute1; |
| 198 | + const to = testRoutes.namedRoute; |
| 199 | + beforeEachCallback(to, from, mockNext); |
| 200 | + |
| 201 | + // first startTx call happens when the instrumentation is initialized (for pageloads) |
| 202 | + expect(mockStartTransaction).toHaveBeenLastCalledWith({ |
| 203 | + name: '/login', |
| 204 | + metadata: { |
| 205 | + source: 'route', |
| 206 | + }, |
| 207 | + data: { |
| 208 | + params: to.params, |
| 209 | + query: to.query, |
| 210 | + }, |
| 211 | + op: 'navigation', |
| 212 | + tags: { |
| 213 | + 'routing.instrumentation': 'vue-router', |
| 214 | + }, |
| 215 | + }); |
| 216 | + }); |
| 217 | + |
172 | 218 | it("doesn't overwrite a pageload transaction name it was set to custom before the router resolved the route", () => { |
173 | 219 | const mockedTxn = { |
174 | 220 | setName: jest.fn(), |
|
0 commit comments