Skip to content

Commit 516f632

Browse files
authored
test(browser): Avoid making requests to http://example.com` (#15059)
The `http` version of example.com seems to have become unstable, even for the preflight CORS requests the browser makes. This PR adds a couple of `page.route` proxies to ensure we don't actually send requests to example.com. Also, I found a test which previously wasn't failing when the assertions didn't pass
1 parent e28d491 commit 516f632

File tree

3 files changed

+20
-16
lines changed
  • dev-packages/browser-integration-tests/suites/tracing/request

3 files changed

+20
-16
lines changed

dev-packages/browser-integration-tests/suites/tracing/request/fetch-with-request/test.ts

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -10,21 +10,19 @@ sentryTest(
1010
sentryTest.skip();
1111
}
1212

13-
await page.route('**/api/test/', async route => {
14-
const req = route.request();
15-
const headers = await req.allHeaders();
16-
17-
// headers.bar was set in fetch options (and should be sent)
18-
expect(headers.bar).toBe('22');
19-
// headers.foo was set in init request object (and should be ignored)
20-
expect(headers.foo).toBeUndefined();
21-
22-
return route.fulfill({
23-
status: 200,
24-
body: 'ok',
25-
});
26-
});
27-
28-
await getLocalTestUrl({ testDir: __dirname });
13+
const requestPromise = page.waitForRequest('http://example.com/api/test/');
14+
15+
const url = await getLocalTestUrl({ testDir: __dirname });
16+
17+
await page.goto(url);
18+
19+
const request = await requestPromise;
20+
21+
const headers = await request.allHeaders();
22+
23+
// headers.bar was set in fetch options (and should be sent)
24+
expect(headers.bar).toBe('22');
25+
// headers.foo was set in init request object (and should be ignored)
26+
expect(headers.foo).toBeUndefined();
2927
},
3028
);

dev-packages/browser-integration-tests/suites/tracing/request/fetch/test.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ sentryTest('should create spans for fetch requests', async ({ getLocalTestUrl, p
1111
sentryTest.skip();
1212
}
1313

14+
await page.route('http://example.com/*', route => route.fulfill({ body: 'ok' }));
15+
1416
const url = await getLocalTestUrl({ testDir: __dirname });
1517

1618
const req = await waitForTransactionRequestOnUrl(page, url);
@@ -44,6 +46,8 @@ sentryTest('should attach `sentry-trace` header to fetch requests', async ({ get
4446
sentryTest.skip();
4547
}
4648

49+
await page.route('http://example.com/*', route => route.fulfill({ body: 'ok' }));
50+
4751
const url = await getLocalTestUrl({ testDir: __dirname });
4852

4953
const requests = (

dev-packages/browser-integration-tests/suites/tracing/request/xhr/test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ sentryTest('should create spans for XHR requests', async ({ getLocalTestUrl, pag
99
sentryTest.skip();
1010
}
1111

12+
await page.route('http://example.com/*', route => route.fulfill({ body: 'ok' }));
13+
1214
const url = await getLocalTestUrl({ testDir: __dirname });
1315

1416
const eventData = await getFirstSentryEnvelopeRequest<Event>(page, url);

0 commit comments

Comments
 (0)