-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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))
- Loading branch information
Showing
3 changed files
with
67 additions
and
10 deletions.
There are no files selected for viewing
22 changes: 14 additions & 8 deletions
22
dev-packages/e2e-tests/test-applications/nuxt-3/pages/test-param/[param].vue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,23 @@ | ||
<template> | ||
<p>{{ $route.params.param }} - {{ $route.params.param }}</p> | ||
|
||
<ErrorButton id="errorBtn" errorText="Error thrown from Param Route Button" /> | ||
<button @click="fetchData">Fetch Server Data</button> | ||
</template> | ||
|
||
<script setup lang="ts"> | ||
import { useRoute, useFetch } from '#imports' | ||
const route = useRoute(); | ||
const param = route.params.param; | ||
const fetchData = async () => { | ||
const fetchError = async () => { | ||
await useFetch(`/api/param-error/${param}`); | ||
} | ||
const fetchData = async () => { | ||
await useFetch(`/api/test-param/${param}`); | ||
}; | ||
</script> | ||
|
||
<template> | ||
<p>Param: {{ $route.params.param }}</p> | ||
|
||
<ErrorButton id="errorBtn" errorText="Error thrown from Param Route Button" /> | ||
<button @click="fetchData">Fetch Server Data</button> | ||
<button @click="fetchError">Fetch Server Error</button> | ||
</template> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
dev-packages/e2e-tests/test-applications/nuxt-3/tests/tracing.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import { expect, test } from '@playwright/test'; | ||
import { waitForTransaction } from '@sentry-internal/test-utils'; | ||
|
||
test.describe('distributed tracing', () => { | ||
const PARAM = 's0me-param'; | ||
|
||
test('capture a distributed pageload trace', async ({ page }) => { | ||
const clientTxnEventPromise = waitForTransaction('nuxt-3', txnEvent => { | ||
return txnEvent.transaction === '/test-param/:param()'; | ||
}); | ||
|
||
const serverTxnEventPromise = waitForTransaction('nuxt-3', txnEvent => { | ||
return txnEvent.transaction.includes('GET /test-param/'); | ||
}); | ||
|
||
const [_, clientTxnEvent, serverTxnEvent] = await Promise.all([ | ||
page.goto(`/test-param/${PARAM}`), | ||
clientTxnEventPromise, | ||
serverTxnEventPromise, | ||
expect(page.getByText(`Param: ${PARAM}`)).toBeVisible(), | ||
]); | ||
|
||
expect(clientTxnEvent).toMatchObject({ | ||
transaction: '/test-param/:param()', | ||
transaction_info: { source: 'route' }, | ||
type: 'transaction', | ||
contexts: { | ||
trace: { | ||
op: 'pageload', | ||
origin: 'auto.pageload.vue', | ||
}, | ||
}, | ||
}); | ||
|
||
expect(serverTxnEvent).toMatchObject({ | ||
transaction: 'GET /test-param/s0me-param', // todo: parametrize (nitro) | ||
transaction_info: { source: 'url' }, | ||
type: 'transaction', | ||
contexts: { | ||
trace: { | ||
op: 'http.server', | ||
origin: 'auto.http.otel.http', | ||
}, | ||
}, | ||
}); | ||
|
||
// connected trace | ||
expect(clientTxnEvent.contexts?.trace?.trace_id).toBe(serverTxnEvent.contexts?.trace?.trace_id); | ||
expect(clientTxnEvent.contexts?.trace?.parent_span_id).toBe(serverTxnEvent.contexts?.trace?.span_id); | ||
}); | ||
}); |