|
| 1 | +import { expect } from '@playwright/test'; |
| 2 | + |
| 3 | +import { sentryTest } from '../../../utils/fixtures'; |
| 4 | +import { getCustomRecordingEvents, shouldSkipReplayTest, waitForReplayRequest } from '../../../utils/replayHelpers'; |
| 5 | + |
| 6 | +sentryTest('should capture console messages in replay', async ({ getLocalTestPath, page, forceFlushReplay }) => { |
| 7 | + // console integration is not used in bundles/loader |
| 8 | + const bundle = process.env.PW_BUNDLE || ''; |
| 9 | + if (shouldSkipReplayTest() || bundle.startsWith('bundle_') || bundle.startsWith('loader_')) { |
| 10 | + sentryTest.skip(); |
| 11 | + } |
| 12 | + |
| 13 | + const reqPromise0 = waitForReplayRequest(page, 0); |
| 14 | + const reqPromise1 = waitForReplayRequest(page, (_event, res) => { |
| 15 | + const { breadcrumbs } = getCustomRecordingEvents(res); |
| 16 | + |
| 17 | + return breadcrumbs.filter(breadcrumb => breadcrumb.category === 'console').length > 0; |
| 18 | + }); |
| 19 | + |
| 20 | + await page.route('https://dsn.ingest.sentry.io/**/*', route => { |
| 21 | + return route.fulfill({ |
| 22 | + status: 200, |
| 23 | + contentType: 'application/json', |
| 24 | + body: JSON.stringify({ id: 'test-id' }), |
| 25 | + }); |
| 26 | + }); |
| 27 | + |
| 28 | + const url = await getLocalTestPath({ testDir: __dirname }); |
| 29 | + |
| 30 | + await page.goto(url); |
| 31 | + await reqPromise0; |
| 32 | + |
| 33 | + await page.click('[data-log]'); |
| 34 | + |
| 35 | + await forceFlushReplay(); |
| 36 | + |
| 37 | + const { breadcrumbs } = getCustomRecordingEvents(await reqPromise1); |
| 38 | + |
| 39 | + expect(breadcrumbs.filter(breadcrumb => breadcrumb.category === 'console')).toEqual([ |
| 40 | + { |
| 41 | + timestamp: expect.any(Number), |
| 42 | + type: 'default', |
| 43 | + category: 'console', |
| 44 | + data: { arguments: ['Test log', '[HTMLElement: HTMLBodyElement]'], logger: 'console' }, |
| 45 | + level: 'log', |
| 46 | + message: 'Test log [object HTMLBodyElement]', |
| 47 | + }, |
| 48 | + ]); |
| 49 | +}); |
0 commit comments