|
| 1 | +import { describe, it, beforeAll, expect, afterAll } from '@jest/globals'; |
| 2 | +import { Envelope, EventItem } from '@sentry/core'; |
| 3 | +import { device } from 'detox'; |
| 4 | +import { |
| 5 | + createSentryServer, |
| 6 | + containingTransactionWithName, |
| 7 | +} from './utils/mockedSentryServer'; |
| 8 | +import { tap } from './utils/tap'; |
| 9 | +import { sleep } from './utils/sleep'; |
| 10 | +import { getItemOfTypeFrom } from './utils/event'; |
| 11 | + |
| 12 | +describe('Capture transaction', () => { |
| 13 | + let sentryServer = createSentryServer(); |
| 14 | + sentryServer.start(); |
| 15 | + |
| 16 | + const getErrorsEnvelope = () => |
| 17 | + sentryServer.getEnvelope(containingTransactionWithName('Errors')); |
| 18 | + |
| 19 | + const getTrackerEnvelope = () => |
| 20 | + sentryServer.getEnvelope(containingTransactionWithName('Tracker')); |
| 21 | + |
| 22 | + beforeAll(async () => { |
| 23 | + await device.launchApp(); |
| 24 | + |
| 25 | + const waitForPerformanceTransaction = sentryServer.waitForEnvelope( |
| 26 | + containingTransactionWithName('Tracker'), // The last created and sent transaction |
| 27 | + ); |
| 28 | + |
| 29 | + await sleep(500); |
| 30 | + await tap('Performance'); // Bottom tab |
| 31 | + await sleep(200); |
| 32 | + await tap('Auto Tracing Example'); // Screen with Full Display |
| 33 | + |
| 34 | + await waitForPerformanceTransaction; |
| 35 | + }); |
| 36 | + |
| 37 | + afterAll(async () => { |
| 38 | + await sentryServer.close(); |
| 39 | + }); |
| 40 | + |
| 41 | + it('envelope contains transaction context', async () => { |
| 42 | + const item = getItemOfTypeFrom<EventItem>( |
| 43 | + getErrorsEnvelope(), |
| 44 | + 'transaction', |
| 45 | + ); |
| 46 | + |
| 47 | + expect(item).toEqual([ |
| 48 | + expect.objectContaining({ |
| 49 | + length: expect.any(Number), |
| 50 | + type: 'transaction', |
| 51 | + }), |
| 52 | + expect.objectContaining({ |
| 53 | + platform: 'javascript', |
| 54 | + contexts: expect.objectContaining({ |
| 55 | + trace: { |
| 56 | + data: { |
| 57 | + 'route.has_been_seen': false, |
| 58 | + 'route.key': expect.stringMatching(/^ErrorsScreen/), |
| 59 | + 'route.name': 'ErrorsScreen', |
| 60 | + 'sentry.idle_span_finish_reason': 'idleTimeout', |
| 61 | + 'sentry.op': 'ui.load', |
| 62 | + 'sentry.origin': 'auto.app.start', |
| 63 | + 'sentry.sample_rate': 1, |
| 64 | + 'sentry.source': 'component', |
| 65 | + }, |
| 66 | + op: 'ui.load', |
| 67 | + origin: 'auto.app.start', |
| 68 | + span_id: expect.any(String), |
| 69 | + trace_id: expect.any(String), |
| 70 | + }, |
| 71 | + }), |
| 72 | + }), |
| 73 | + ]); |
| 74 | + }); |
| 75 | + |
| 76 | + it('contains app start measurements', async () => { |
| 77 | + const item = getItemOfTypeFrom<EventItem>( |
| 78 | + getErrorsEnvelope(), |
| 79 | + 'transaction', |
| 80 | + ); |
| 81 | + |
| 82 | + expect(item?.[1]).toEqual( |
| 83 | + expect.objectContaining({ |
| 84 | + measurements: expect.objectContaining({ |
| 85 | + app_start_warm: { |
| 86 | + unit: 'millisecond', |
| 87 | + value: expect.any(Number), |
| 88 | + }, |
| 89 | + time_to_initial_display: { |
| 90 | + unit: 'millisecond', |
| 91 | + value: expect.any(Number), |
| 92 | + }, |
| 93 | + }), |
| 94 | + }), |
| 95 | + ); |
| 96 | + }); |
| 97 | + |
| 98 | + it('contains time to initial display measurements', async () => { |
| 99 | + const item = getItemOfTypeFrom<EventItem>( |
| 100 | + await getErrorsEnvelope(), |
| 101 | + 'transaction', |
| 102 | + ); |
| 103 | + |
| 104 | + expect(item?.[1]).toEqual( |
| 105 | + expect.objectContaining({ |
| 106 | + measurements: expect.objectContaining({ |
| 107 | + time_to_initial_display: { |
| 108 | + unit: 'millisecond', |
| 109 | + value: expect.any(Number), |
| 110 | + }, |
| 111 | + }), |
| 112 | + }), |
| 113 | + ); |
| 114 | + }); |
| 115 | + |
| 116 | + it('contains JS stall measurements', async () => { |
| 117 | + const item = getItemOfTypeFrom<EventItem>( |
| 118 | + await getErrorsEnvelope(), |
| 119 | + 'transaction', |
| 120 | + ); |
| 121 | + |
| 122 | + expect(item?.[1]).toEqual( |
| 123 | + expect.objectContaining({ |
| 124 | + measurements: expect.objectContaining({ |
| 125 | + stall_count: { |
| 126 | + unit: 'none', |
| 127 | + value: expect.any(Number), |
| 128 | + }, |
| 129 | + stall_longest_time: { |
| 130 | + unit: 'millisecond', |
| 131 | + value: expect.any(Number), |
| 132 | + }, |
| 133 | + stall_total_time: { |
| 134 | + unit: 'millisecond', |
| 135 | + value: expect.any(Number), |
| 136 | + }, |
| 137 | + }), |
| 138 | + }), |
| 139 | + ); |
| 140 | + }); |
| 141 | + |
| 142 | + it('contains native frames measurements', async () => { |
| 143 | + const item = getItemOfTypeFrom<EventItem>( |
| 144 | + getErrorsEnvelope(), |
| 145 | + 'transaction', |
| 146 | + ); |
| 147 | + |
| 148 | + expect(item?.[1]).toEqual( |
| 149 | + expect.objectContaining({ |
| 150 | + measurements: expect.objectContaining({ |
| 151 | + frames_frozen: { |
| 152 | + unit: 'none', |
| 153 | + value: 0, // Should we force 0 in e2e tests? |
| 154 | + }, |
| 155 | + frames_slow: { |
| 156 | + unit: 'none', |
| 157 | + value: expect.any(Number), |
| 158 | + }, |
| 159 | + frames_total: { |
| 160 | + unit: 'none', |
| 161 | + value: expect.any(Number), |
| 162 | + }, |
| 163 | + }), |
| 164 | + }), |
| 165 | + ); |
| 166 | + }); |
| 167 | + |
| 168 | + it('contains time to display measurements', async () => { |
| 169 | + const item = getItemOfTypeFrom<EventItem>( |
| 170 | + getTrackerEnvelope(), |
| 171 | + 'transaction', |
| 172 | + ); |
| 173 | + |
| 174 | + expect(item?.[1]).toEqual( |
| 175 | + expect.objectContaining({ |
| 176 | + measurements: expect.objectContaining({ |
| 177 | + time_to_initial_display: { |
| 178 | + unit: 'millisecond', |
| 179 | + value: expect.any(Number), |
| 180 | + }, |
| 181 | + time_to_full_display: { |
| 182 | + unit: 'millisecond', |
| 183 | + value: expect.any(Number), |
| 184 | + }, |
| 185 | + }), |
| 186 | + }), |
| 187 | + ); |
| 188 | + }); |
| 189 | + |
| 190 | + it('contains at least one xhr breadcrumb of request to the tracker endpoint', async () => { |
| 191 | + const item = getItemOfTypeFrom<EventItem>( |
| 192 | + getTrackerEnvelope(), |
| 193 | + 'transaction', |
| 194 | + ); |
| 195 | + |
| 196 | + expect(item?.[1]).toEqual( |
| 197 | + expect.objectContaining({ |
| 198 | + breadcrumbs: expect.arrayContaining([ |
| 199 | + expect.objectContaining({ |
| 200 | + category: 'xhr', |
| 201 | + data: { |
| 202 | + end_timestamp: expect.any(Number), |
| 203 | + method: 'GET', |
| 204 | + response_body_size: expect.any(Number), |
| 205 | + start_timestamp: expect.any(Number), |
| 206 | + status_code: expect.any(Number), |
| 207 | + url: expect.stringContaining('api.covid19api.com/summary'), |
| 208 | + }, |
| 209 | + level: 'info', |
| 210 | + timestamp: expect.any(Number), |
| 211 | + type: 'http', |
| 212 | + }), |
| 213 | + ]), |
| 214 | + }), |
| 215 | + ); |
| 216 | + }); |
| 217 | +}); |
0 commit comments