Skip to content

Commit d2c6d80

Browse files
committed
test: added e2e tests
1 parent 58b607f commit d2c6d80

File tree

8 files changed

+268
-0
lines changed

8 files changed

+268
-0
lines changed
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
export async function generateStaticParams(): Promise<Array<{ product: string }>> {
2+
return [{ product: 'laptop' }, { product: 'phone' }, { product: 'tablet' }];
3+
}
4+
5+
export default async function ISRProductPage({ params }: { params: Promise<{ product: string }> }) {
6+
const { product } = await params;
7+
8+
return (
9+
<div>
10+
<h1>ISR Product: {product}</h1>
11+
<div id="isr-product-id">{product}</div>
12+
</div>
13+
);
14+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
export async function generateStaticParams(): Promise<never[]> {
2+
return [];
3+
}
4+
5+
export default function ISRStaticPage() {
6+
return (
7+
<div>
8+
<h1>ISR Static Page</h1>
9+
<div id="isr-static-marker">static-isr</div>
10+
</div>
11+
);
12+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// No generateStaticParams - this is NOT an ISR page
2+
export default async function NonISRPage({ params }: { params: Promise<{ item: string }> }) {
3+
const { item } = await params;
4+
5+
return (
6+
<div>
7+
<h1>Non-ISR Dynamic Page: {item}</h1>
8+
<div id="non-isr-item-id">{item}</div>
9+
</div>
10+
);
11+
}
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
import { expect, test } from '@playwright/test';
2+
import { waitForTransaction } from '@sentry-internal/test-utils';
3+
4+
test('should remove sentry-trace and baggage meta tags on ISR dynamic route page load', async ({ page }) => {
5+
// Navigate to ISR page
6+
await page.goto('/isr-test/laptop');
7+
8+
// Wait for page to be fully loaded
9+
await expect(page.locator('#isr-product-id')).toHaveText('laptop');
10+
11+
// Check that sentry-trace and baggage meta tags are removed for ISR pages
12+
await expect(page.locator('meta[name="sentry-trace"]')).toHaveCount(0);
13+
await expect(page.locator('meta[name="baggage"]')).toHaveCount(0);
14+
});
15+
16+
test('should remove sentry-trace and baggage meta tags on ISR static route', async ({ page }) => {
17+
// Navigate to ISR static page
18+
await page.goto('/isr-test/static');
19+
20+
// Wait for page to be fully loaded
21+
await expect(page.locator('#isr-static-marker')).toHaveText('static-isr');
22+
23+
// Check that sentry-trace and baggage meta tags are removed for ISR pages
24+
await expect(page.locator('meta[name="sentry-trace"]')).toHaveCount(0);
25+
await expect(page.locator('meta[name="baggage"]')).toHaveCount(0);
26+
});
27+
28+
test('should remove meta tags for different ISR dynamic route values', async ({ page }) => {
29+
// Test with 'phone' (one of the pre-generated static params)
30+
await page.goto('/isr-test/phone');
31+
await expect(page.locator('#isr-product-id')).toHaveText('phone');
32+
33+
await expect(page.locator('meta[name="sentry-trace"]')).toHaveCount(0);
34+
await expect(page.locator('meta[name="baggage"]')).toHaveCount(0);
35+
36+
// Test with 'tablet'
37+
await page.goto('/isr-test/tablet');
38+
await expect(page.locator('#isr-product-id')).toHaveText('tablet');
39+
40+
await expect(page.locator('meta[name="sentry-trace"]')).toHaveCount(0);
41+
await expect(page.locator('meta[name="baggage"]')).toHaveCount(0);
42+
});
43+
44+
test('should create unique transactions for ISR pages (not using stale trace IDs)', async ({ page }) => {
45+
// First navigation - capture the trace ID
46+
const firstTransactionPromise = waitForTransaction('nextjs-15', async transactionEvent => {
47+
return transactionEvent.transaction === '/isr-test/:product' && transactionEvent.contexts?.trace?.op === 'pageload';
48+
});
49+
50+
await page.goto('/isr-test/laptop');
51+
const firstTransaction = await firstTransactionPromise;
52+
const firstTraceId = firstTransaction.contexts?.trace?.trace_id;
53+
54+
expect(firstTraceId).toBeDefined();
55+
expect(firstTraceId).toMatch(/[a-f0-9]{32}/);
56+
57+
// Second navigation to the same ISR route with different param
58+
const secondTransactionPromise = waitForTransaction('nextjs-15', async transactionEvent => {
59+
return !!(
60+
transactionEvent.transaction === '/isr-test/:product' &&
61+
transactionEvent.contexts?.trace?.op === 'pageload' &&
62+
transactionEvent.request?.url?.includes('/isr-test/phone')
63+
);
64+
});
65+
66+
await page.goto('/isr-test/phone');
67+
const secondTransaction = await secondTransactionPromise;
68+
const secondTraceId = secondTransaction.contexts?.trace?.trace_id;
69+
70+
expect(secondTraceId).toBeDefined();
71+
expect(secondTraceId).toMatch(/[a-f0-9]{32}/);
72+
73+
// Verify that each page load gets a NEW trace ID (not reusing cached/stale ones)
74+
expect(firstTraceId).not.toBe(secondTraceId);
75+
});
76+
77+
test('ISR route should be identified correctly in the route manifest', async ({ page }) => {
78+
const transactionPromise = waitForTransaction('nextjs-15', async transactionEvent => {
79+
return transactionEvent.transaction === '/isr-test/:product' && transactionEvent.contexts?.trace?.op === 'pageload';
80+
});
81+
82+
await page.goto('/isr-test/laptop');
83+
const transaction = await transactionPromise;
84+
85+
// Verify the transaction is properly parameterized
86+
expect(transaction).toMatchObject({
87+
transaction: '/isr-test/:product',
88+
transaction_info: { source: 'route' },
89+
contexts: {
90+
trace: {
91+
data: {
92+
'sentry.source': 'route',
93+
},
94+
},
95+
},
96+
});
97+
});
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
export async function generateStaticParams(): Promise<Array<{ product: string }>> {
2+
return [{ product: 'laptop' }, { product: 'phone' }, { product: 'tablet' }];
3+
}
4+
5+
export default async function ISRProductPage({ params }: { params: Promise<{ product: string }> }) {
6+
const { product } = await params;
7+
8+
return (
9+
<div>
10+
<h1>ISR Product: {product}</h1>
11+
<div id="isr-product-id">{product}</div>
12+
</div>
13+
);
14+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
export async function generateStaticParams(): Promise<never[]> {
2+
return [];
3+
}
4+
5+
export default function ISRStaticPage() {
6+
return (
7+
<div>
8+
<h1>ISR Static Page</h1>
9+
<div id="isr-static-marker">static-isr</div>
10+
</div>
11+
);
12+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// No generateStaticParams - this is NOT an ISR page
2+
export default async function NonISRPage({ params }: { params: Promise<{ item: string }> }) {
3+
const { item } = await params;
4+
5+
return (
6+
<div>
7+
<h1>Non-ISR Dynamic Page: {item}</h1>
8+
<div id="non-isr-item-id">{item}</div>
9+
</div>
10+
);
11+
}
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
import { expect, test } from '@playwright/test';
2+
import { waitForTransaction } from '@sentry-internal/test-utils';
3+
4+
test('should remove sentry-trace and baggage meta tags on ISR dynamic route page load', async ({ page }) => {
5+
// Navigate to ISR page
6+
await page.goto('/isr-test/laptop');
7+
8+
// Wait for page to be fully loaded
9+
await expect(page.locator('#isr-product-id')).toHaveText('laptop');
10+
11+
// Check that sentry-trace and baggage meta tags are removed for ISR pages
12+
await expect(page.locator('meta[name="sentry-trace"]')).toHaveCount(0);
13+
await expect(page.locator('meta[name="baggage"]')).toHaveCount(0);
14+
});
15+
16+
test('should remove sentry-trace and baggage meta tags on ISR static route', async ({ page }) => {
17+
// Navigate to ISR static page
18+
await page.goto('/isr-test/static');
19+
20+
// Wait for page to be fully loaded
21+
await expect(page.locator('#isr-static-marker')).toHaveText('static-isr');
22+
23+
// Check that sentry-trace and baggage meta tags are removed for ISR pages
24+
await expect(page.locator('meta[name="sentry-trace"]')).toHaveCount(0);
25+
await expect(page.locator('meta[name="baggage"]')).toHaveCount(0);
26+
});
27+
28+
test('should remove meta tags for different ISR dynamic route values', async ({ page }) => {
29+
// Test with 'phone' (one of the pre-generated static params)
30+
await page.goto('/isr-test/phone');
31+
await expect(page.locator('#isr-product-id')).toHaveText('phone');
32+
33+
await expect(page.locator('meta[name="sentry-trace"]')).toHaveCount(0);
34+
await expect(page.locator('meta[name="baggage"]')).toHaveCount(0);
35+
36+
// Test with 'tablet'
37+
await page.goto('/isr-test/tablet');
38+
await expect(page.locator('#isr-product-id')).toHaveText('tablet');
39+
40+
await expect(page.locator('meta[name="sentry-trace"]')).toHaveCount(0);
41+
await expect(page.locator('meta[name="baggage"]')).toHaveCount(0);
42+
});
43+
44+
test('should create unique transactions for ISR pages (not using stale trace IDs)', async ({ page }) => {
45+
// First navigation - capture the trace ID
46+
const firstTransactionPromise = waitForTransaction('nextjs-16', async transactionEvent => {
47+
return transactionEvent.transaction === '/isr-test/:product' && transactionEvent.contexts?.trace?.op === 'pageload';
48+
});
49+
50+
await page.goto('/isr-test/laptop');
51+
const firstTransaction = await firstTransactionPromise;
52+
const firstTraceId = firstTransaction.contexts?.trace?.trace_id;
53+
54+
expect(firstTraceId).toBeDefined();
55+
expect(firstTraceId).toMatch(/[a-f0-9]{32}/);
56+
57+
// Second navigation to the same ISR route with different param
58+
const secondTransactionPromise = waitForTransaction('nextjs-16', async transactionEvent => {
59+
return !!(
60+
transactionEvent.transaction === '/isr-test/:product' &&
61+
transactionEvent.contexts?.trace?.op === 'pageload' &&
62+
transactionEvent.request?.url?.includes('/isr-test/phone')
63+
);
64+
});
65+
66+
await page.goto('/isr-test/phone');
67+
const secondTransaction = await secondTransactionPromise;
68+
const secondTraceId = secondTransaction.contexts?.trace?.trace_id;
69+
70+
expect(secondTraceId).toBeDefined();
71+
expect(secondTraceId).toMatch(/[a-f0-9]{32}/);
72+
73+
// Verify that each page load gets a NEW trace ID (not reusing cached/stale ones)
74+
expect(firstTraceId).not.toBe(secondTraceId);
75+
});
76+
77+
test('ISR route should be identified correctly in the route manifest', async ({ page }) => {
78+
const transactionPromise = waitForTransaction('nextjs-16', async transactionEvent => {
79+
return transactionEvent.transaction === '/isr-test/:product' && transactionEvent.contexts?.trace?.op === 'pageload';
80+
});
81+
82+
await page.goto('/isr-test/laptop');
83+
const transaction = await transactionPromise;
84+
85+
// Verify the transaction is properly parameterized
86+
expect(transaction).toMatchObject({
87+
transaction: '/isr-test/:product',
88+
transaction_info: { source: 'route' },
89+
contexts: {
90+
trace: {
91+
data: {
92+
'sentry.source': 'route',
93+
},
94+
},
95+
},
96+
});
97+
});

0 commit comments

Comments
 (0)