Skip to content

Commit 2e3ae56

Browse files
author
Luca Forstner
authored
test(nextjs): Fix Next.js canary tests (#12792)
1 parent 4c54a79 commit 2e3ae56

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
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+
const isDevMode = process.env.TEST_ENV === 'development';
10+
511
await page.goto('/');
612

713
const errorEventPromise = waitForError('nextjs-app-dir', errorEvent => {
@@ -23,6 +29,9 @@ test('Sends a client-side exception to Sentry', async ({ page }) => {
2329
expect(errorEvent.transaction).toEqual('/');
2430

2531
expect(errorEvent.contexts?.trace).toEqual({
32+
// Next.js >= 15 propagates a trace ID to the client via a meta tag. Also, only dev mode emits a meta tag because
33+
// the requested page is static and only in dev mode SSR is kicked off.
34+
parent_span_id: nextjsMajor >= 15 && isDevMode ? expect.any(String) : undefined,
2635
trace_id: expect.any(String),
2736
span_id: expect.any(String),
2837
});

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ 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+
const isDevMode = process.env.TEST_ENV === 'development';
10+
711
const pageloadTransactionEventPromise = waitForTransaction('nextjs-app-dir', transactionEvent => {
812
return transactionEvent?.contexts?.trace?.op === 'pageload' && transactionEvent?.transaction === '/';
913
});
@@ -23,6 +27,9 @@ test('Sends a pageload transaction', async ({ page }) => {
2327
version: expect.any(String),
2428
},
2529
trace: {
30+
// Next.js >= 15 propagates a trace ID to the client via a meta tag. Also, only dev mode emits a meta tag because
31+
// the requested page is static and only in dev mode SSR is kicked off.
32+
parent_span_id: nextjsMajor >= 15 && isDevMode ? expect.any(String) : undefined,
2633
span_id: expect.any(String),
2734
trace_id: expect.any(String),
2835
op: 'pageload',

0 commit comments

Comments
 (0)