Skip to content

Commit 5e2bc47

Browse files
authored
test(nuxt): Add E2E test for distributed tracing (#13752)
Test for pageload. Tests for distributed tracing for navigations are still coming (waiting for next Nuxt version which includes the new version of ofetch with [this PR](unjs/ofetch#377))
1 parent 3714d60 commit 5e2bc47

File tree

3 files changed

+67
-10
lines changed

3 files changed

+67
-10
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,23 @@
1-
<template>
2-
<p>{{ $route.params.param }} - {{ $route.params.param }}</p>
3-
4-
<ErrorButton id="errorBtn" errorText="Error thrown from Param Route Button" />
5-
<button @click="fetchData">Fetch Server Data</button>
6-
</template>
7-
81
<script setup lang="ts">
92
import { useRoute, useFetch } from '#imports'
103
114
const route = useRoute();
125
const param = route.params.param;
136
14-
const fetchData = async () => {
7+
const fetchError = async () => {
158
await useFetch(`/api/param-error/${param}`);
169
}
10+
11+
const fetchData = async () => {
12+
await useFetch(`/api/test-param/${param}`);
13+
};
1714
</script>
15+
16+
<template>
17+
<p>Param: {{ $route.params.param }}</p>
18+
19+
<ErrorButton id="errorBtn" errorText="Error thrown from Param Route Button" />
20+
<button @click="fetchData">Fetch Server Data</button>
21+
<button @click="fetchError">Fetch Server Error</button>
22+
</template>
23+

dev-packages/e2e-tests/test-applications/nuxt-3/tests/errors.server.test.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ test.describe('server-side errors', async () => {
88
});
99

1010
await page.goto(`/fetch-server-error`);
11-
await page.getByText('Fetch Server Data').click();
11+
await page.getByText('Fetch Server Data', { exact: true }).click();
1212

1313
const error = await errorPromise;
1414

@@ -26,7 +26,7 @@ test.describe('server-side errors', async () => {
2626
});
2727

2828
await page.goto(`/test-param/1234`);
29-
await page.getByText('Fetch Server Data').click();
29+
await page.getByRole('button', { name: 'Fetch Server Error', exact: true }).click();
3030

3131
const error = await errorPromise;
3232

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
import { expect, test } from '@playwright/test';
2+
import { waitForTransaction } from '@sentry-internal/test-utils';
3+
4+
test.describe('distributed tracing', () => {
5+
const PARAM = 's0me-param';
6+
7+
test('capture a distributed pageload trace', async ({ page }) => {
8+
const clientTxnEventPromise = waitForTransaction('nuxt-3', txnEvent => {
9+
return txnEvent.transaction === '/test-param/:param()';
10+
});
11+
12+
const serverTxnEventPromise = waitForTransaction('nuxt-3', txnEvent => {
13+
return txnEvent.transaction.includes('GET /test-param/');
14+
});
15+
16+
const [_, clientTxnEvent, serverTxnEvent] = await Promise.all([
17+
page.goto(`/test-param/${PARAM}`),
18+
clientTxnEventPromise,
19+
serverTxnEventPromise,
20+
expect(page.getByText(`Param: ${PARAM}`)).toBeVisible(),
21+
]);
22+
23+
expect(clientTxnEvent).toMatchObject({
24+
transaction: '/test-param/:param()',
25+
transaction_info: { source: 'route' },
26+
type: 'transaction',
27+
contexts: {
28+
trace: {
29+
op: 'pageload',
30+
origin: 'auto.pageload.vue',
31+
},
32+
},
33+
});
34+
35+
expect(serverTxnEvent).toMatchObject({
36+
transaction: 'GET /test-param/s0me-param', // todo: parametrize (nitro)
37+
transaction_info: { source: 'url' },
38+
type: 'transaction',
39+
contexts: {
40+
trace: {
41+
op: 'http.server',
42+
origin: 'auto.http.otel.http',
43+
},
44+
},
45+
});
46+
47+
// connected trace
48+
expect(clientTxnEvent.contexts?.trace?.trace_id).toBe(serverTxnEvent.contexts?.trace?.trace_id);
49+
expect(clientTxnEvent.contexts?.trace?.parent_span_id).toBe(serverTxnEvent.contexts?.trace?.span_id);
50+
});
51+
});

0 commit comments

Comments
 (0)