Skip to content

Commit d7538cd

Browse files
authored
test(nuxt): Update Nuxt version and add Nitro $fetch test (#17713)
This PR adds the following: - an E2E test case for Nitro `$fetch` requests - Upgrading the Nuxt 4 version (previously in alpha) - Deleting the `app.vue` file as this is not needed when using the `app/pages` directory (following the [Nuxt docs](https://nuxt.com/docs/4.x/guide/directory-structure/app/app))
1 parent d024907 commit d7538cd

File tree

7 files changed

+49
-24
lines changed

7 files changed

+49
-24
lines changed

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

Lines changed: 0 additions & 20 deletions
This file was deleted.

dev-packages/e2e-tests/test-applications/nuxt-4/app/pages/fetch-server-error.vue renamed to dev-packages/e2e-tests/test-applications/nuxt-4/app/pages/fetch-server-routes.vue

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<template>
22
<div>
33
<button @click="fetchError">Fetch Server API Error</button>
4+
<button @click="fetchNitroFetch">Fetch Nitro $fetch</button>
45
</div>
56
</template>
67

@@ -10,4 +11,8 @@ import { useFetch } from '#imports';
1011
const fetchError = async () => {
1112
await useFetch('/api/server-error');
1213
};
14+
15+
const fetchNitroFetch = async () => {
16+
await useFetch('/api/nitro-fetch');
17+
};
1318
</script>
Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,20 @@
11
<template>
2-
<h1>Hello!</h1>
2+
<NuxtLayout>
3+
<header>
4+
<nav>
5+
<ul>
6+
<li><NuxtLink to="/fetch-server-routes">Fetch Server Routes</NuxtLink></li>
7+
<li><NuxtLink to="/test-param/1234">Fetch Param</NuxtLink></li>
8+
<li><NuxtLink to="/client-error">Client Error</NuxtLink></li>
9+
</ul>
10+
</nav>
11+
</header>
12+
<NuxtPage />
13+
</NuxtLayout>
314
</template>
15+
16+
<script setup lang="ts">
17+
import { useSentryTestTag } from '#imports';
18+
19+
useSentryTestTag();
20+
</script>

dev-packages/e2e-tests/test-applications/nuxt-4/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
"dependencies": {
1919
"@pinia/nuxt": "^0.5.5",
2020
"@sentry/nuxt": "latest || *",
21-
"nuxt": "^4.0.0-alpha.4"
21+
"nuxt": "^4.1.2"
2222
},
2323
"devDependencies": {
2424
"@playwright/test": "~1.53.2",
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import { defineEventHandler } from '#imports';
2+
3+
export default defineEventHandler(async () => {
4+
return await $fetch('https://example.com');
5+
});

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ test.describe('server-side errors', async () => {
77
return errorEvent?.exception?.values?.[0]?.value === 'Nuxt 4 Server error';
88
});
99

10-
await page.goto(`/fetch-server-error`);
10+
await page.goto(`/fetch-server-routes`);
1111
await page.getByText('Fetch Server API Error', { exact: true }).click();
1212

1313
const error = await errorPromise;

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

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { expect, test } from '@playwright/test';
2-
import { waitForTransaction } from '@sentry-internal/test-utils';
2+
import { waitForError, waitForTransaction } from '@sentry-internal/test-utils';
33
import { SEMANTIC_ATTRIBUTE_SENTRY_OP, SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN } from '@sentry/nuxt';
44

55
test('sends a server action transaction on pageload', async ({ page }) => {
@@ -43,3 +43,21 @@ test('does not send transactions for build asset folder "_nuxt"', async ({ page
4343

4444
expect(transactionEvent.transaction).toBe('GET /test-param/:param()');
4545
});
46+
47+
test('captures server API calls made with Nitro $fetch', async ({ page }) => {
48+
const transactionPromise = waitForTransaction('nuxt-4', async transactionEvent => {
49+
return transactionEvent.transaction === 'GET /api/nitro-fetch';
50+
});
51+
52+
await page.goto(`/fetch-server-routes`);
53+
await page.getByText('Fetch Nitro $fetch', { exact: true }).click();
54+
55+
const httpServerFetchSpan = await transactionPromise;
56+
const httpClientSpan = httpServerFetchSpan.spans.find(span => span.description === 'GET https://example.com/');
57+
58+
expect(httpServerFetchSpan.transaction).toEqual('GET /api/nitro-fetch');
59+
expect(httpServerFetchSpan.contexts.trace.op).toEqual('http.server');
60+
61+
expect(httpClientSpan.parent_span_id).toEqual(httpServerFetchSpan.contexts.trace.span_id);
62+
expect(httpClientSpan.op).toEqual('http.client');
63+
});

0 commit comments

Comments
 (0)