|
| 1 | +import { expect, test } from '@playwright/test'; |
| 2 | +import { waitForError, waitForTransaction } from '@sentry-internal/test-utils'; |
| 3 | + |
| 4 | +test('Should handle server action redirect without capturing errors', async ({ page }) => { |
| 5 | + // Wait for the initial page load transaction |
| 6 | + const pageLoadTransactionPromise = waitForTransaction('nextjs-15', async transactionEvent => { |
| 7 | + return transactionEvent?.transaction === '/redirect/origin'; |
| 8 | + }); |
| 9 | + |
| 10 | + // Navigate to the origin page |
| 11 | + await page.goto('/redirect/origin'); |
| 12 | + |
| 13 | + const pageLoadTransaction = await pageLoadTransactionPromise; |
| 14 | + expect(pageLoadTransaction).toBeDefined(); |
| 15 | + |
| 16 | + // Wait for the redirect transaction |
| 17 | + const redirectTransactionPromise = waitForTransaction('nextjs-15', async transactionEvent => { |
| 18 | + return transactionEvent?.transaction === 'GET /redirect/destination'; |
| 19 | + }); |
| 20 | + |
| 21 | + // No error should be captured |
| 22 | + const redirectErrorPromise = waitForError('nextjs-15', async errorEvent => { |
| 23 | + return !!errorEvent; |
| 24 | + }); |
| 25 | + |
| 26 | + // Click the redirect button |
| 27 | + await page.click('button[type="submit"]'); |
| 28 | + |
| 29 | + await redirectTransactionPromise; |
| 30 | + |
| 31 | + // Verify we got redirected to the destination page |
| 32 | + await expect(page).toHaveURL('/redirect/destination'); |
| 33 | + |
| 34 | + // Wait for potential errors with a 2 second timeout |
| 35 | + const errorTimeout = new Promise((_, reject) => |
| 36 | + setTimeout(() => reject(new Error('No error captured (timeout)')), 2000), |
| 37 | + ); |
| 38 | + |
| 39 | + // We expect this to timeout since no error should be captured during the redirect |
| 40 | + try { |
| 41 | + await Promise.race([redirectErrorPromise, errorTimeout]); |
| 42 | + throw new Error('Expected no error to be captured, but an error was found'); |
| 43 | + } catch (e) { |
| 44 | + // If we get a timeout error (as expected), no error was captured |
| 45 | + expect((e as Error).message).toBe('No error captured (timeout)'); |
| 46 | + } |
| 47 | +}); |
0 commit comments