-
-
Notifications
You must be signed in to change notification settings - Fork 360
Expand file tree
/
Copy pathcaptureErrorsScreenTransaction.test.ts
More file actions
151 lines (131 loc) · 4.53 KB
/
captureErrorsScreenTransaction.test.ts
File metadata and controls
151 lines (131 loc) · 4.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
import { describe, it, beforeAll, expect, afterAll } from '@jest/globals';
import { EventItem } from '@sentry/core';
import {
createSentryServer,
containingTransactionWithName,
} from '../../utils/mockedSentryServer';
import { getItemOfTypeFrom } from '../../utils/event';
import { maestro } from '../../utils/maestro';
describe('Capture Errors Screen Transaction', () => {
let sentryServer = createSentryServer();
const getErrorsEnvelope = () =>
sentryServer.getEnvelope(containingTransactionWithName('ErrorsScreen'));
beforeAll(async () => {
await sentryServer.start();
const waitForErrorsTx = sentryServer.waitForEnvelope(
containingTransactionWithName('ErrorsScreen'), // The last created and sent transaction
);
await maestro('tests/captureErrorScreenTransaction/captureErrorsScreenTransaction.test.yml');
await waitForErrorsTx;
}, 240000); // 240 seconds timeout for iOS event delivery
afterAll(async () => {
await sentryServer.close();
});
it('envelope contains transaction context', async () => {
// The app start transaction may arrive in a separate envelope on slow CI VMs,
// so search all matching envelopes instead of just the first one.
const allEnvelopes = sentryServer.getAllEnvelopes(
containingTransactionWithName('ErrorsScreen'),
);
let appStartTransaction: EventItem | undefined;
for (const envelope of allEnvelopes) {
const items = envelope[1];
const transactions = items.filter(([header]) => header.type === 'transaction') as EventItem[];
appStartTransaction = transactions.find(([_header, payload]) => {
const event = payload as any;
return event.transaction === 'ErrorsScreen' &&
event.contexts?.trace?.origin === 'auto.app.start';
});
if (appStartTransaction) break;
}
expect(appStartTransaction).toBeDefined();
const [header, payload] = appStartTransaction!;
expect(header).toEqual(
expect.objectContaining({
length: expect.any(Number),
type: 'transaction',
})
);
expect(payload).toEqual(
expect.objectContaining({
platform: 'javascript',
transaction: 'ErrorsScreen',
contexts: expect.objectContaining({
trace: expect.objectContaining({
data: expect.objectContaining({
'route.has_been_seen': false,
'route.key': expect.stringMatching(/^ErrorsScreen/),
'route.name': 'ErrorsScreen',
'sentry.idle_span_finish_reason': 'idleTimeout',
'sentry.op': 'ui.load',
'sentry.origin': 'auto.app.start',
'sentry.sample_rate': 1,
'sentry.source': 'component',
'thread.name': 'javascript',
}),
op: 'ui.load',
origin: 'auto.app.start',
span_id: expect.any(String),
trace_id: expect.any(String),
}),
}),
})
);
});
it('contains app start measurements', async () => {
const item = getItemOfTypeFrom<EventItem>(
getErrorsEnvelope(),
'transaction',
);
expect(item?.[1]).toEqual(
expect.objectContaining({
measurements: expect.objectContaining({
time_to_initial_display: expect.objectContaining({
unit: 'millisecond',
value: expect.any(Number),
}),
}),
}),
);
});
it('contains time to initial display measurements', async () => {
const item = getItemOfTypeFrom<EventItem>(
await getErrorsEnvelope(),
'transaction',
);
expect(item?.[1]).toEqual(
expect.objectContaining({
measurements: expect.objectContaining({
time_to_initial_display: expect.objectContaining({
unit: 'millisecond',
value: expect.any(Number),
}),
}),
}),
);
});
it('contains JS stall measurements', async () => {
const item = getItemOfTypeFrom<EventItem>(
await getErrorsEnvelope(),
'transaction',
);
expect(item?.[1]).toEqual(
expect.objectContaining({
measurements: expect.objectContaining({
stall_count: expect.objectContaining({
unit: 'none',
value: expect.any(Number),
}),
stall_longest_time: expect.objectContaining({
unit: 'millisecond',
value: expect.any(Number),
}),
stall_total_time: expect.objectContaining({
unit: 'millisecond',
value: expect.any(Number),
}),
}),
}),
);
});
});