|
1 | 1 | import { expect, test } from '@playwright/test'; |
2 | | -import { waitForTransaction } from '@sentry-internal/test-utils'; |
3 | | -import type { Span } from '@sentry/nuxt'; |
| 2 | +import { collectStreamedSpans, getSpanOp, waitForStreamedSpan } from '@sentry-internal/test-utils'; |
4 | 3 |
|
5 | 4 | test('sends a pageload root span with a parameterized URL', async ({ page }) => { |
6 | | - const transactionPromise = waitForTransaction('nuxt-3-dynamic-import', async transactionEvent => { |
7 | | - return transactionEvent.transaction === '/test-param/:param()'; |
| 5 | + const pageloadSpanPromise = waitForStreamedSpan('nuxt-3-dynamic-import', span => { |
| 6 | + return getSpanOp(span) === 'pageload' && span.is_segment; |
8 | 7 | }); |
9 | 8 |
|
10 | 9 | await page.goto(`/test-param/1234`); |
11 | 10 |
|
12 | | - const rootSpan = await transactionPromise; |
13 | | - |
14 | | - expect(rootSpan).toMatchObject({ |
15 | | - contexts: { |
16 | | - trace: { |
17 | | - data: { |
18 | | - 'sentry.segment.name.source': 'route', |
19 | | - 'sentry.origin': 'auto.pageload.vue', |
20 | | - 'sentry.op': 'pageload', |
21 | | - 'params.param': '1234', |
22 | | - 'url.template': '/test-param/:param()', |
23 | | - 'url.path': '/test-param/1234', |
24 | | - 'url.full': expect.stringMatching(/^https?:\/\/localhost:\d+\/test-param\/1234$/), |
25 | | - }, |
26 | | - op: 'pageload', |
27 | | - origin: 'auto.pageload.vue', |
28 | | - }, |
29 | | - }, |
30 | | - transaction: '/test-param/:param()', |
31 | | - transaction_info: { |
32 | | - source: 'route', |
33 | | - }, |
| 11 | + const pageloadSpan = await pageloadSpanPromise; |
| 12 | + |
| 13 | + expect(pageloadSpan.name).toBe('/test-param/:param()'); |
| 14 | + expect(pageloadSpan.status).toBe('ok'); |
| 15 | + expect(pageloadSpan.attributes).toMatchObject({ |
| 16 | + 'sentry.segment.name.source': { type: 'string', value: 'route' }, |
| 17 | + 'sentry.origin': { type: 'string', value: 'auto.pageload.vue' }, |
| 18 | + 'sentry.op': { type: 'string', value: 'pageload' }, |
| 19 | + 'params.param': { type: 'string', value: '1234' }, |
| 20 | + 'url.template': { type: 'string', value: '/test-param/:param()' }, |
| 21 | + 'url.path': { type: 'string', value: '/test-param/1234' }, |
| 22 | + 'url.full': { type: 'string', value: expect.stringMatching(/^https?:\/\/localhost:\d+\/test-param\/1234$/) }, |
34 | 23 | }); |
35 | 24 | }); |
36 | 25 |
|
37 | 26 | test('sends component tracking spans when `trackComponents` is enabled', async ({ page }) => { |
38 | | - const transactionPromise = waitForTransaction('nuxt-3-dynamic-import', async transactionEvent => { |
39 | | - return transactionEvent.transaction === '/client-error'; |
40 | | - }); |
| 27 | + const spansPromise = collectStreamedSpans('nuxt-3-dynamic-import', spans => |
| 28 | + spans.some(span => span.name === '/client-error' && span.is_segment && getSpanOp(span) === 'pageload'), |
| 29 | + ); |
41 | 30 |
|
42 | 31 | await page.goto(`/client-error`); |
43 | 32 |
|
44 | | - const rootSpan = await transactionPromise; |
45 | | - const errorButtonSpan = rootSpan.spans.find((span: Span) => span.description === 'Vue <ErrorButton>'); |
| 33 | + const spans = await spansPromise; |
| 34 | + const errorButtonSpan = spans.find(span => span.name === 'Vue <ErrorButton>'); |
46 | 35 |
|
47 | | - const expected = { |
48 | | - data: { 'sentry.origin': 'auto.ui.vue', 'sentry.op': 'ui.mount' }, |
49 | | - description: 'Vue <ErrorButton>', |
50 | | - op: 'ui.mount', |
| 36 | + expect(errorButtonSpan).toMatchObject({ |
| 37 | + name: 'Vue <ErrorButton>', |
| 38 | + is_segment: false, |
51 | 39 | parent_span_id: expect.stringMatching(/[a-f0-9]{16}/), |
52 | 40 | span_id: expect.stringMatching(/[a-f0-9]{16}/), |
53 | | - start_timestamp: expect.any(Number), |
54 | | - timestamp: expect.any(Number), |
55 | 41 | trace_id: expect.stringMatching(/[a-f0-9]{32}/), |
56 | | - origin: 'auto.ui.vue', |
57 | | - }; |
58 | | - |
59 | | - expect(errorButtonSpan).toMatchObject(expected); |
| 42 | + start_timestamp: expect.any(Number), |
| 43 | + end_timestamp: expect.any(Number), |
| 44 | + attributes: expect.objectContaining({ |
| 45 | + 'sentry.op': { type: 'string', value: 'ui.mount' }, |
| 46 | + 'sentry.origin': { type: 'string', value: 'auto.ui.vue' }, |
| 47 | + }), |
| 48 | + }); |
60 | 49 | }); |
0 commit comments