Skip to content

Commit b35f4e5

Browse files
committed
improve tests & prevent flakiness
1 parent c67db15 commit b35f4e5

File tree

4 files changed

+236
-84
lines changed
  • dev-packages/browser-integration-tests/suites/tracing/trace-lifetime

4 files changed

+236
-84
lines changed

dev-packages/browser-integration-tests/suites/tracing/trace-lifetime/navigation/test.ts

Lines changed: 64 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@ import {
99
shouldSkipTracingTest,
1010
} from '../../../../utils/helpers';
1111

12-
sentryTest('creates a new trace on each navigation', async ({ getLocalTestPath, page }) => {
12+
sentryTest('creates a new trace on each navigation', async ({ getLocalTestUrl, page }) => {
1313
if (shouldSkipTracingTest()) {
1414
sentryTest.skip();
1515
}
1616

17-
const url = await getLocalTestPath({ testDir: __dirname });
17+
const url = await getLocalTestUrl({ testDir: __dirname });
1818

1919
await getFirstSentryEnvelopeRequest(page, url);
2020

@@ -32,6 +32,9 @@ sentryTest('creates a new trace on each navigation', async ({ getLocalTestPath,
3232
const navigation1TraceContext = navigation1Event.contexts?.trace;
3333
const navigation2TraceContext = navigation2Event.contexts?.trace;
3434

35+
expect(navigation1Event.type).toEqual('transaction');
36+
expect(navigation2Event.type).toEqual('transaction');
37+
3538
expect(navigation1TraceContext).toMatchObject({
3639
op: 'navigation',
3740
trace_id: expect.stringMatching(/^[0-9a-f]{32}$/),
@@ -65,12 +68,12 @@ sentryTest('creates a new trace on each navigation', async ({ getLocalTestPath,
6568
expect(navigation1TraceContext?.trace_id).not.toEqual(navigation2TraceContext?.trace_id);
6669
});
6770

68-
sentryTest('error after navigation has navigation traceId', async ({ getLocalTestPath, page }) => {
71+
sentryTest('error after navigation has navigation traceId', async ({ getLocalTestUrl, page }) => {
6972
if (shouldSkipTracingTest()) {
7073
sentryTest.skip();
7174
}
7275

73-
const url = await getLocalTestPath({ testDir: __dirname });
76+
const url = await getLocalTestUrl({ testDir: __dirname });
7477

7578
// ensure pageload transaction is finished
7679
await getFirstSentryEnvelopeRequest<Event>(page, url);
@@ -82,6 +85,8 @@ sentryTest('error after navigation has navigation traceId', async ({ getLocalTes
8285
);
8386
const navigationTraceContext = navigationEvent.contexts?.trace;
8487

88+
expect(navigationEvent.type).toEqual('transaction');
89+
8590
expect(navigationTraceContext).toMatchObject({
8691
op: 'navigation',
8792
trace_id: expect.stringMatching(/^[0-9a-f]{32}$/),
@@ -105,6 +110,8 @@ sentryTest('error after navigation has navigation traceId', async ({ getLocalTes
105110
await page.locator('#errorBtn').click();
106111
const [errorEvent, errorTraceHeader] = await errorEventPromise;
107112

113+
expect(errorEvent.type).toEqual(undefined);
114+
108115
const errorTraceContext = errorEvent.contexts?.trace;
109116
expect(errorTraceContext).toEqual({
110117
trace_id: navigationTraceContext?.trace_id,
@@ -119,12 +126,12 @@ sentryTest('error after navigation has navigation traceId', async ({ getLocalTes
119126
});
120127
});
121128

122-
sentryTest('error during navigation has new navigation traceId', async ({ getLocalTestPath, page }) => {
129+
sentryTest('error during navigation has new navigation traceId', async ({ getLocalTestUrl, page }) => {
123130
if (shouldSkipTracingTest()) {
124131
sentryTest.skip();
125132
}
126133

127-
const url = await getLocalTestPath({ testDir: __dirname });
134+
const url = await getLocalTestUrl({ testDir: __dirname });
128135

129136
// ensure navigation transaction is finished
130137
await getFirstSentryEnvelopeRequest<Event>(page, url);
@@ -143,6 +150,9 @@ sentryTest('error during navigation has new navigation traceId', async ({ getLoc
143150
const [navigationEvent, navigationTraceHeader] = envelopes.find(envelope => envelope[0].type === 'transaction')!;
144151
const [errorEvent, errorTraceHeader] = envelopes.find(envelope => !envelope[0].type)!;
145152

153+
expect(navigationEvent.type).toEqual('transaction');
154+
expect(errorEvent.type).toEqual(undefined);
155+
146156
const navigationTraceContext = navigationEvent?.contexts?.trace;
147157
expect(navigationTraceContext).toMatchObject({
148158
op: 'navigation',
@@ -176,12 +186,20 @@ sentryTest('error during navigation has new navigation traceId', async ({ getLoc
176186

177187
sentryTest(
178188
'outgoing fetch request after navigation has navigation traceId in headers',
179-
async ({ getLocalTestPath, page }) => {
189+
async ({ getLocalTestUrl, page }) => {
180190
if (shouldSkipTracingTest()) {
181191
sentryTest.skip();
182192
}
183193

184-
const url = await getLocalTestPath({ testDir: __dirname });
194+
const url = await getLocalTestUrl({ testDir: __dirname });
195+
196+
await page.route('http://example.com/**', route => {
197+
return route.fulfill({
198+
status: 200,
199+
contentType: 'application/json',
200+
body: JSON.stringify({}),
201+
});
202+
});
185203

186204
// ensure navigation transaction is finished
187205
await getFirstSentryEnvelopeRequest<Event>(page, url);
@@ -193,6 +211,8 @@ sentryTest(
193211
);
194212

195213
const navigationTraceContext = navigationEvent.contexts?.trace;
214+
215+
expect(navigationEvent.type).toEqual('transaction');
196216
expect(navigationTraceContext).toMatchObject({
197217
op: 'navigation',
198218
trace_id: expect.stringMatching(/^[0-9a-f]{32}$/),
@@ -224,12 +244,20 @@ sentryTest(
224244

225245
sentryTest(
226246
'outgoing fetch request during navigation has navigation traceId in headers',
227-
async ({ getLocalTestPath, page }) => {
247+
async ({ getLocalTestUrl, page }) => {
228248
if (shouldSkipTracingTest()) {
229249
sentryTest.skip();
230250
}
231251

232-
const url = await getLocalTestPath({ testDir: __dirname });
252+
const url = await getLocalTestUrl({ testDir: __dirname });
253+
254+
await page.route('http://example.com/**', route => {
255+
return route.fulfill({
256+
status: 200,
257+
contentType: 'application/json',
258+
body: JSON.stringify({}),
259+
});
260+
});
233261

234262
// ensure navigation transaction is finished
235263
await getFirstSentryEnvelopeRequest<Event>(page, url);
@@ -248,6 +276,8 @@ sentryTest(
248276
]);
249277

250278
const navigationTraceContext = navigationEvent.contexts?.trace;
279+
280+
expect(navigationEvent.type).toEqual('transaction');
251281
expect(navigationTraceContext).toMatchObject({
252282
op: 'navigation',
253283
trace_id: expect.stringMatching(/^[0-9a-f]{32}$/),
@@ -276,12 +306,20 @@ sentryTest(
276306

277307
sentryTest(
278308
'outgoing XHR request after navigation has navigation traceId in headers',
279-
async ({ getLocalTestPath, page }) => {
309+
async ({ getLocalTestUrl, page }) => {
280310
if (shouldSkipTracingTest()) {
281311
sentryTest.skip();
282312
}
283313

284-
const url = await getLocalTestPath({ testDir: __dirname });
314+
const url = await getLocalTestUrl({ testDir: __dirname });
315+
316+
await page.route('http://example.com/**', route => {
317+
return route.fulfill({
318+
status: 200,
319+
contentType: 'application/json',
320+
body: JSON.stringify({}),
321+
});
322+
});
285323

286324
// ensure navigation transaction is finished
287325
await getFirstSentryEnvelopeRequest(page, url);
@@ -293,6 +331,8 @@ sentryTest(
293331
);
294332

295333
const navigationTraceContext = navigationEvent.contexts?.trace;
334+
335+
expect(navigationEvent.type).toEqual('transaction');
296336
expect(navigationTraceContext).toMatchObject({
297337
op: 'navigation',
298338
trace_id: expect.stringMatching(/^[0-9a-f]{32}$/),
@@ -324,12 +364,20 @@ sentryTest(
324364

325365
sentryTest(
326366
'outgoing XHR request during navigation has navigation traceId in headers',
327-
async ({ getLocalTestPath, page }) => {
367+
async ({ getLocalTestUrl, page }) => {
328368
if (shouldSkipTracingTest()) {
329369
sentryTest.skip();
330370
}
331371

332-
const url = await getLocalTestPath({ testDir: __dirname });
372+
const url = await getLocalTestUrl({ testDir: __dirname });
373+
374+
await page.route('http://example.com/**', route => {
375+
return route.fulfill({
376+
status: 200,
377+
contentType: 'application/json',
378+
body: JSON.stringify({}),
379+
});
380+
});
333381

334382
// ensure navigation transaction is finished
335383
await getFirstSentryEnvelopeRequest(page, url);
@@ -348,6 +396,8 @@ sentryTest(
348396
]);
349397

350398
const navigationTraceContext = navigationEvent.contexts?.trace;
399+
400+
expect(navigationEvent.type).toEqual('transaction');
351401
expect(navigationTraceContext).toMatchObject({
352402
op: 'navigation',
353403
trace_id: expect.stringMatching(/^[0-9a-f]{32}$/),

0 commit comments

Comments
 (0)