|
| 1 | +import { expect } from '@playwright/test'; |
| 2 | + |
| 3 | +import { sentryTest } from '../../../utils/fixtures'; |
| 4 | +import { envelopeRequestParser } from '../../../utils/helpers'; |
| 5 | +import { |
| 6 | + getDecompressedRecordingEvents, |
| 7 | + getReplaySnapshot, |
| 8 | + isReplayEvent, |
| 9 | + REPLAY_DEFAULT_FLUSH_MAX_DELAY, |
| 10 | + shouldSkipReplayTest, |
| 11 | + waitForReplayRequest, |
| 12 | +} from '../../../utils/replayHelpers'; |
| 13 | + |
| 14 | +sentryTest( |
| 15 | + 'should stop recording when running into eventBuffer error', |
| 16 | + async ({ getLocalTestPath, page, forceFlushReplay }) => { |
| 17 | + if (shouldSkipReplayTest()) { |
| 18 | + sentryTest.skip(); |
| 19 | + } |
| 20 | + |
| 21 | + await page.route('https://dsn.ingest.sentry.io/**/*', route => { |
| 22 | + return route.fulfill({ |
| 23 | + status: 200, |
| 24 | + }); |
| 25 | + }); |
| 26 | + |
| 27 | + const url = await getLocalTestPath({ testDir: __dirname }); |
| 28 | + await page.goto(url); |
| 29 | + |
| 30 | + await waitForReplayRequest(page); |
| 31 | + const replay = await getReplaySnapshot(page); |
| 32 | + expect(replay._isEnabled).toBe(true); |
| 33 | + |
| 34 | + await forceFlushReplay(); |
| 35 | + |
| 36 | + let called = 0; |
| 37 | + |
| 38 | + await page.route('https://dsn.ingest.sentry.io/**/*', route => { |
| 39 | + const event = envelopeRequestParser(route.request()); |
| 40 | + |
| 41 | + // We only want to count replays here |
| 42 | + if (event && isReplayEvent(event)) { |
| 43 | + const events = getDecompressedRecordingEvents(route.request()); |
| 44 | + // this makes sure we ignore e.g. mouse move events which can otherwise lead to flakes |
| 45 | + if (events.length > 0) { |
| 46 | + called++; |
| 47 | + } |
| 48 | + } |
| 49 | + |
| 50 | + return route.fulfill({ |
| 51 | + status: 200, |
| 52 | + }); |
| 53 | + }); |
| 54 | + |
| 55 | + called = 0; |
| 56 | + |
| 57 | + /** |
| 58 | + * We test the following here: |
| 59 | + * 1. First click should add an event (so the eventbuffer is not empty) |
| 60 | + * 2. Second click should throw an error in eventBuffer (which should lead to stopping the replay) |
| 61 | + * 3. Nothing should be sent to API, as we stop the replay due to the eventBuffer error. |
| 62 | + */ |
| 63 | + await page.evaluate(` |
| 64 | +window._count = 0; |
| 65 | +window._addEvent = window.Replay._replay.eventBuffer.addEvent.bind(window.Replay._replay.eventBuffer); |
| 66 | +window.Replay._replay.eventBuffer.addEvent = (...args) => { |
| 67 | + window._count++; |
| 68 | + if (window._count === 2) { |
| 69 | + throw new Error('provoked error'); |
| 70 | + } |
| 71 | + window._addEvent(...args); |
| 72 | +}; |
| 73 | +`); |
| 74 | + |
| 75 | + void page.click('#button1'); |
| 76 | + void page.click('#button2'); |
| 77 | + |
| 78 | + // Should immediately skip retrying and just cancel, no backoff |
| 79 | + // This waitForTimeout call should be okay, as we're not checking for any |
| 80 | + // further network requests afterwards. |
| 81 | + await page.waitForTimeout(REPLAY_DEFAULT_FLUSH_MAX_DELAY + 100); |
| 82 | + |
| 83 | + expect(called).toBe(0); |
| 84 | + |
| 85 | + const replay2 = await getReplaySnapshot(page); |
| 86 | + |
| 87 | + expect(replay2._isEnabled).toBe(false); |
| 88 | + }, |
| 89 | +); |
0 commit comments