|
| 1 | +import { expect } from '@playwright/test'; |
| 2 | + |
| 3 | +import { sentryTest } from '../../../utils/fixtures'; |
| 4 | +import { getCustomRecordingEvents, shouldSkipReplayTest, waitForReplayRequest } from '../../../utils/replayHelpers'; |
| 5 | + |
| 6 | +sentryTest('captures component name attribute when available', async ({ forceFlushReplay, getLocalTestPath, page }) => { |
| 7 | + if (shouldSkipReplayTest()) { |
| 8 | + sentryTest.skip(); |
| 9 | + } |
| 10 | + |
| 11 | + const reqPromise0 = waitForReplayRequest(page, 0); |
| 12 | + |
| 13 | + await page.route('https://dsn.ingest.sentry.io/**/*', route => { |
| 14 | + return route.fulfill({ |
| 15 | + status: 200, |
| 16 | + contentType: 'application/json', |
| 17 | + body: JSON.stringify({ id: 'test-id' }), |
| 18 | + }); |
| 19 | + }); |
| 20 | + |
| 21 | + const url = await getLocalTestPath({ testDir: __dirname }); |
| 22 | + |
| 23 | + await page.goto(url); |
| 24 | + await reqPromise0; |
| 25 | + await forceFlushReplay(); |
| 26 | + |
| 27 | + const reqPromise1 = waitForReplayRequest(page, (event, res) => { |
| 28 | + return getCustomRecordingEvents(res).breadcrumbs.some(breadcrumb => breadcrumb.category === 'ui.click'); |
| 29 | + }); |
| 30 | + const reqPromise2 = waitForReplayRequest(page, (event, res) => { |
| 31 | + return getCustomRecordingEvents(res).breadcrumbs.some(breadcrumb => breadcrumb.category === 'ui.input'); |
| 32 | + }); |
| 33 | + |
| 34 | + await page.locator('#button').click(); |
| 35 | + |
| 36 | + await page.locator('#input').focus(); |
| 37 | + await page.keyboard.press('Control+A'); |
| 38 | + await page.keyboard.type('Hello', { delay: 10 }); |
| 39 | + |
| 40 | + await forceFlushReplay(); |
| 41 | + const { breadcrumbs } = getCustomRecordingEvents(await reqPromise1); |
| 42 | + const { breadcrumbs: breadcrumbs2 } = getCustomRecordingEvents(await reqPromise2); |
| 43 | + |
| 44 | + // Combine the two together |
| 45 | + breadcrumbs2.forEach(breadcrumb => { |
| 46 | + if (!breadcrumbs.some(b => b.category === breadcrumb.category && b.timestamp === breadcrumb.timestamp)) { |
| 47 | + breadcrumbs.push(breadcrumb); |
| 48 | + } |
| 49 | + }); |
| 50 | + |
| 51 | + expect(breadcrumbs).toEqual([ |
| 52 | + { |
| 53 | + timestamp: expect.any(Number), |
| 54 | + type: 'default', |
| 55 | + category: 'ui.click', |
| 56 | + message: 'body > MyCoolButton', |
| 57 | + data: { |
| 58 | + nodeId: expect.any(Number), |
| 59 | + node: { |
| 60 | + attributes: { id: 'button', 'data-sentry-component': 'MyCoolButton' }, |
| 61 | + id: expect.any(Number), |
| 62 | + tagName: 'button', |
| 63 | + textContent: '**', |
| 64 | + }, |
| 65 | + }, |
| 66 | + }, |
| 67 | + { |
| 68 | + timestamp: expect.any(Number), |
| 69 | + type: 'default', |
| 70 | + category: 'ui.input', |
| 71 | + message: 'body > MyCoolInput', |
| 72 | + data: { |
| 73 | + nodeId: expect.any(Number), |
| 74 | + node: { |
| 75 | + attributes: { id: 'input', 'data-sentry-component': 'MyCoolInput' }, |
| 76 | + id: expect.any(Number), |
| 77 | + tagName: 'input', |
| 78 | + textContent: '', |
| 79 | + }, |
| 80 | + }, |
| 81 | + }, |
| 82 | + ]); |
| 83 | +}); |
0 commit comments