|
| 1 | +import { expect } from '@playwright/test'; |
| 2 | + |
| 3 | +import { sentryTest } from '../../../../utils/fixtures'; |
| 4 | +import { |
| 5 | + getCustomRecordingEvents, |
| 6 | + getReplayEventFromRequest, |
| 7 | + shouldSkipReplayTest, |
| 8 | + waitForReplayRequest, |
| 9 | +} from '../../../../utils/replayHelpers'; |
| 10 | + |
| 11 | +sentryTest('slow click that triggers error is captured', async ({ getLocalTestUrl, page }) => { |
| 12 | + if (shouldSkipReplayTest()) { |
| 13 | + sentryTest.skip(); |
| 14 | + } |
| 15 | + |
| 16 | + await page.route('https://dsn.ingest.sentry.io/**/*', route => { |
| 17 | + return route.fulfill({ |
| 18 | + status: 200, |
| 19 | + contentType: 'application/json', |
| 20 | + body: JSON.stringify({ id: 'test-id' }), |
| 21 | + }); |
| 22 | + }); |
| 23 | + |
| 24 | + const url = await getLocalTestUrl({ testDir: __dirname }); |
| 25 | + |
| 26 | + await page.goto(url); |
| 27 | + |
| 28 | + const [req0] = await Promise.all([ |
| 29 | + waitForReplayRequest(page, (_event, res) => { |
| 30 | + const { breadcrumbs } = getCustomRecordingEvents(res); |
| 31 | + |
| 32 | + return breadcrumbs.some(breadcrumb => breadcrumb.category === 'ui.slowClickDetected'); |
| 33 | + }), |
| 34 | + page.click('#buttonError'), |
| 35 | + ]); |
| 36 | + |
| 37 | + const { breadcrumbs } = getCustomRecordingEvents(req0); |
| 38 | + |
| 39 | + const slowClickBreadcrumbs = breadcrumbs.filter(breadcrumb => breadcrumb.category === 'ui.slowClickDetected'); |
| 40 | + |
| 41 | + expect(slowClickBreadcrumbs).toEqual([ |
| 42 | + { |
| 43 | + category: 'ui.slowClickDetected', |
| 44 | + type: 'default', |
| 45 | + data: { |
| 46 | + endReason: 'timeout', |
| 47 | + clickCount: 1, |
| 48 | + node: { |
| 49 | + attributes: { |
| 50 | + id: 'buttonError', |
| 51 | + }, |
| 52 | + id: expect.any(Number), |
| 53 | + tagName: 'button', |
| 54 | + textContent: '******* *****', |
| 55 | + }, |
| 56 | + nodeId: expect.any(Number), |
| 57 | + timeAfterClickMs: 3500, |
| 58 | + url: 'http://sentry-test.io/index.html', |
| 59 | + }, |
| 60 | + message: 'body > button#buttonError', |
| 61 | + timestamp: expect.any(Number), |
| 62 | + }, |
| 63 | + ]); |
| 64 | +}); |
| 65 | + |
| 66 | +sentryTest('click that triggers error & mutation is not captured', async ({ getLocalTestUrl, page }) => { |
| 67 | + if (shouldSkipReplayTest()) { |
| 68 | + sentryTest.skip(); |
| 69 | + } |
| 70 | + |
| 71 | + await page.route('https://dsn.ingest.sentry.io/**/*', route => { |
| 72 | + return route.fulfill({ |
| 73 | + status: 200, |
| 74 | + contentType: 'application/json', |
| 75 | + body: JSON.stringify({ id: 'test-id' }), |
| 76 | + }); |
| 77 | + }); |
| 78 | + |
| 79 | + const url = await getLocalTestUrl({ testDir: __dirname }); |
| 80 | + |
| 81 | + await page.goto(url); |
| 82 | + |
| 83 | + let slowClickCount = 0; |
| 84 | + |
| 85 | + page.on('response', res => { |
| 86 | + const req = res.request(); |
| 87 | + |
| 88 | + const event = getReplayEventFromRequest(req); |
| 89 | + |
| 90 | + if (!event) { |
| 91 | + return; |
| 92 | + } |
| 93 | + |
| 94 | + const { breadcrumbs } = getCustomRecordingEvents(res); |
| 95 | + |
| 96 | + const slowClicks = breadcrumbs.filter(breadcrumb => breadcrumb.category === 'ui.slowClickDetected'); |
| 97 | + slowClickCount += slowClicks.length; |
| 98 | + }); |
| 99 | + |
| 100 | + const [req1] = await Promise.all([ |
| 101 | + waitForReplayRequest(page, (_event, res) => { |
| 102 | + const { breadcrumbs } = getCustomRecordingEvents(res); |
| 103 | + |
| 104 | + return breadcrumbs.some(breadcrumb => breadcrumb.category === 'ui.click'); |
| 105 | + }), |
| 106 | + page.click('#buttonErrorMutation'), |
| 107 | + ]); |
| 108 | + |
| 109 | + const { breadcrumbs } = getCustomRecordingEvents(req1); |
| 110 | + |
| 111 | + expect(breadcrumbs).toEqual([ |
| 112 | + { |
| 113 | + category: 'ui.click', |
| 114 | + data: { |
| 115 | + node: { |
| 116 | + attributes: { |
| 117 | + id: 'buttonErrorMutation', |
| 118 | + }, |
| 119 | + id: expect.any(Number), |
| 120 | + tagName: 'button', |
| 121 | + textContent: '******* *****', |
| 122 | + }, |
| 123 | + nodeId: expect.any(Number), |
| 124 | + }, |
| 125 | + message: 'body > button#buttonErrorMutation', |
| 126 | + timestamp: expect.any(Number), |
| 127 | + type: 'default', |
| 128 | + }, |
| 129 | + ]); |
| 130 | + |
| 131 | + // Ensure we wait for timeout, to make sure no slow click is created |
| 132 | + await new Promise(resolve => setTimeout(resolve, 3500)); |
| 133 | + |
| 134 | + expect(slowClickCount).toBe(0); |
| 135 | +}); |
0 commit comments