Skip to content

Commit a597ea0

Browse files
committed
test(replay): Fix flakey extendNetworkBreadcrumbs/fetch tests
See #11140
1 parent 643eff2 commit a597ea0

File tree

4 files changed

+146
-128
lines changed
  • dev-packages/browser-integration-tests/suites/replay/extendNetworkBreadcrumbs/fetch

4 files changed

+146
-128
lines changed

dev-packages/browser-integration-tests/suites/replay/extendNetworkBreadcrumbs/fetch/captureRequestHeaders/test.ts

Lines changed: 54 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,7 @@ import {
88
shouldSkipReplayTest,
99
} from '../../../../../utils/replayHelpers';
1010

11-
// Skipping because this test is flaky
12-
// https://github.com/getsentry/sentry-javascript/issues/11062
13-
sentryTest.skip('handles empty/missing request headers', async ({ getLocalTestPath, page, browserName }) => {
11+
sentryTest('handles empty/missing request headers', async ({ getLocalTestPath, page, browserName }) => {
1412
if (shouldSkipReplayTest()) {
1513
sentryTest.skip();
1614
}
@@ -37,18 +35,20 @@ sentryTest.skip('handles empty/missing request headers', async ({ getLocalTestPa
3735
const url = await getLocalTestPath({ testDir: __dirname });
3836
await page.goto(url);
3937

40-
await page.evaluate(() => {
41-
/* eslint-disable */
42-
fetch('http://localhost:7654/foo', {
43-
method: 'POST',
44-
}).then(() => {
45-
// @ts-expect-error Sentry is a global
46-
Sentry.captureException('test error');
47-
});
48-
/* eslint-enable */
49-
});
38+
const [, request] = await Promise.all([
39+
page.evaluate(() => {
40+
/* eslint-disable */
41+
fetch('http://localhost:7654/foo', {
42+
method: 'POST',
43+
}).then(() => {
44+
// @ts-expect-error Sentry is a global
45+
Sentry.captureException('test error');
46+
});
47+
/* eslint-enable */
48+
}),
49+
requestPromise,
50+
]);
5051

51-
const request = await requestPromise;
5252
const eventData = envelopeRequestParser(request);
5353

5454
expect(eventData.exception?.values).toHaveLength(1);
@@ -110,25 +110,27 @@ sentryTest('captures request headers as POJO', async ({ getLocalTestPath, page,
110110
const url = await getLocalTestPath({ testDir: __dirname });
111111
await page.goto(url);
112112

113-
await page.evaluate(() => {
114-
/* eslint-disable */
115-
fetch('http://localhost:7654/foo', {
116-
method: 'POST',
117-
headers: {
118-
Accept: 'application/json',
119-
'Content-Type': 'application/json',
120-
Cache: 'no-cache',
121-
'X-Custom-Header': 'foo',
122-
'X-Test-Header': 'test-value',
123-
},
124-
}).then(() => {
125-
// @ts-expect-error Sentry is a global
126-
Sentry.captureException('test error');
127-
});
128-
/* eslint-enable */
129-
});
113+
const [, request] = await Promise.all([
114+
page.evaluate(() => {
115+
/* eslint-disable */
116+
fetch('http://localhost:7654/foo', {
117+
method: 'POST',
118+
headers: {
119+
Accept: 'application/json',
120+
'Content-Type': 'application/json',
121+
Cache: 'no-cache',
122+
'X-Custom-Header': 'foo',
123+
'X-Test-Header': 'test-value',
124+
},
125+
}).then(() => {
126+
// @ts-expect-error Sentry is a global
127+
Sentry.captureException('test error');
128+
});
129+
/* eslint-enable */
130+
}),
131+
requestPromise,
132+
]);
130133

131-
const request = await requestPromise;
132134
const eventData = envelopeRequestParser(request);
133135

134136
expect(eventData.exception?.values).toHaveLength(1);
@@ -364,25 +366,27 @@ sentryTest('does not captures request headers if URL does not match', async ({ g
364366
const url = await getLocalTestPath({ testDir: __dirname });
365367
await page.goto(url);
366368

367-
await page.evaluate(() => {
368-
/* eslint-disable */
369-
fetch('http://localhost:7654/bar', {
370-
method: 'POST',
371-
headers: {
372-
Accept: 'application/json',
373-
'Content-Type': 'application/json',
374-
Cache: 'no-cache',
375-
'X-Custom-Header': 'foo',
376-
'X-Test-Header': 'test-value',
377-
},
378-
}).then(() => {
379-
// @ts-expect-error Sentry is a global
380-
Sentry.captureException('test error');
381-
});
382-
/* eslint-enable */
383-
});
369+
const [, request] = await Promise.all([
370+
page.evaluate(() => {
371+
/* eslint-disable */
372+
fetch('http://localhost:7654/bar', {
373+
method: 'POST',
374+
headers: {
375+
Accept: 'application/json',
376+
'Content-Type': 'application/json',
377+
Cache: 'no-cache',
378+
'X-Custom-Header': 'foo',
379+
'X-Test-Header': 'test-value',
380+
},
381+
}).then(() => {
382+
// @ts-expect-error Sentry is a global
383+
Sentry.captureException('test error');
384+
});
385+
/* eslint-enable */
386+
}),
387+
requestPromise,
388+
]);
384389

385-
const request = await requestPromise;
386390
const eventData = envelopeRequestParser(request);
387391

388392
expect(eventData.exception?.values).toHaveLength(1);

dev-packages/browser-integration-tests/suites/replay/extendNetworkBreadcrumbs/fetch/captureRequestSize/test.ts

Lines changed: 30 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,7 @@ import {
88
shouldSkipReplayTest,
99
} from '../../../../../utils/replayHelpers';
1010

11-
// Skipping because this test is flaky
12-
// https://github.com/getsentry/sentry-javascript/issues/10395
13-
sentryTest.skip('captures request body size when body is sent', async ({ getLocalTestPath, page }) => {
11+
sentryTest('captures request body size when body is sent', async ({ getLocalTestPath, page }) => {
1412
if (shouldSkipReplayTest()) {
1513
sentryTest.skip();
1614
}
@@ -37,19 +35,21 @@ sentryTest.skip('captures request body size when body is sent', async ({ getLoca
3735
const url = await getLocalTestPath({ testDir: __dirname });
3836
await page.goto(url);
3937

40-
await page.evaluate(() => {
41-
/* eslint-disable */
42-
fetch('http://localhost:7654/foo', {
43-
method: 'POST',
44-
body: '{"foo":"bar"}',
45-
}).then(() => {
46-
// @ts-expect-error Sentry is a global
47-
Sentry.captureException('test error');
48-
});
49-
/* eslint-enable */
50-
});
38+
const [, request] = await Promise.all([
39+
page.evaluate(() => {
40+
/* eslint-disable */
41+
fetch('http://localhost:7654/foo', {
42+
method: 'POST',
43+
body: '{"foo":"bar"}',
44+
}).then(() => {
45+
// @ts-expect-error Sentry is a global
46+
Sentry.captureException('test error');
47+
});
48+
/* eslint-enable */
49+
}),
50+
requestPromise,
51+
]);
5152

52-
const request = await requestPromise;
5353
const eventData = envelopeRequestParser(request);
5454

5555
expect(eventData.exception?.values).toHaveLength(1);
@@ -122,21 +122,23 @@ sentryTest('captures request size from non-text request body', async ({ getLocal
122122
const url = await getLocalTestPath({ testDir: __dirname });
123123
await page.goto(url);
124124

125-
await page.evaluate(() => {
126-
/* eslint-disable */
127-
const blob = new Blob(['<html>Hello world!!</html>'], { type: 'text/html' });
125+
const [, request] = await Promise.all([
126+
page.evaluate(() => {
127+
/* eslint-disable */
128+
const blob = new Blob(['<html>Hello world!!</html>'], { type: 'text/html' });
128129

129-
fetch('http://localhost:7654/foo', {
130-
method: 'POST',
131-
body: blob,
132-
}).then(() => {
133-
// @ts-expect-error Sentry is a global
134-
Sentry.captureException('test error');
135-
});
136-
/* eslint-enable */
137-
});
130+
fetch('http://localhost:7654/foo', {
131+
method: 'POST',
132+
body: blob,
133+
}).then(() => {
134+
// @ts-expect-error Sentry is a global
135+
Sentry.captureException('test error');
136+
});
137+
/* eslint-enable */
138+
}),
139+
requestPromise,
140+
]);
138141

139-
const request = await requestPromise;
140142
const eventData = envelopeRequestParser(request);
141143

142144
expect(eventData.exception?.values).toHaveLength(1);

dev-packages/browser-integration-tests/suites/replay/extendNetworkBreadcrumbs/fetch/captureResponseHeaders/test.ts

Lines changed: 27 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -37,14 +37,16 @@ sentryTest('handles empty headers', async ({ getLocalTestPath, page, browserName
3737
const url = await getLocalTestPath({ testDir: __dirname });
3838
await page.goto(url);
3939

40-
await page.evaluate(() => {
41-
fetch('http://localhost:7654/foo').then(() => {
42-
// @ts-expect-error Sentry is a global
43-
Sentry.captureException('test error');
44-
});
45-
});
40+
const [, request] = await Promise.all([
41+
page.evaluate(() => {
42+
fetch('http://localhost:7654/foo').then(() => {
43+
// @ts-expect-error Sentry is a global
44+
Sentry.captureException('test error');
45+
});
46+
}),
47+
requestPromise,
48+
]);
4649

47-
const request = await requestPromise;
4850
const eventData = envelopeRequestParser(request);
4951

5052
expect(eventData.exception?.values).toHaveLength(1);
@@ -111,14 +113,16 @@ sentryTest('captures response headers', async ({ getLocalTestPath, page }) => {
111113
const url = await getLocalTestPath({ testDir: __dirname });
112114
await page.goto(url);
113115

114-
await page.evaluate(() => {
115-
fetch('http://localhost:7654/foo').then(() => {
116-
// @ts-expect-error Sentry is a global
117-
Sentry.captureException('test error');
118-
});
119-
});
116+
const [, request] = await Promise.all([
117+
page.evaluate(() => {
118+
fetch('http://localhost:7654/foo').then(() => {
119+
// @ts-expect-error Sentry is a global
120+
Sentry.captureException('test error');
121+
});
122+
}),
123+
requestPromise,
124+
]);
120125

121-
const request = await requestPromise;
122126
const eventData = envelopeRequestParser(request);
123127

124128
expect(eventData.exception?.values).toHaveLength(1);
@@ -191,14 +195,16 @@ sentryTest('does not capture response headers if URL does not match', async ({ g
191195
const url = await getLocalTestPath({ testDir: __dirname });
192196
await page.goto(url);
193197

194-
await page.evaluate(() => {
195-
fetch('http://localhost:7654/bar').then(() => {
196-
// @ts-expect-error Sentry is a global
197-
Sentry.captureException('test error');
198-
});
199-
});
198+
const [, request] = await Promise.all([
199+
page.evaluate(() => {
200+
fetch('http://localhost:7654/bar').then(() => {
201+
// @ts-expect-error Sentry is a global
202+
Sentry.captureException('test error');
203+
});
204+
}),
205+
requestPromise,
206+
]);
200207

201-
const request = await requestPromise;
202208
const eventData = envelopeRequestParser(request);
203209

204210
expect(eventData.exception?.values).toHaveLength(1);

dev-packages/browser-integration-tests/suites/replay/extendNetworkBreadcrumbs/fetch/captureResponseSize/test.ts

Lines changed: 35 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -43,16 +43,18 @@ sentryTest('captures response size from Content-Length header if available', asy
4343
const url = await getLocalTestPath({ testDir: __dirname });
4444
await page.goto(url);
4545

46-
await page.evaluate(() => {
47-
/* eslint-disable */
48-
fetch('http://localhost:7654/foo').then(() => {
49-
// @ts-expect-error Sentry is a global
50-
Sentry.captureException('test error');
51-
});
52-
/* eslint-enable */
53-
});
46+
const [, request] = await Promise.all([
47+
page.evaluate(() => {
48+
/* eslint-disable */
49+
fetch('http://localhost:7654/foo').then(() => {
50+
// @ts-expect-error Sentry is a global
51+
Sentry.captureException('test error');
52+
});
53+
/* eslint-enable */
54+
}),
55+
requestPromise,
56+
]);
5457

55-
const request = await requestPromise;
5658
const eventData = envelopeRequestParser(request);
5759

5860
expect(eventData.exception?.values).toHaveLength(1);
@@ -133,16 +135,18 @@ sentryTest('captures response size without Content-Length header', async ({ getL
133135
const url = await getLocalTestPath({ testDir: __dirname });
134136
await page.goto(url);
135137

136-
await page.evaluate(() => {
137-
/* eslint-disable */
138-
fetch('http://localhost:7654/foo').then(() => {
139-
// @ts-expect-error Sentry is a global
140-
Sentry.captureException('test error');
141-
});
142-
/* eslint-enable */
143-
});
138+
const [, request] = await Promise.all([
139+
page.evaluate(() => {
140+
/* eslint-disable */
141+
fetch('http://localhost:7654/foo').then(() => {
142+
// @ts-expect-error Sentry is a global
143+
Sentry.captureException('test error');
144+
});
145+
/* eslint-enable */
146+
}),
147+
requestPromise,
148+
]);
144149

145-
const request = await requestPromise;
146150
const eventData = envelopeRequestParser(request);
147151

148152
expect(eventData.exception?.values).toHaveLength(1);
@@ -220,18 +224,20 @@ sentryTest('captures response size from non-text response body', async ({ getLoc
220224
const url = await getLocalTestPath({ testDir: __dirname });
221225
await page.goto(url);
222226

223-
await page.evaluate(() => {
224-
/* eslint-disable */
225-
fetch('http://localhost:7654/foo', {
226-
method: 'POST',
227-
}).then(() => {
228-
// @ts-expect-error Sentry is a global
229-
Sentry.captureException('test error');
230-
});
231-
/* eslint-enable */
232-
});
227+
const [, request] = await Promise.all([
228+
page.evaluate(() => {
229+
/* eslint-disable */
230+
fetch('http://localhost:7654/foo', {
231+
method: 'POST',
232+
}).then(() => {
233+
// @ts-expect-error Sentry is a global
234+
Sentry.captureException('test error');
235+
});
236+
/* eslint-enable */
237+
}),
238+
requestPromise,
239+
]);
233240

234-
const request = await requestPromise;
235241
const eventData = envelopeRequestParser(request);
236242

237243
expect(eventData.exception?.values).toHaveLength(1);

0 commit comments

Comments
 (0)