Skip to content

Commit ae913ff

Browse files
author
Luca Forstner
committed
test(nextjs): Fix Next.js canary tests
1 parent ecc95e7 commit ae913ff

File tree

4 files changed

+18
-4
lines changed

4 files changed

+18
-4
lines changed

dev-packages/e2e-tests/test-applications/nextjs-14/app/propagation/test-outgoing-fetch-external-disallowed/route.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ import { NextResponse } from 'next/server';
33
export const dynamic = 'force-dynamic';
44

55
export async function GET() {
6-
const data = await fetch(`http://localhost:3030/propagation/test-outgoing-fetch-external-disallowed/check`).then(
7-
res => res.json(),
8-
);
6+
const data = await fetch(`http://localhost:3030/propagation/test-outgoing-fetch-external-disallowed/check`, {
7+
cache: 'no-store',
8+
}).then(res => res.json());
99
return NextResponse.json(data);
1010
}

dev-packages/e2e-tests/test-applications/nextjs-14/app/propagation/test-outgoing-fetch/route.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ import { NextResponse } from 'next/server';
33
export const dynamic = 'force-dynamic';
44

55
export async function GET() {
6-
const data = await fetch(`http://localhost:3030/propagation/test-outgoing-fetch/check`).then(res => res.json());
6+
const data = await fetch(`http://localhost:3030/propagation/test-outgoing-fetch/check`, { cache: 'no-store' }).then(
7+
res => res.json(),
8+
);
79
return NextResponse.json(data);
810
}

dev-packages/e2e-tests/test-applications/nextjs-app-dir/tests/client-errors.test.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
import { expect, test } from '@playwright/test';
22
import { waitForError } from '@sentry-internal/test-utils';
33

4+
const packageJson = require('../package.json');
5+
46
test('Sends a client-side exception to Sentry', async ({ page }) => {
7+
const nextjsVersion = packageJson.dependencies.next;
8+
const nextjsMajor = Number(nextjsVersion.split('.')[0]);
9+
510
await page.goto('/');
611

712
const errorEventPromise = waitForError('nextjs-app-dir', errorEvent => {
@@ -23,6 +28,8 @@ test('Sends a client-side exception to Sentry', async ({ page }) => {
2328
expect(errorEvent.transaction).toEqual('/');
2429

2530
expect(errorEvent.contexts?.trace).toEqual({
31+
// Next.js >= 15 propagates a trace ID to the client via a meta tag.
32+
parent_span_id: nextjsMajor >= 15 ? expect.any(String) : undefined,
2633
trace_id: expect.any(String),
2734
span_id: expect.any(String),
2835
});

dev-packages/e2e-tests/test-applications/nextjs-app-dir/tests/transactions.test.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ import { waitForTransaction } from '@sentry-internal/test-utils';
44
const packageJson = require('../package.json');
55

66
test('Sends a pageload transaction', async ({ page }) => {
7+
const nextjsVersion = packageJson.dependencies.next;
8+
const nextjsMajor = Number(nextjsVersion.split('.')[0]);
9+
710
const pageloadTransactionEventPromise = waitForTransaction('nextjs-app-dir', transactionEvent => {
811
return transactionEvent?.contexts?.trace?.op === 'pageload' && transactionEvent?.transaction === '/';
912
});
@@ -23,6 +26,8 @@ test('Sends a pageload transaction', async ({ page }) => {
2326
version: expect.any(String),
2427
},
2528
trace: {
29+
// Next.js >= 15 propagates a trace ID to the client via a meta tag.
30+
parent_span_id: nextjsMajor >= 15 ? expect.any(String) : undefined,
2631
span_id: expect.any(String),
2732
trace_id: expect.any(String),
2833
op: 'pageload',

0 commit comments

Comments
 (0)