|
1 | 1 | import { expect, test } from '@playwright/test';
|
2 |
| -import { waitForTransaction } from '@sentry-internal/test-utils'; |
| 2 | +import { waitForError, waitForTransaction } from '@sentry-internal/test-utils'; |
3 | 3 |
|
4 | 4 | const packageJson = require('../package.json');
|
5 | 5 |
|
@@ -108,19 +108,49 @@ test('Should set not_found status for server actions calling notFound()', async
|
108 | 108 | const nextjsMajor = Number(nextjsVersion.split('.')[0]);
|
109 | 109 | test.skip(!isNaN(nextjsMajor) && nextjsMajor < 14, 'only applies to nextjs apps >= version 14');
|
110 | 110 |
|
111 |
| - const serverComponentTransactionPromise = waitForTransaction('nextjs-app-dir', async transactionEvent => { |
| 111 | + const serverActionTransactionPromise = waitForTransaction('nextjs-app-dir', async transactionEvent => { |
112 | 112 | return transactionEvent?.transaction === 'serverAction/notFoundServerAction';
|
113 | 113 | });
|
114 | 114 |
|
115 | 115 | await page.goto('/server-action');
|
116 | 116 | await page.getByText('Run NotFound Action').click();
|
117 | 117 |
|
118 |
| - const transactionEvent = await serverComponentTransactionPromise; |
| 118 | + const transactionEvent = await serverActionTransactionPromise; |
119 | 119 |
|
120 | 120 | expect(transactionEvent).toBeDefined();
|
121 | 121 | expect(transactionEvent.contexts?.trace?.status).toBe('not_found');
|
122 | 122 | });
|
123 | 123 |
|
| 124 | +test('Should not capture "NEXT_REDIRECT" control-flow errors for server actions calling redirect()', async ({ |
| 125 | + page, |
| 126 | +}) => { |
| 127 | + const nextjsVersion = packageJson.dependencies.next; |
| 128 | + const nextjsMajor = Number(nextjsVersion.split('.')[0]); |
| 129 | + test.skip(!isNaN(nextjsMajor) && nextjsMajor < 14, 'only applies to nextjs apps >= version 14'); |
| 130 | + |
| 131 | + const serverActionTransactionPromise = waitForTransaction('nextjs-app-dir', transactionEvent => { |
| 132 | + return transactionEvent?.transaction === 'serverAction/redirectServerAction'; |
| 133 | + }); |
| 134 | + |
| 135 | + let controlFlowErrorCaptured = false; |
| 136 | + waitForError('nextjs-app-dir', errorEvent => { |
| 137 | + if (errorEvent.exception?.values?.[0].value === 'NEXT_REDIRECT') { |
| 138 | + controlFlowErrorCaptured = true; |
| 139 | + } |
| 140 | + |
| 141 | + return false; |
| 142 | + }); |
| 143 | + |
| 144 | + await page.goto('/server-action'); |
| 145 | + await page.getByText('Run Redirect Action').click(); |
| 146 | + |
| 147 | + const serverActionTransactionEvent = await serverActionTransactionPromise; |
| 148 | + expect(serverActionTransactionEvent).toBeDefined(); |
| 149 | + |
| 150 | + // By the time the server action span finishes the error should already have been sent |
| 151 | + expect(controlFlowErrorCaptured).toBe(false); |
| 152 | +}); |
| 153 | + |
124 | 154 | test('Will not include spans in pageload transaction with faulty timestamps for slow loading pages', async ({
|
125 | 155 | page,
|
126 | 156 | }) => {
|
|
0 commit comments