Skip to content

Commit

Permalink
Add test
Browse files Browse the repository at this point in the history
  • Loading branch information
lforst committed Sep 9, 2024
1 parent 2a49c1a commit bbd3f1d
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { test } from '@playwright/test';
import { waitForTransaction } from '@sentry-internal/test-utils';

test('should create a transaction for a CJS pages router API endpoint', async ({ page }) => {
let received404Transaction = false;
waitForTransaction('nextjs-13', async transactionEvent => {
return transactionEvent.transaction === 'GET /404' || transactionEvent.transaction === 'GET /_not-found';
}).then(() => {
received404Transaction = true;
});

await page.goto('/page-that-doesnt-exist');

await new Promise<void>((resolve, reject) => {
setTimeout(() => {
if (received404Transaction) {
reject(new Error('received 404 transaction'));
} else {
resolve();
}
}, 5_000);
});
});
3 changes: 2 additions & 1 deletion packages/nextjs/src/server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,8 @@ export function init(options: NodeOptions): NodeClient | undefined {
// Pages router
event.transaction === '/404' ||
// App router (could be "GET /404", "POST /404", ...)
event.transaction?.match(/^(GET|HEAD|POST|PUT|DELETE|CONNECT|OPTIONS|TRACE|PATCH) \/404$/)
event.transaction?.match(/^(GET|HEAD|POST|PUT|DELETE|CONNECT|OPTIONS|TRACE|PATCH) \/404$/) ||
event.transaction === 'GET /_not-found'
) {
return null;
}
Expand Down

0 comments on commit bbd3f1d

Please sign in to comment.