|
| 1 | +import { expect } from '@playwright/test'; |
| 2 | +import type { Event } from '@sentry/types'; |
| 3 | + |
| 4 | +import { sentryTest } from '../../../../../utils/fixtures'; |
| 5 | +import { getFirstSentryEnvelopeRequest } from '../../../../../utils/helpers'; |
| 6 | + |
| 7 | +sentryTest('captures Breadcrumb for events on inputs & debounced them', async ({ getLocalTestUrl, page }) => { |
| 8 | + const url = await getLocalTestUrl({ testDir: __dirname }); |
| 9 | + |
| 10 | + await page.route('**/foo', route => { |
| 11 | + return route.fulfill({ |
| 12 | + status: 200, |
| 13 | + body: JSON.stringify({ |
| 14 | + userNames: ['John', 'Jane'], |
| 15 | + }), |
| 16 | + headers: { |
| 17 | + 'Content-Type': 'application/json', |
| 18 | + }, |
| 19 | + }); |
| 20 | + }); |
| 21 | + |
| 22 | + const promise = getFirstSentryEnvelopeRequest<Event>(page); |
| 23 | + |
| 24 | + await page.goto(url); |
| 25 | + |
| 26 | + await page.click('#input1'); |
| 27 | + // Not debounced because other event type |
| 28 | + await page.type('#input1', 'John', { delay: 1 }); |
| 29 | + // This should be debounced |
| 30 | + await page.type('#input1', 'Abby', { delay: 1 }); |
| 31 | + // not debounced because other target |
| 32 | + await page.type('#input2', 'Anne', { delay: 1 }); |
| 33 | + |
| 34 | + // Wait a second for the debounce to finish |
| 35 | + await page.waitForTimeout(1000); |
| 36 | + await page.type('#input2', 'John', { delay: 1 }); |
| 37 | + |
| 38 | + await page.evaluate('Sentry.captureException("test exception")'); |
| 39 | + |
| 40 | + const eventData = await promise; |
| 41 | + |
| 42 | + expect(eventData.exception?.values).toHaveLength(1); |
| 43 | + |
| 44 | + expect(eventData.breadcrumbs).toEqual([ |
| 45 | + { |
| 46 | + timestamp: expect.any(Number), |
| 47 | + category: 'ui.click', |
| 48 | + message: 'body > input#input1[type="text"]', |
| 49 | + }, |
| 50 | + { |
| 51 | + timestamp: expect.any(Number), |
| 52 | + category: 'ui.input', |
| 53 | + message: 'body > input#input1[type="text"]', |
| 54 | + }, |
| 55 | + { |
| 56 | + timestamp: expect.any(Number), |
| 57 | + category: 'ui.input', |
| 58 | + message: 'body > input#input2[type="text"]', |
| 59 | + }, |
| 60 | + { |
| 61 | + timestamp: expect.any(Number), |
| 62 | + category: 'ui.input', |
| 63 | + message: 'body > input#input2[type="text"]', |
| 64 | + }, |
| 65 | + ]); |
| 66 | +}); |
0 commit comments