Skip to content

Commit 56c916f

Browse files
committed
Standardize test case
1 parent 58e6f4f commit 56c916f

File tree

5 files changed

+52
-26
lines changed

5 files changed

+52
-26
lines changed

dev-packages/e2e-tests/README.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,3 +133,22 @@ A standardized frontend test application has the following features:
133133
### Standardized Backend Test Apps
134134

135135
TBD
136+
137+
### Standardized Frontend-to-Backend Test Apps
138+
139+
A standardized Meta test application has the following features:
140+
141+
- Has a parameterized backend API route `/user/:id` that returns a JSON object with the user ID.
142+
- Has a parameterized frontend page (can be SSR) `/user/:id` that fetches the user data on the client-side from the API route and displays it.
143+
144+
The following test cases for connected tracing should be implemented in the test app:
145+
146+
- Capturing a distributed page load trace when a page is loaded
147+
- The HTML meta-tag should include the Sentry trace data and baggage
148+
- The server root span should be the parent of the client pageload span
149+
- All routes (server and client) should be parameterized, e.g. `/user/5` should be captured as `/user/:id` route
150+
- Capturing a distributed trace when requesting the API from the client-side
151+
- There should be three transactions involved: the client pageload, the server "pageload", and the server API request
152+
- The client pageload should include an `http.client` span that is the parent of the server API request span
153+
- All three transactions and the `http.client` span should share the same `trace_id`
154+
- All `transaction` names and the `span` description should be parameterized, e.g. `/user/5` should be captured as `/user/:id` route

dev-packages/e2e-tests/test-applications/nuxt-4/app/pages/test-param/fetch-api/[param].vue

Lines changed: 0 additions & 16 deletions
This file was deleted.
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<script setup lang="ts">
2+
import { useFetch, useRoute } from '#imports';
3+
4+
const route = useRoute();
5+
const userId = route.params.userId as string;
6+
7+
const { data } = await useFetch(`/api/user/${userId}`, {
8+
server: false, // Don't fetch during SSR, only client-side
9+
});
10+
</script>
11+
12+
<template>
13+
<div>
14+
<p v-if="data">User ID: {{ data }}</p>
15+
</div>
16+
</template>
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import { defineEventHandler, getRouterParam } from '#imports';
2+
3+
export default defineEventHandler(event => {
4+
const userId = getRouterParam(event, 'userId');
5+
6+
return `UserId Param: ${userId}!`;
7+
});

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

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -69,30 +69,30 @@ test.describe('distributed tracing', () => {
6969

7070
test('capture a distributed trace from a client-side API request with parametrized routes', async ({ page }) => {
7171
const clientTxnEventPromise = waitForTransaction('nuxt-4', txnEvent => {
72-
return txnEvent.transaction === '/test-param/fetch-api/:param()';
72+
return txnEvent.transaction === '/test-param/user/:userId()';
7373
});
7474
const ssrTxnEventPromise = waitForTransaction('nuxt-4', txnEvent => {
75-
return txnEvent.transaction?.includes('GET /test-param/fetch-api') ?? false;
75+
return txnEvent.transaction?.includes('GET /test-param/user') ?? false;
7676
});
7777
const serverReqTxnEventPromise = waitForTransaction('nuxt-4', txnEvent => {
78-
return txnEvent.transaction?.includes('GET /api/test-param/') ?? false;
78+
return txnEvent.transaction?.includes('GET /api/user/') ?? false;
7979
});
8080

8181
// Navigate to the page which will trigger an API call from the client-side
82-
await page.goto(`/test-param/fetch-api/${PARAM}`);
82+
await page.goto(`/test-param/user/${PARAM}`);
8383

8484
const [clientTxnEvent, ssrTxnEvent, serverReqTxnEvent] = await Promise.all([
8585
clientTxnEventPromise,
8686
ssrTxnEventPromise,
8787
serverReqTxnEventPromise,
8888
]);
8989

90-
const httpClientSpan = clientTxnEvent?.spans?.find(span => span.description === `GET /api/test-param/${PARAM}`);
90+
const httpClientSpan = clientTxnEvent?.spans?.find(span => span.description === `GET /api/user/${PARAM}`);
9191

9292
expect(clientTxnEvent).toEqual(
9393
expect.objectContaining({
9494
type: 'transaction',
95-
transaction: '/test-param/fetch-api/:param()', // parametrized route
95+
transaction: '/test-param/user/:userId()', // parametrized route
9696
transaction_info: { source: 'route' },
9797
contexts: expect.objectContaining({
9898
trace: expect.objectContaining({
@@ -106,10 +106,10 @@ test.describe('distributed tracing', () => {
106106
expect(httpClientSpan).toBeDefined();
107107
expect(httpClientSpan).toEqual(
108108
expect.objectContaining({
109-
description: `GET /api/test-param/${PARAM}`, // fixme: parametrize
109+
description: `GET /api/user/${PARAM}`, // fixme: parametrize
110110
parent_span_id: clientTxnEvent.contexts?.trace?.span_id, // pageload span is parent
111111
data: expect.objectContaining({
112-
url: `/api/test-param/${PARAM}`, // fixme: parametrize
112+
url: `/api/user/${PARAM}`,
113113
type: 'fetch',
114114
'sentry.op': 'http.client',
115115
'sentry.origin': 'auto.http.browser',
@@ -121,7 +121,7 @@ test.describe('distributed tracing', () => {
121121
expect(ssrTxnEvent).toEqual(
122122
expect.objectContaining({
123123
type: 'transaction',
124-
transaction: `GET /test-param/fetch-api/${PARAM}`, // fixme: parametrize (nitro)
124+
transaction: `GET /test-param/user/${PARAM}`, // fixme: parametrize (nitro)
125125
transaction_info: { source: 'url' },
126126
contexts: expect.objectContaining({
127127
trace: expect.objectContaining({
@@ -135,7 +135,7 @@ test.describe('distributed tracing', () => {
135135
expect(serverReqTxnEvent).toEqual(
136136
expect.objectContaining({
137137
type: 'transaction',
138-
transaction: `GET /api/test-param/${PARAM}`,
138+
transaction: `GET /api/user/${PARAM}`,
139139
transaction_info: { source: 'url' },
140140
contexts: expect.objectContaining({
141141
trace: expect.objectContaining({

0 commit comments

Comments
 (0)