|
| 1 | +import { expect, test } from '@playwright/test'; |
| 2 | +import { waitForEnvelopeItem, waitForTransaction } from '@sentry-internal/test-utils'; |
| 3 | + |
| 4 | +test('sends an INP span during pageload', async ({ page }) => { |
| 5 | + const inpSpanPromise = waitForEnvelopeItem('create-remix-app', item => { |
| 6 | + return item[0].type === 'span'; |
| 7 | + }); |
| 8 | + |
| 9 | + await page.goto(`/`); |
| 10 | + |
| 11 | + await page.click('#exception-button'); |
| 12 | + |
| 13 | + await page.waitForTimeout(500); |
| 14 | + |
| 15 | + // Page hide to trigger INP |
| 16 | + await page.evaluate(() => { |
| 17 | + window.dispatchEvent(new Event('pagehide')); |
| 18 | + }); |
| 19 | + |
| 20 | + const inpSpan = await inpSpanPromise; |
| 21 | + |
| 22 | + expect(inpSpan[1]).toEqual({ |
| 23 | + data: { |
| 24 | + 'sentry.origin': 'auto.http.browser.inp', |
| 25 | + 'sentry.op': 'ui.interaction.click', |
| 26 | + release: 'e2e-test', |
| 27 | + environment: 'qa', |
| 28 | + transaction: 'routes/_index', |
| 29 | + 'sentry.exclusive_time': expect.any(Number), |
| 30 | + 'sentry.sample_rate': 1, |
| 31 | + 'sentry.source': 'custom', |
| 32 | + replay_id: expect.any(String), |
| 33 | + }, |
| 34 | + description: 'body > div > input#exception-button[type="button"]', |
| 35 | + op: 'ui.interaction.click', |
| 36 | + parent_span_id: expect.any(String), |
| 37 | + is_segment: true, |
| 38 | + span_id: expect.any(String), |
| 39 | + start_timestamp: expect.any(Number), |
| 40 | + timestamp: expect.any(Number), |
| 41 | + trace_id: expect.any(String), |
| 42 | + origin: 'auto.http.browser.inp', |
| 43 | + exclusive_time: expect.any(Number), |
| 44 | + measurements: { inp: { unit: 'millisecond', value: expect.any(Number) } }, |
| 45 | + segment_id: expect.any(String), |
| 46 | + }); |
| 47 | +}); |
| 48 | + |
| 49 | +test('sends an INP span after pageload', async ({ page }) => { |
| 50 | + const transactionPromise = waitForTransaction('create-remix-app', transactionEvent => { |
| 51 | + return transactionEvent.contexts?.trace?.op === 'pageload' && transactionEvent.transaction === 'routes/_index'; |
| 52 | + }); |
| 53 | + |
| 54 | + await page.goto(`/`); |
| 55 | + |
| 56 | + await transactionPromise; |
| 57 | + |
| 58 | + const inpSpanPromise1 = waitForEnvelopeItem('create-remix-app', item => { |
| 59 | + return item[0].type === 'span'; |
| 60 | + }); |
| 61 | + |
| 62 | + await page.click('#exception-button'); |
| 63 | + |
| 64 | + await page.waitForTimeout(500); |
| 65 | + |
| 66 | + // Page hide to trigger INP |
| 67 | + await page.evaluate(() => { |
| 68 | + window.dispatchEvent(new Event('pagehide')); |
| 69 | + }); |
| 70 | + |
| 71 | + const inpSpan1 = await inpSpanPromise1; |
| 72 | + |
| 73 | + expect(inpSpan1[1]).toEqual({ |
| 74 | + data: { |
| 75 | + 'sentry.origin': 'auto.http.browser.inp', |
| 76 | + 'sentry.op': 'ui.interaction.click', |
| 77 | + release: 'e2e-test', |
| 78 | + environment: 'qa', |
| 79 | + transaction: 'routes/_index', |
| 80 | + 'sentry.exclusive_time': expect.any(Number), |
| 81 | + 'sentry.sample_rate': 1, |
| 82 | + 'sentry.source': 'custom', |
| 83 | + replay_id: expect.any(String), |
| 84 | + }, |
| 85 | + description: 'body > div > input#exception-button[type="button"]', |
| 86 | + op: 'ui.interaction.click', |
| 87 | + parent_span_id: expect.any(String), |
| 88 | + is_segment: true, |
| 89 | + span_id: expect.any(String), |
| 90 | + start_timestamp: expect.any(Number), |
| 91 | + timestamp: expect.any(Number), |
| 92 | + trace_id: expect.any(String), |
| 93 | + origin: 'auto.http.browser.inp', |
| 94 | + exclusive_time: expect.any(Number), |
| 95 | + measurements: { inp: { unit: 'millisecond', value: expect.any(Number) } }, |
| 96 | + segment_id: expect.any(String), |
| 97 | + }); |
| 98 | +}); |
| 99 | + |
| 100 | +test('sends an INP span during navigation', async ({ page }) => { |
| 101 | + page.on('console', msg => console.log(msg.text())); |
| 102 | + const inpSpanPromise = waitForEnvelopeItem('create-remix-app', item => { |
| 103 | + return item[0].type === 'span'; |
| 104 | + }); |
| 105 | + |
| 106 | + await page.goto(`/`); |
| 107 | + |
| 108 | + await page.click('#navigation'); |
| 109 | + |
| 110 | + await page.waitForTimeout(500); |
| 111 | + |
| 112 | + // Page hide to trigger INP |
| 113 | + await page.evaluate(() => { |
| 114 | + window.dispatchEvent(new Event('pagehide')); |
| 115 | + }); |
| 116 | + |
| 117 | + const inpSpan = await inpSpanPromise; |
| 118 | + |
| 119 | + expect(inpSpan[1]).toEqual({ |
| 120 | + data: { |
| 121 | + 'sentry.origin': 'auto.http.browser.inp', |
| 122 | + 'sentry.op': 'ui.interaction.click', |
| 123 | + release: 'e2e-test', |
| 124 | + environment: 'qa', |
| 125 | + transaction: 'routes/user.$id', |
| 126 | + 'sentry.exclusive_time': expect.any(Number), |
| 127 | + replay_id: expect.any(String), |
| 128 | + }, |
| 129 | + description: '<unknown>', |
| 130 | + op: 'ui.interaction.click', |
| 131 | + parent_span_id: expect.any(String), |
| 132 | + span_id: expect.any(String), |
| 133 | + start_timestamp: expect.any(Number), |
| 134 | + timestamp: expect.any(Number), |
| 135 | + trace_id: expect.any(String), |
| 136 | + origin: 'auto.http.browser.inp', |
| 137 | + exclusive_time: expect.any(Number), |
| 138 | + measurements: { inp: { unit: 'millisecond', value: expect.any(Number) } }, |
| 139 | + segment_id: expect.any(String), |
| 140 | + }); |
| 141 | +}); |
| 142 | + |
| 143 | +test('sends an INP span after navigation', async ({ page }) => { |
| 144 | + page.on('console', msg => console.log(msg.text())); |
| 145 | + const transactionPromise = waitForTransaction('create-remix-app', transactionEvent => { |
| 146 | + return transactionEvent.contexts?.trace?.op === 'navigation' && transactionEvent.transaction === 'routes/user.$id'; |
| 147 | + }); |
| 148 | + |
| 149 | + await page.goto(`/`); |
| 150 | + |
| 151 | + await page.click('#navigation'); |
| 152 | + |
| 153 | + await transactionPromise; |
| 154 | + |
| 155 | + const inpSpanPromise = waitForEnvelopeItem('create-remix-app', item => { |
| 156 | + return item[0].type === 'span'; |
| 157 | + }); |
| 158 | + |
| 159 | + await page.click('#button'); |
| 160 | + |
| 161 | + await page.waitForTimeout(500); |
| 162 | + |
| 163 | + // Page hide to trigger INP |
| 164 | + await page.evaluate(() => { |
| 165 | + window.dispatchEvent(new Event('pagehide')); |
| 166 | + }); |
| 167 | + |
| 168 | + const inpSpan = await inpSpanPromise; |
| 169 | + |
| 170 | + expect(inpSpan[1]).toEqual({ |
| 171 | + data: { |
| 172 | + 'sentry.origin': 'auto.http.browser.inp', |
| 173 | + 'sentry.op': 'ui.interaction.click', |
| 174 | + release: 'e2e-test', |
| 175 | + environment: 'qa', |
| 176 | + transaction: 'routes/user.$id', |
| 177 | + 'sentry.exclusive_time': expect.any(Number), |
| 178 | + replay_id: expect.any(String), |
| 179 | + 'sentry.sample_rate': 1, |
| 180 | + 'sentry.source': 'custom', |
| 181 | + }, |
| 182 | + description: '<unknown>', |
| 183 | + op: 'ui.interaction.click', |
| 184 | + is_segment: true, |
| 185 | + span_id: expect.any(String), |
| 186 | + start_timestamp: expect.any(Number), |
| 187 | + timestamp: expect.any(Number), |
| 188 | + trace_id: expect.any(String), |
| 189 | + origin: 'auto.http.browser.inp', |
| 190 | + exclusive_time: expect.any(Number), |
| 191 | + measurements: { inp: { unit: 'millisecond', value: expect.any(Number) } }, |
| 192 | + segment_id: expect.any(String), |
| 193 | + }); |
| 194 | +}); |
0 commit comments