Skip to content

Commit 1cfbe38

Browse files
committed
add new tests (connected tracing)
1 parent 05ecade commit 1cfbe38

File tree

7 files changed

+81
-24
lines changed

7 files changed

+81
-24
lines changed

dev-packages/e2e-tests/test-applications/nuxt-4/app/pages/client-error.vue

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ import ErrorButton from '../components/ErrorButton.vue';
33
</script>
44

55
<template>
6-
<ErrorButton id="errorBtn" error-text="Error thrown from nuxt-4 E2E test app"/>
7-
<ErrorButton id="errorBtn2" error-text="Another Error thrown from nuxt-4 E2E test app"/>
6+
<ErrorButton id="errorBtn" error-text="Error thrown from Nuxt-4 E2E test app"/>
7+
<ErrorButton id="errorBtn2" error-text="Another Error thrown from Nuxt-4 E2E test app"/>
88
</template>
99

1010

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+
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { defineEventHandler } from '#imports';
22

33
export default defineEventHandler(_e => {
4-
throw new Error('Nuxt 3 Param Server error');
4+
throw new Error('Nuxt 4 Param Server error');
55
});
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { defineEventHandler } from '#imports';
22

33
export default defineEventHandler(event => {
4-
throw new Error('Nuxt 3 Server error');
4+
throw new Error('Nuxt 4 Server error');
55
});

dev-packages/e2e-tests/test-applications/nuxt-4/tests/errors.client.test.ts

+6-6
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { waitForError } from '@sentry-internal/test-utils';
44
test.describe('client-side errors', async () => {
55
test('captures error thrown on click', async ({ page }) => {
66
const errorPromise = waitForError('nuxt-4', async errorEvent => {
7-
return errorEvent?.exception?.values?.[0]?.value === 'Error thrown from nuxt-4 E2E test app';
7+
return errorEvent?.exception?.values?.[0]?.value === 'Error thrown from Nuxt-4 E2E test app';
88
});
99

1010
await page.goto(`/client-error`);
@@ -18,7 +18,7 @@ test.describe('client-side errors', async () => {
1818
values: [
1919
{
2020
type: 'Error',
21-
value: 'Error thrown from nuxt-4 E2E test app',
21+
value: 'Error thrown from Nuxt-4 E2E test app',
2222
mechanism: {
2323
handled: false,
2424
},
@@ -58,7 +58,7 @@ test.describe('client-side errors', async () => {
5858

5959
test('page is still interactive after client error', async ({ page }) => {
6060
const error1Promise = waitForError('nuxt-4', async errorEvent => {
61-
return errorEvent?.exception?.values?.[0]?.value === 'Error thrown from nuxt-4 E2E test app';
61+
return errorEvent?.exception?.values?.[0]?.value === 'Error thrown from Nuxt-4 E2E test app';
6262
});
6363

6464
await page.goto(`/client-error`);
@@ -67,7 +67,7 @@ test.describe('client-side errors', async () => {
6767
const error1 = await error1Promise;
6868

6969
const error2Promise = waitForError('nuxt-4', async errorEvent => {
70-
return errorEvent?.exception?.values?.[0]?.value === 'Another Error thrown from nuxt-4 E2E test app';
70+
return errorEvent?.exception?.values?.[0]?.value === 'Another Error thrown from Nuxt-4 E2E test app';
7171
});
7272

7373
await page.locator('#errorBtn2').click();
@@ -79,7 +79,7 @@ test.describe('client-side errors', async () => {
7979
values: [
8080
{
8181
type: 'Error',
82-
value: 'Error thrown from nuxt-4 E2E test app',
82+
value: 'Error thrown from Nuxt-4 E2E test app',
8383
mechanism: {
8484
handled: false,
8585
},
@@ -93,7 +93,7 @@ test.describe('client-side errors', async () => {
9393
values: [
9494
{
9595
type: 'Error',
96-
value: 'Another Error thrown from nuxt-4 E2E test app',
96+
value: 'Another Error thrown from Nuxt-4 E2E test app',
9797
mechanism: {
9898
handled: false,
9999
},

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

+6-6
Original file line numberDiff line numberDiff line change
@@ -4,37 +4,37 @@ import { waitForError } from '@sentry-internal/test-utils';
44
test.describe('server-side errors', async () => {
55
test('captures api fetch error (fetched on click)', async ({ page }) => {
66
const errorPromise = waitForError('nuxt-4', async errorEvent => {
7-
return errorEvent?.exception?.values?.[0]?.value === 'Nuxt 3 Server error';
7+
return errorEvent?.exception?.values?.[0]?.value === 'Nuxt 4 Server error';
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

1515
expect(error.transaction).toEqual('GET /api/server-error');
1616

1717
const exception = error.exception.values[0];
1818
expect(exception.type).toEqual('Error');
19-
expect(exception.value).toEqual('Nuxt 3 Server error');
19+
expect(exception.value).toEqual('Nuxt 4 Server error');
2020
expect(exception.mechanism.handled).toBe(false);
2121
});
2222

2323
test('captures api fetch error (fetched on click) with parametrized route', async ({ page }) => {
2424
const errorPromise = waitForError('nuxt-4', async errorEvent => {
25-
return errorEvent?.exception?.values?.[0]?.value === 'Nuxt 3 Param Server error';
25+
return errorEvent?.exception?.values?.[0]?.value === 'Nuxt 4 Param Server error';
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

3333
expect(error.transaction).toEqual('GET /api/param-error/1234');
3434

3535
const exception = error.exception.values[0];
3636
expect(exception.type).toEqual('Error');
37-
expect(exception.value).toEqual('Nuxt 3 Param Server error');
37+
expect(exception.value).toEqual('Nuxt 4 Param Server error');
3838
expect(exception.mechanism.handled).toBe(false);
3939
});
4040
});
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-4', txnEvent => {
9+
return txnEvent.transaction === '/test-param/:param()';
10+
});
11+
12+
const serverTxnEventPromise = waitForTransaction('nuxt-4', 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)