|
| 1 | +import { describe, it, beforeAll, expect, afterAll } from '@jest/globals'; |
| 2 | +import { Envelope, EventItem } from '@sentry/core'; |
| 3 | +import { |
| 4 | + createSentryServer, |
| 5 | + containingTransactionWithName, |
| 6 | + takeSecond, |
| 7 | +} from './utils/mockedSentryServer'; |
| 8 | + |
| 9 | +import { getItemOfTypeFrom } from './utils/event'; |
| 10 | +import { maestro } from './utils/maestro'; |
| 11 | + |
| 12 | +describe('Capture Spaceflight News Screen Transaction', () => { |
| 13 | + let sentryServer = createSentryServer(); |
| 14 | + sentryServer.start(); |
| 15 | + |
| 16 | + let envelopes: Envelope[] = []; |
| 17 | + |
| 18 | + const getFirstTransactionEnvelopeItem = () => |
| 19 | + getItemOfTypeFrom<EventItem>(envelopes[0], 'transaction'); |
| 20 | + |
| 21 | + const getSecondTransactionEnvelopeItem = () => |
| 22 | + getItemOfTypeFrom<EventItem>(envelopes[1], 'transaction'); |
| 23 | + |
| 24 | + beforeAll(async () => { |
| 25 | + const containingNewsScreen = containingTransactionWithName( |
| 26 | + 'SpaceflightNewsScreen', |
| 27 | + ); |
| 28 | + const waitForSpaceflightNewsTx = sentryServer.waitForEnvelope( |
| 29 | + takeSecond(containingNewsScreen), |
| 30 | + ); |
| 31 | + |
| 32 | + await maestro('captureSpaceflightNewsScreenTransaction.test.yml'); |
| 33 | + |
| 34 | + await waitForSpaceflightNewsTx; |
| 35 | + |
| 36 | + envelopes = sentryServer.getAllEnvelopes(containingNewsScreen); |
| 37 | + }); |
| 38 | + |
| 39 | + afterAll(async () => { |
| 40 | + await sentryServer.close(); |
| 41 | + }); |
| 42 | + |
| 43 | + it('first received new screen transaction was created before the second visit', async () => { |
| 44 | + const first = getFirstTransactionEnvelopeItem(); |
| 45 | + const second = getSecondTransactionEnvelopeItem(); |
| 46 | + |
| 47 | + expect(first?.[1].timestamp).toBeDefined(); |
| 48 | + expect(second?.[1].timestamp).toBeDefined(); |
| 49 | + expect(first![1].timestamp!).toBeLessThan(second![1].timestamp!); |
| 50 | + }); |
| 51 | + |
| 52 | + it('contains time to display measurements on the first visit', async () => { |
| 53 | + expectToContainTimeToDisplayMeasurements(getFirstTransactionEnvelopeItem()); |
| 54 | + }); |
| 55 | + |
| 56 | + it('contains time to display measurements on the second visit', async () => { |
| 57 | + expectToContainTimeToDisplayMeasurements( |
| 58 | + getSecondTransactionEnvelopeItem(), |
| 59 | + ); |
| 60 | + }); |
| 61 | + |
| 62 | + function expectToContainTimeToDisplayMeasurements( |
| 63 | + item: EventItem | undefined, |
| 64 | + ) { |
| 65 | + expect(item?.[1]).toEqual( |
| 66 | + expect.objectContaining({ |
| 67 | + measurements: expect.objectContaining({ |
| 68 | + time_to_initial_display: { |
| 69 | + unit: 'millisecond', |
| 70 | + value: expect.any(Number), |
| 71 | + }, |
| 72 | + time_to_full_display: { |
| 73 | + unit: 'millisecond', |
| 74 | + value: expect.any(Number), |
| 75 | + }, |
| 76 | + }), |
| 77 | + }), |
| 78 | + ); |
| 79 | + } |
| 80 | + |
| 81 | + it('contains at least one xhr breadcrumb of request to the news endpoint', async () => { |
| 82 | + const item = getFirstTransactionEnvelopeItem(); |
| 83 | + |
| 84 | + expect(item?.[1]).toEqual( |
| 85 | + expect.objectContaining({ |
| 86 | + breadcrumbs: expect.arrayContaining([ |
| 87 | + expect.objectContaining({ |
| 88 | + category: 'xhr', |
| 89 | + data: { |
| 90 | + end_timestamp: expect.any(Number), |
| 91 | + method: 'GET', |
| 92 | + response_body_size: expect.any(Number), |
| 93 | + start_timestamp: expect.any(Number), |
| 94 | + status_code: expect.any(Number), |
| 95 | + url: expect.stringContaining( |
| 96 | + 'api.spaceflightnewsapi.net/v4/articles', |
| 97 | + ), |
| 98 | + }, |
| 99 | + level: 'info', |
| 100 | + timestamp: expect.any(Number), |
| 101 | + type: 'http', |
| 102 | + }), |
| 103 | + ]), |
| 104 | + }), |
| 105 | + ); |
| 106 | + }); |
| 107 | +}); |
0 commit comments