|
| 1 | +import { expect } from '@playwright/test'; |
| 2 | + |
| 3 | +import { sentryTest } from '../../../../utils/fixtures'; |
| 4 | +import { envelopeRequestParser, getEnvelopeType } from '../../../../utils/helpers'; |
| 5 | +import { getCustomRecordingEvents, getReplayEvent, waitForReplayRequest } from '../../../../utils/replayHelpers'; |
| 6 | + |
| 7 | +sentryTest( |
| 8 | + 'should capture feedback (@sentry-internal/feedback import)', |
| 9 | + async ({ forceFlushReplay, getLocalTestPath, page }) => { |
| 10 | + if (process.env.PW_BUNDLE) { |
| 11 | + sentryTest.skip(); |
| 12 | + } |
| 13 | + |
| 14 | + const reqPromise0 = waitForReplayRequest(page, 0); |
| 15 | + const reqPromise1 = waitForReplayRequest(page, 1); |
| 16 | + const reqPromise2 = waitForReplayRequest(page, 2); |
| 17 | + const feedbackRequestPromise = page.waitForResponse(res => { |
| 18 | + const req = res.request(); |
| 19 | + |
| 20 | + const postData = req.postData(); |
| 21 | + if (!postData) { |
| 22 | + return false; |
| 23 | + } |
| 24 | + |
| 25 | + try { |
| 26 | + return getEnvelopeType(req) === 'feedback'; |
| 27 | + } catch (err) { |
| 28 | + return false; |
| 29 | + } |
| 30 | + }); |
| 31 | + |
| 32 | + await page.route('https://dsn.ingest.sentry.io/**/*', route => { |
| 33 | + return route.fulfill({ |
| 34 | + status: 200, |
| 35 | + contentType: 'application/json', |
| 36 | + body: JSON.stringify({ id: 'test-id' }), |
| 37 | + }); |
| 38 | + }); |
| 39 | + |
| 40 | + const url = await getLocalTestPath({ testDir: __dirname }); |
| 41 | + |
| 42 | + const [, , replayReq0] = await Promise.all([page.goto(url), page.getByText('Report a Bug').click(), reqPromise0]); |
| 43 | + |
| 44 | + // Inputs are slow, these need to be serial |
| 45 | + await page.locator('[name="name"]').fill('Jane Doe'); |
| 46 | + await page.locator('[name="email"]').fill('[email protected]'); |
| 47 | + await page.locator('[name="message"]').fill('my example feedback'); |
| 48 | + |
| 49 | + // Force flush here, as inputs are slow and can cause click event to be in unpredictable segments |
| 50 | + await Promise.all([forceFlushReplay(), reqPromise1]); |
| 51 | + |
| 52 | + const [, feedbackResp, replayReq2] = await Promise.all([ |
| 53 | + page.getByLabel('Send Bug Report').click(), |
| 54 | + feedbackRequestPromise, |
| 55 | + reqPromise2, |
| 56 | + ]); |
| 57 | + |
| 58 | + const feedbackEvent = envelopeRequestParser(feedbackResp.request()); |
| 59 | + const replayEvent = getReplayEvent(replayReq0); |
| 60 | + // Feedback breadcrumb is on second segment because we flush when "Report a Bug" is clicked |
| 61 | + // And then the breadcrumb is sent when feedback form is submitted |
| 62 | + const { breadcrumbs } = getCustomRecordingEvents(replayReq2); |
| 63 | + |
| 64 | + expect(breadcrumbs).toEqual( |
| 65 | + expect.arrayContaining([ |
| 66 | + expect.objectContaining({ |
| 67 | + category: 'sentry.feedback', |
| 68 | + data: { feedbackId: expect.any(String) }, |
| 69 | + timestamp: expect.any(Number), |
| 70 | + type: 'default', |
| 71 | + }), |
| 72 | + ]), |
| 73 | + ); |
| 74 | + |
| 75 | + expect(feedbackEvent).toEqual({ |
| 76 | + type: 'feedback', |
| 77 | + breadcrumbs: expect.any(Array), |
| 78 | + contexts: { |
| 79 | + feedback: { |
| 80 | + contact_email: '[email protected]', |
| 81 | + message: 'my example feedback', |
| 82 | + name: 'Jane Doe', |
| 83 | + replay_id: replayEvent.event_id, |
| 84 | + source: 'widget', |
| 85 | + url: expect.stringContaining('/dist/index.html'), |
| 86 | + }, |
| 87 | + }, |
| 88 | + level: 'info', |
| 89 | + timestamp: expect.any(Number), |
| 90 | + event_id: expect.stringMatching(/\w{32}/), |
| 91 | + environment: 'production', |
| 92 | + sdk: { |
| 93 | + integrations: expect.arrayContaining(['Feedback']), |
| 94 | + version: expect.any(String), |
| 95 | + name: 'sentry.javascript.browser', |
| 96 | + packages: expect.anything(), |
| 97 | + }, |
| 98 | + request: { |
| 99 | + url: expect.stringContaining('/dist/index.html'), |
| 100 | + headers: { |
| 101 | + 'User-Agent': expect.stringContaining(''), |
| 102 | + }, |
| 103 | + }, |
| 104 | + platform: 'javascript', |
| 105 | + }); |
| 106 | + }, |
| 107 | +); |
0 commit comments