Skip to content

Commit fa9fa5d

Browse files
authored
test(nuxt): Add tests for Vue component tracking (#13633)
1 parent e944daa commit fa9fa5d

File tree

5 files changed

+60
-32
lines changed

5 files changed

+60
-32
lines changed

dev-packages/e2e-tests/test-applications/nuxt-3/sentry.client.config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,5 @@ Sentry.init({
66
dsn: useRuntimeConfig().public.sentry.dsn,
77
tunnel: `http://localhost:3031/`, // proxy server
88
tracesSampleRate: 1.0,
9+
trackComponents: true,
910
});

dev-packages/e2e-tests/test-applications/nuxt-3/tests/performance.client.test.ts

Lines changed: 0 additions & 31 deletions
This file was deleted.
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
import { expect, test } from '@nuxt/test-utils/playwright';
2+
import { waitForTransaction } from '@sentry-internal/test-utils';
3+
import type { Span } from '@sentry/nuxt';
4+
5+
test('sends a pageload root span with a parameterized URL', async ({ page }) => {
6+
const transactionPromise = waitForTransaction('nuxt-3', async transactionEvent => {
7+
return transactionEvent.transaction === '/test-param/:param()';
8+
});
9+
10+
await page.goto(`/test-param/1234`);
11+
12+
const rootSpan = await transactionPromise;
13+
14+
expect(rootSpan).toMatchObject({
15+
contexts: {
16+
trace: {
17+
data: {
18+
'sentry.source': 'route',
19+
'sentry.origin': 'auto.pageload.vue',
20+
'sentry.op': 'pageload',
21+
'params.param': '1234',
22+
},
23+
op: 'pageload',
24+
origin: 'auto.pageload.vue',
25+
},
26+
},
27+
transaction: '/test-param/:param()',
28+
transaction_info: {
29+
source: 'route',
30+
},
31+
});
32+
});
33+
34+
test('sends component tracking spans when `trackComponents` is enabled', async ({ page }) => {
35+
const transactionPromise = waitForTransaction('nuxt-3', async transactionEvent => {
36+
return transactionEvent.transaction === '/client-error';
37+
});
38+
39+
await page.goto(`/client-error`);
40+
41+
const rootSpan = await transactionPromise;
42+
const errorButtonSpan = rootSpan.spans.find((span: Span) => span.description === 'Vue <ErrorButton>');
43+
44+
const expected = {
45+
data: { 'sentry.origin': 'auto.ui.vue', 'sentry.op': 'ui.vue.mount' },
46+
description: 'Vue <ErrorButton>',
47+
op: 'ui.vue.mount',
48+
parent_span_id: expect.any(String),
49+
span_id: expect.any(String),
50+
start_timestamp: expect.any(Number),
51+
timestamp: expect.any(Number),
52+
trace_id: expect.any(String),
53+
origin: 'auto.ui.vue',
54+
};
55+
56+
expect(errorButtonSpan).toMatchObject(expected);
57+
});

packages/nuxt/src/index.types.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import type { Integration, Options, StackParser } from '@sentry/types';
2+
import type { SentryNuxtClientOptions } from './common/types';
23
import type * as clientSdk from './index.client';
34
import type * as serverSdk from './index.server';
45

@@ -8,7 +9,7 @@ export * from './index.client';
89
export * from './index.server';
910

1011
// re-export colliding types
11-
export declare function init(options: Options | clientSdk.BrowserOptions | serverSdk.NodeOptions): void;
12+
export declare function init(options: Options | SentryNuxtClientOptions | serverSdk.NodeOptions): void;
1213
export declare const linkedErrorsIntegration: typeof clientSdk.linkedErrorsIntegration;
1314
export declare const contextLinesIntegration: typeof clientSdk.contextLinesIntegration;
1415
export declare const getDefaultIntegrations: (options: Options) => Integration[];

0 commit comments

Comments
 (0)