Skip to content

Commit 8b2c0c2

Browse files
authored
test(nextjs): Add e2e tests for server component spans in next 16 (#18544)
closes #18396 also removed some remaining debug logs in other tests, because why not
1 parent 3d58496 commit 8b2c0c2

File tree

9 files changed

+112
-3
lines changed

9 files changed

+112
-3
lines changed

dev-packages/e2e-tests/test-applications/nextjs-15/tests/route-handler.test.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import { waitForTransaction } from '@sentry-internal/test-utils';
33

44
test('Should create a transaction for node route handlers', async ({ request }) => {
55
const routehandlerTransactionPromise = waitForTransaction('nextjs-15', async transactionEvent => {
6-
console.log(transactionEvent?.transaction);
76
return transactionEvent?.transaction === 'GET /route-handler/[xoxo]/node';
87
});
98

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { PropsWithChildren } from 'react';
2+
3+
export const dynamic = 'force-dynamic';
4+
5+
export default function Layout({ children }: PropsWithChildren<{}>) {
6+
return (
7+
<div>
8+
<p>Layout</p>
9+
{children}
10+
</div>
11+
);
12+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { PropsWithChildren } from 'react';
2+
3+
export const dynamic = 'force-dynamic';
4+
5+
export default function Layout({ children }: PropsWithChildren<{}>) {
6+
return (
7+
<div>
8+
<p>DynamicLayout</p>
9+
{children}
10+
</div>
11+
);
12+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
export const dynamic = 'force-dynamic';
2+
3+
export default async function Page() {
4+
return (
5+
<div>
6+
<p>Dynamic Page</p>
7+
</div>
8+
);
9+
}
10+
11+
export async function generateMetadata() {
12+
return {
13+
title: 'I am dynamic page generated metadata',
14+
};
15+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { PropsWithChildren } from 'react';
2+
3+
export const dynamic = 'force-dynamic';
4+
5+
export default function Layout({ children }: PropsWithChildren<{}>) {
6+
return (
7+
<div>
8+
<p>Layout</p>
9+
{children}
10+
</div>
11+
);
12+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
export const dynamic = 'force-dynamic';
2+
3+
export default function Page() {
4+
return <p>Hello World!</p>;
5+
}
6+
7+
export async function generateMetadata() {
8+
return {
9+
title: 'I am generated metadata',
10+
};
11+
}

dev-packages/e2e-tests/test-applications/nextjs-16/tests/route-handler.test.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import { waitForTransaction } from '@sentry-internal/test-utils';
33

44
test('Should create a transaction for node route handlers', async ({ request }) => {
55
const routehandlerTransactionPromise = waitForTransaction('nextjs-16', async transactionEvent => {
6-
console.log(transactionEvent?.transaction);
76
return transactionEvent?.transaction === 'GET /route-handler/[xoxo]/node';
87
});
98

dev-packages/e2e-tests/test-applications/nextjs-16/tests/server-components.test.ts

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,3 +46,53 @@ test('Sends a transaction for a request to app router with URL', async ({ page }
4646
}),
4747
).toHaveLength(0);
4848
});
49+
50+
test('Will create a transaction with spans for every server component and metadata generation functions when visiting a page', async ({
51+
page,
52+
}) => {
53+
const serverTransactionEventPromise = waitForTransaction('nextjs-16', async transactionEvent => {
54+
return transactionEvent?.transaction === 'GET /nested-layout';
55+
});
56+
57+
await page.goto('/nested-layout');
58+
59+
const spanDescriptions = (await serverTransactionEventPromise).spans?.map(span => {
60+
return span.description;
61+
});
62+
63+
expect(spanDescriptions).toContainEqual('render route (app) /nested-layout');
64+
expect(spanDescriptions).toContainEqual('build component tree');
65+
expect(spanDescriptions).toContainEqual('resolve root layout server component');
66+
expect(spanDescriptions).toContainEqual('resolve layout server component "(nested-layout)"');
67+
expect(spanDescriptions).toContainEqual('resolve layout server component "nested-layout"');
68+
expect(spanDescriptions).toContainEqual('resolve page server component "/nested-layout"');
69+
expect(spanDescriptions).toContainEqual('generateMetadata /(nested-layout)/nested-layout/page');
70+
expect(spanDescriptions).toContainEqual('start response');
71+
expect(spanDescriptions).toContainEqual('NextNodeServer.clientComponentLoading');
72+
});
73+
74+
test('Will create a transaction with spans for every server component and metadata generation functions when visiting a dynamic page', async ({
75+
page,
76+
}) => {
77+
const serverTransactionEventPromise = waitForTransaction('nextjs-16', async transactionEvent => {
78+
return transactionEvent?.transaction === 'GET /nested-layout/[dynamic]';
79+
});
80+
81+
await page.goto('/nested-layout/123');
82+
83+
const spanDescriptions = (await serverTransactionEventPromise).spans?.map(span => {
84+
return span.description;
85+
});
86+
87+
expect(spanDescriptions).toContainEqual('resolve page components');
88+
expect(spanDescriptions).toContainEqual('render route (app) /nested-layout/[dynamic]');
89+
expect(spanDescriptions).toContainEqual('build component tree');
90+
expect(spanDescriptions).toContainEqual('resolve root layout server component');
91+
expect(spanDescriptions).toContainEqual('resolve layout server component "(nested-layout)"');
92+
expect(spanDescriptions).toContainEqual('resolve layout server component "nested-layout"');
93+
expect(spanDescriptions).toContainEqual('resolve layout server component "[dynamic]"');
94+
expect(spanDescriptions).toContainEqual('resolve page server component "/nested-layout/[dynamic]"');
95+
expect(spanDescriptions).toContainEqual('generateMetadata /(nested-layout)/nested-layout/[dynamic]/page');
96+
expect(spanDescriptions).toContainEqual('start response');
97+
expect(spanDescriptions).toContainEqual('NextNodeServer.clientComponentLoading');
98+
});

dev-packages/e2e-tests/test-applications/nextjs-app-dir/tests/connected-servercomponent-trace.test.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ test('Will create a transaction with spans for every server component and metada
3535
page,
3636
}) => {
3737
const serverTransactionEventPromise = waitForTransaction('nextjs-app-dir', async transactionEvent => {
38-
console.log(transactionEvent?.transaction);
3938
return transactionEvent?.transaction === 'GET /nested-layout/[dynamic]';
4039
});
4140

0 commit comments

Comments
 (0)