Skip to content

Commit 9e676e0

Browse files
authored
test(browser-integration): Add sentry DSN route handler by default (#14095)
Instead of sprinkling this through tests, we can just generally handle this route, streamlining tests a bit and avoid unexpected errors/console warnings messing with things. So this PR basically inverses this - by default, we add a "success" route handler for the Sentry DSN, and if you want to have special handling you can opt-out of this. Supersedes https://github.com/getsentry/sentry-javascript/pull/14092/files
1 parent c7378e6 commit 9e676e0

File tree

102 files changed

+45
-1141
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

102 files changed

+45
-1141
lines changed

dev-packages/browser-integration-tests/loader-suites/loader/noOnLoad/replay/test.ts

-8
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,6 @@ sentryTest('should capture a replay', async ({ getLocalTestUrl, page }) => {
1111
sentryTest.skip();
1212
}
1313

14-
await page.route('https://dsn.ingest.sentry.io/**/*', route => {
15-
return route.fulfill({
16-
status: 200,
17-
contentType: 'application/json',
18-
body: JSON.stringify({ id: 'test-id' }),
19-
});
20-
});
21-
2214
const req = waitForReplayRequest(page);
2315

2416
const url = await getLocalTestUrl({ testDir: __dirname });

dev-packages/browser-integration-tests/loader-suites/loader/noOnLoad/replayError/test.ts

-8
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,6 @@ sentryTest('should capture a replay & attach an error', async ({ getLocalTestUrl
99
sentryTest.skip();
1010
}
1111

12-
await page.route('https://dsn.ingest.sentry.io/**/*', route => {
13-
return route.fulfill({
14-
status: 200,
15-
contentType: 'application/json',
16-
body: JSON.stringify({ id: 'test-id' }),
17-
});
18-
});
19-
2012
const req = waitForReplayRequest(page);
2113

2214
const url = await getLocalTestUrl({ testDir: __dirname });

dev-packages/browser-integration-tests/loader-suites/loader/noOnLoad/sdkLoadedInMeanwhile/test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ sentryTest('it does not download the SDK if the SDK was loaded in the meanwhile'
2828
});
2929
});
3030

31-
const tmpDir = await getLocalTestUrl({ testDir: __dirname, skipRouteHandler: true });
31+
const tmpDir = await getLocalTestUrl({ testDir: __dirname, skipRouteHandler: true, skipDsnRouteHandler: true });
3232

3333
await page.route(`${TEST_HOST}/*.*`, route => {
3434
const file = route.request().url().split('/').pop();

dev-packages/browser-integration-tests/loader-suites/loader/onLoad/captureExceptionInOnLoad/test.ts

-16
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,6 @@ import { sentryTest } from '../../../../utils/fixtures';
44
import { envelopeRequestParser, waitForErrorRequestOnUrl } from '../../../../utils/helpers';
55

66
sentryTest('captureException works inside of onLoad', async ({ getLocalTestUrl, page }) => {
7-
await page.route('https://dsn.ingest.sentry.io/**/*', route => {
8-
return route.fulfill({
9-
status: 200,
10-
contentType: 'application/json',
11-
body: JSON.stringify({ id: 'test-id' }),
12-
});
13-
});
14-
157
const url = await getLocalTestUrl({ testDir: __dirname });
168
const req = await waitForErrorRequestOnUrl(page, url);
179

@@ -21,14 +13,6 @@ sentryTest('captureException works inside of onLoad', async ({ getLocalTestUrl,
2113
});
2214

2315
sentryTest('should set SENTRY_SDK_SOURCE value', async ({ getLocalTestUrl, page }) => {
24-
await page.route('https://dsn.ingest.sentry.io/**/*', route => {
25-
return route.fulfill({
26-
status: 200,
27-
contentType: 'application/json',
28-
body: JSON.stringify({ id: 'test-id' }),
29-
});
30-
});
31-
3216
const url = await getLocalTestUrl({ testDir: __dirname });
3317
const req = await waitForErrorRequestOnUrl(page, url);
3418

dev-packages/browser-integration-tests/loader-suites/loader/onLoad/customInit/test.ts

-8
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,6 @@ const bundle = process.env.PW_BUNDLE || '';
77
const isLazy = LOADER_CONFIGS[bundle]?.lazy;
88

99
sentryTest('always calls onLoad init correctly', async ({ getLocalTestUrl, page }) => {
10-
await page.route('https://dsn.ingest.sentry.io/**/*', route => {
11-
return route.fulfill({
12-
status: 200,
13-
contentType: 'application/json',
14-
body: JSON.stringify({ id: 'test-id' }),
15-
});
16-
});
17-
1810
const url = await getLocalTestUrl({ testDir: __dirname });
1911

2012
await page.goto(url);

dev-packages/browser-integration-tests/loader-suites/loader/onLoad/customIntegrations/test.ts

-8
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,6 @@ sentryTest('should handle custom added integrations & default integrations', asy
88
const shouldHaveReplay = !shouldSkipReplayTest();
99
const shouldHaveBrowserTracing = !shouldSkipTracingTest();
1010

11-
await page.route('https://dsn.ingest.sentry.io/**/*', route => {
12-
return route.fulfill({
13-
status: 200,
14-
contentType: 'application/json',
15-
body: JSON.stringify({ id: 'test-id' }),
16-
});
17-
});
18-
1911
const url = await getLocalTestUrl({ testDir: __dirname });
2012
await page.goto(url);
2113

dev-packages/browser-integration-tests/loader-suites/loader/onLoad/customIntegrationsFunction/test.ts

-8
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,6 @@ import { sentryTest } from '../../../../utils/fixtures';
55
sentryTest(
66
'should not add default integrations if integrations function is provided',
77
async ({ getLocalTestUrl, page }) => {
8-
await page.route('https://dsn.ingest.sentry.io/**/*', route => {
9-
return route.fulfill({
10-
status: 200,
11-
contentType: 'application/json',
12-
body: JSON.stringify({ id: 'test-id' }),
13-
});
14-
});
15-
168
const url = await getLocalTestUrl({ testDir: __dirname });
179
await page.goto(url);
1810

dev-packages/browser-integration-tests/loader-suites/loader/onLoad/customReplay/test.ts

-8
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,6 @@ sentryTest('should handle custom added Replay integration', async ({ getLocalTes
88
sentryTest.skip();
99
}
1010

11-
await page.route('https://dsn.ingest.sentry.io/**/*', route => {
12-
return route.fulfill({
13-
status: 200,
14-
contentType: 'application/json',
15-
body: JSON.stringify({ id: 'test-id' }),
16-
});
17-
});
18-
1911
const req = waitForReplayRequest(page);
2012

2113
const url = await getLocalTestUrl({ testDir: __dirname });

dev-packages/browser-integration-tests/loader-suites/loader/onLoad/keepSentryGlobal/test.ts

-8
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,6 @@ import { sentryTest } from '../../../../utils/fixtures';
44
import { envelopeRequestParser, waitForErrorRequestOnUrl } from '../../../../utils/helpers';
55

66
sentryTest('keeps data on window.Sentry intact', async ({ getLocalTestUrl, page }) => {
7-
await page.route('https://dsn.ingest.sentry.io/**/*', route => {
8-
return route.fulfill({
9-
status: 200,
10-
contentType: 'application/json',
11-
body: JSON.stringify({ id: 'test-id' }),
12-
});
13-
});
14-
157
const url = await getLocalTestUrl({ testDir: __dirname });
168
const req = await waitForErrorRequestOnUrl(page, url);
179

dev-packages/browser-integration-tests/loader-suites/loader/onLoad/onLoadLate/test.ts

-8
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,6 @@ import { sentryTest } from '../../../../utils/fixtures';
44
import { envelopeRequestParser, waitForErrorRequestOnUrl } from '../../../../utils/helpers';
55

66
sentryTest('late onLoad call is handled', async ({ getLocalTestUrl, page }) => {
7-
await page.route('https://dsn.ingest.sentry.io/**/*', route => {
8-
return route.fulfill({
9-
status: 200,
10-
contentType: 'application/json',
11-
body: JSON.stringify({ id: 'test-id' }),
12-
});
13-
});
14-
157
const url = await getLocalTestUrl({ testDir: __dirname });
168
const req = await waitForErrorRequestOnUrl(page, url);
179

dev-packages/browser-integration-tests/loader-suites/loader/onLoad/replay/test.ts

-8
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,6 @@ sentryTest('should capture a replay', async ({ getLocalTestUrl, page }) => {
88
sentryTest.skip();
99
}
1010

11-
await page.route('https://dsn.ingest.sentry.io/**/*', route => {
12-
return route.fulfill({
13-
status: 200,
14-
contentType: 'application/json',
15-
body: JSON.stringify({ id: 'test-id' }),
16-
});
17-
});
18-
1911
const req = waitForReplayRequest(page);
2012

2113
const url = await getLocalTestUrl({ testDir: __dirname });

dev-packages/browser-integration-tests/suites/feedback/attachTo/test.ts

-8
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,6 @@ sentryTest('should capture feedback with custom button', async ({ getLocalTestUr
2323
}
2424
});
2525

26-
await page.route('https://dsn.ingest.sentry.io/**/*', route => {
27-
return route.fulfill({
28-
status: 200,
29-
contentType: 'application/json',
30-
body: JSON.stringify({ id: 'test-id' }),
31-
});
32-
});
33-
3426
const url = await getLocalTestUrl({ testDir: __dirname });
3527

3628
await page.goto(url);

dev-packages/browser-integration-tests/suites/feedback/captureFeedback/test.ts

-8
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,6 @@ sentryTest('should capture feedback', async ({ getLocalTestUrl, page }) => {
2323
}
2424
});
2525

26-
await page.route('https://dsn.ingest.sentry.io/**/*', route => {
27-
return route.fulfill({
28-
status: 200,
29-
contentType: 'application/json',
30-
body: JSON.stringify({ id: 'test-id' }),
31-
});
32-
});
33-
3426
const url = await getLocalTestUrl({ testDir: __dirname });
3527

3628
await page.goto(url);

dev-packages/browser-integration-tests/suites/feedback/captureFeedbackAndReplay/hasSampling/test.ts

-8
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,6 @@ sentryTest('should capture feedback', async ({ forceFlushReplay, getLocalTestUrl
3131
}
3232
});
3333

34-
await page.route('https://dsn.ingest.sentry.io/**/*', route => {
35-
return route.fulfill({
36-
status: 200,
37-
contentType: 'application/json',
38-
body: JSON.stringify({ id: 'test-id' }),
39-
});
40-
});
41-
4234
const url = await getLocalTestUrl({ testDir: __dirname });
4335

4436
await Promise.all([page.goto(url), page.getByText('Report a Bug').click(), reqPromise0]);

dev-packages/browser-integration-tests/suites/feedback/captureFeedbackCsp/test.ts

-8
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,6 @@ sentryTest('should capture feedback', async ({ getLocalTestUrl, page }) => {
2323
}
2424
});
2525

26-
await page.route('https://dsn.ingest.sentry.io/**/*', route => {
27-
return route.fulfill({
28-
status: 200,
29-
contentType: 'application/json',
30-
body: JSON.stringify({ id: 'test-id' }),
31-
});
32-
});
33-
3426
const url = await getLocalTestUrl({ testDir: __dirname });
3527

3628
await page.goto(url);

dev-packages/browser-integration-tests/suites/feedback/logger/test.ts

-8
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,6 @@ sentryTest('should log error correctly', async ({ getLocalTestUrl, page }) => {
1919
messages.push(message.text());
2020
});
2121

22-
await page.route('https://dsn.ingest.sentry.io/**/*', route => {
23-
return route.fulfill({
24-
status: 200,
25-
contentType: 'application/json',
26-
body: JSON.stringify({ id: 'test-id' }),
27-
});
28-
});
29-
3022
const url = await getLocalTestUrl({ testDir: __dirname });
3123

3224
await page.goto(url);

dev-packages/browser-integration-tests/suites/integrations/captureConsole/test.ts

-8
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,6 @@ import { getMultipleSentryEnvelopeRequests } from '../../../utils/helpers';
77
sentryTest('it captures console messages correctly', async ({ getLocalTestUrl, page }) => {
88
const url = await getLocalTestUrl({ testDir: __dirname });
99

10-
await page.route('https://dsn.ingest.sentry.io/**/*', route => {
11-
return route.fulfill({
12-
status: 200,
13-
contentType: 'application/json',
14-
body: JSON.stringify({ id: 'test-id' }),
15-
});
16-
});
17-
1810
const [, events] = await Promise.all([page.goto(url), getMultipleSentryEnvelopeRequests<Event>(page, 7)]);
1911

2012
expect(events).toHaveLength(7);

dev-packages/browser-integration-tests/suites/manual-client/skip-init-browser-extension/test.ts

-8
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,6 @@ import { sentryTest } from '../../../utils/fixtures';
44
sentryTest(
55
'should not initialize when inside a Firefox/Safari browser extension',
66
async ({ getLocalTestUrl, page }) => {
7-
await page.route('https://dsn.ingest.sentry.io/**/*', route => {
8-
return route.fulfill({
9-
status: 200,
10-
contentType: 'application/json',
11-
body: JSON.stringify({ id: 'test-id' }),
12-
});
13-
});
14-
157
const errorLogs: string[] = [];
168

179
page.on('console', message => {

dev-packages/browser-integration-tests/suites/manual-client/skip-init-chrome-extension/test.ts

-8
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,6 @@ import { expect } from '@playwright/test';
22
import { sentryTest } from '../../../utils/fixtures';
33

44
sentryTest('should not initialize when inside a Chrome browser extension', async ({ getLocalTestUrl, page }) => {
5-
await page.route('https://dsn.ingest.sentry.io/**/*', route => {
6-
return route.fulfill({
7-
status: 200,
8-
contentType: 'application/json',
9-
body: JSON.stringify({ id: 'test-id' }),
10-
});
11-
});
12-
135
const errorLogs: string[] = [];
146

157
page.on('console', message => {

dev-packages/browser-integration-tests/suites/metrics/metricsShim/test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ sentryTest('exports shim metrics integration for non-tracing bundles', async ({
2222
});
2323
});
2424

25-
const url = await getLocalTestPath({ testDir: __dirname });
25+
const url = await getLocalTestPath({ testDir: __dirname, skipDsnRouteHandler: true });
2626

2727
await page.goto(url);
2828

dev-packages/browser-integration-tests/suites/metrics/timing/test.ts

-16
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,6 @@ sentryTest('allows to wrap sync methods with a timing metric', async ({ getLocal
1313
sentryTest.skip();
1414
}
1515

16-
await page.route('https://dsn.ingest.sentry.io/**/*', route => {
17-
return route.fulfill({
18-
status: 200,
19-
contentType: 'application/json',
20-
body: JSON.stringify({ id: 'test-id' }),
21-
});
22-
});
23-
2416
const url = await getLocalTestUrl({ testDir: __dirname });
2517

2618
const beforeTime = Math.floor(Date.now() / 1000);
@@ -96,14 +88,6 @@ sentryTest('allows to wrap async methods with a timing metric', async ({ getLoca
9688
sentryTest.skip();
9789
}
9890

99-
await page.route('https://dsn.ingest.sentry.io/**/*', route => {
100-
return route.fulfill({
101-
status: 200,
102-
contentType: 'application/json',
103-
body: JSON.stringify({ id: 'test-id' }),
104-
});
105-
});
106-
10791
const url = await getLocalTestUrl({ testDir: __dirname });
10892

10993
const beforeTime = Math.floor(Date.now() / 1000);

dev-packages/browser-integration-tests/suites/replay/bufferModeManual/test.ts

+3-19
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ sentryTest(
4545
});
4646
});
4747

48-
const url = await getLocalTestPath({ testDir: __dirname });
48+
const url = await getLocalTestPath({ testDir: __dirname, skipDsnRouteHandler: true });
4949

5050
await page.goto(url);
5151
await page.locator('#go-background').click();
@@ -190,7 +190,7 @@ sentryTest(
190190
});
191191
});
192192

193-
const url = await getLocalTestPath({ testDir: __dirname });
193+
const url = await getLocalTestPath({ testDir: __dirname, skipDsnRouteHandler: true });
194194

195195
await page.goto(url);
196196
await page.locator('#go-background').click();
@@ -297,14 +297,6 @@ sentryTest(
297297

298298
const reqPromise0 = waitForReplayRequest(page, 0);
299299

300-
await page.route('https://dsn.ingest.sentry.io/**/*', route => {
301-
return route.fulfill({
302-
status: 200,
303-
contentType: 'application/json',
304-
body: JSON.stringify({ id: 'test-id' }),
305-
});
306-
});
307-
308300
const url = await getLocalTestUrl({ testDir: __dirname });
309301

310302
await page.goto(url);
@@ -359,14 +351,6 @@ sentryTest(
359351

360352
const reqPromise0 = waitForReplayRequest(page, 0);
361353

362-
await page.route('https://dsn.ingest.sentry.io/**/*', route => {
363-
return route.fulfill({
364-
status: 200,
365-
contentType: 'application/json',
366-
body: JSON.stringify({ id: 'test-id' }),
367-
});
368-
});
369-
370354
const url = await getLocalTestUrl({ testDir: __dirname });
371355

372356
page.goto(url);
@@ -440,7 +424,7 @@ sentryTest(
440424
});
441425
});
442426

443-
const url = await getLocalTestPath({ testDir: __dirname });
427+
const url = await getLocalTestPath({ testDir: __dirname, skipDsnRouteHandler: true });
444428

445429
await page.goto(url);
446430
// Start buffering and assert that it is enabled

0 commit comments

Comments
 (0)