|
| 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 | + |
| 15 | + await page.route('https://dsn.ingest.sentry.io/**/*', route => { |
| 16 | + return route.fulfill({ |
| 17 | + status: 200, |
| 18 | + contentType: 'application/json', |
| 19 | + body: JSON.stringify({ id: 'test-id' }), |
| 20 | + }); |
| 21 | + }); |
| 22 | + |
| 23 | + const url = await getLocalTestPath({ testDir: __dirname }); |
| 24 | + |
| 25 | + await page.goto(url); |
| 26 | + await reqPromise0; |
| 27 | + |
| 28 | + const reqPromise1 = waitForReplayRequest( |
| 29 | + page, |
| 30 | + (_event, res) => { |
| 31 | + const { breadcrumbs } = getCustomRecordingEvents(res); |
| 32 | + |
| 33 | + return breadcrumbs.filter(breadcrumb => breadcrumb.category === 'console').length > 0; |
| 34 | + }, |
| 35 | + 5_000, |
| 36 | + ); |
| 37 | + |
| 38 | + await page.click('[data-log]'); |
| 39 | + |
| 40 | + await forceFlushReplay(); |
| 41 | + |
| 42 | + const { breadcrumbs } = getCustomRecordingEvents(await reqPromise1); |
| 43 | + |
| 44 | + expect(breadcrumbs.filter(breadcrumb => breadcrumb.category === 'console')).toEqual([ |
| 45 | + { |
| 46 | + timestamp: expect.any(Number), |
| 47 | + type: 'default', |
| 48 | + category: 'console', |
| 49 | + data: { arguments: ['Test log', '[HTMLElement: HTMLBodyElement]'], logger: 'console' }, |
| 50 | + level: 'log', |
| 51 | + message: 'Test log [object HTMLBodyElement]', |
| 52 | + }, |
| 53 | + ]); |
| 54 | +}); |
| 55 | + |
| 56 | +sentryTest('should capture very large console logs', async ({ getLocalTestPath, page, forceFlushReplay }) => { |
| 57 | + // console integration is not used in bundles/loader |
| 58 | + const bundle = process.env.PW_BUNDLE || ''; |
| 59 | + if (shouldSkipReplayTest() || bundle.startsWith('bundle_') || bundle.startsWith('loader_')) { |
| 60 | + sentryTest.skip(); |
| 61 | + } |
| 62 | + |
| 63 | + const reqPromise0 = waitForReplayRequest(page, 0); |
| 64 | + |
| 65 | + await page.route('https://dsn.ingest.sentry.io/**/*', route => { |
| 66 | + return route.fulfill({ |
| 67 | + status: 200, |
| 68 | + contentType: 'application/json', |
| 69 | + body: JSON.stringify({ id: 'test-id' }), |
| 70 | + }); |
| 71 | + }); |
| 72 | + |
| 73 | + const url = await getLocalTestPath({ testDir: __dirname }); |
| 74 | + |
| 75 | + await page.goto(url); |
| 76 | + await reqPromise0; |
| 77 | + |
| 78 | + const reqPromise1 = waitForReplayRequest( |
| 79 | + page, |
| 80 | + (_event, res) => { |
| 81 | + const { breadcrumbs } = getCustomRecordingEvents(res); |
| 82 | + |
| 83 | + return breadcrumbs.filter(breadcrumb => breadcrumb.category === 'console').length > 0; |
| 84 | + }, |
| 85 | + 5_000, |
| 86 | + ); |
| 87 | + |
| 88 | + await page.click('[data-log-large]'); |
| 89 | + |
| 90 | + await forceFlushReplay(); |
| 91 | + |
| 92 | + const { breadcrumbs } = getCustomRecordingEvents(await reqPromise1); |
| 93 | + |
| 94 | + expect(breadcrumbs.filter(breadcrumb => breadcrumb.category === 'console')).toEqual([ |
| 95 | + { |
| 96 | + timestamp: expect.any(Number), |
| 97 | + type: 'default', |
| 98 | + category: 'console', |
| 99 | + data: { |
| 100 | + arguments: [ |
| 101 | + expect.objectContaining({ |
| 102 | + 'item-0': { |
| 103 | + aa: expect.objectContaining({ |
| 104 | + 'item-0': { |
| 105 | + aa: expect.any(Object), |
| 106 | + bb: expect.any(String), |
| 107 | + cc: expect.any(String), |
| 108 | + dd: expect.any(String), |
| 109 | + }, |
| 110 | + }), |
| 111 | + bb: expect.any(String), |
| 112 | + cc: expect.any(String), |
| 113 | + dd: expect.any(String), |
| 114 | + }, |
| 115 | + }), |
| 116 | + ], |
| 117 | + logger: 'console', |
| 118 | + }, |
| 119 | + level: 'log', |
| 120 | + message: '[object Object]', |
| 121 | + }, |
| 122 | + ]); |
| 123 | +}); |
0 commit comments