|
| 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('should capture feedback (@sentry-internal/feedback import)', async ({ getLocalTestPath, page }) => { |
| 8 | + if (process.env.PW_BUNDLE) { |
| 9 | + sentryTest.skip(); |
| 10 | + } |
| 11 | + |
| 12 | + const reqPromise0 = waitForReplayRequest(page, 0); |
| 13 | + const feedbackRequestPromise = page.waitForResponse(res => { |
| 14 | + const req = res.request(); |
| 15 | + |
| 16 | + const postData = req.postData(); |
| 17 | + if (!postData) { |
| 18 | + return false; |
| 19 | + } |
| 20 | + |
| 21 | + try { |
| 22 | + return getEnvelopeType(req) === 'feedback'; |
| 23 | + } catch (err) { |
| 24 | + return false; |
| 25 | + } |
| 26 | + }); |
| 27 | + |
| 28 | + await page.route('https://dsn.ingest.sentry.io/**/*', route => { |
| 29 | + return route.fulfill({ |
| 30 | + status: 200, |
| 31 | + contentType: 'application/json', |
| 32 | + body: JSON.stringify({ id: 'test-id' }), |
| 33 | + }); |
| 34 | + }); |
| 35 | + |
| 36 | + const url = await getLocalTestPath({ testDir: __dirname }); |
| 37 | + |
| 38 | + await page.goto(url); |
| 39 | + await page.getByText('Report a Bug').click(); |
| 40 | + await page.locator('[name="name"]').fill('Jane Doe'); |
| 41 | + await page.locator('[name="email"]').fill('janedoe@example.org'); |
| 42 | + await page.locator('[name="message"]').fill('my example feedback'); |
| 43 | + await page.getByLabel('Send Bug Report').click(); |
| 44 | + |
| 45 | + const [feedbackResp, replayReq] = await Promise.all([feedbackRequestPromise, reqPromise0]); |
| 46 | + |
| 47 | + const feedbackEvent = envelopeRequestParser(feedbackResp.request()); |
| 48 | + const replayEvent = getReplayEvent(replayReq); |
| 49 | + const { breadcrumbs } = getCustomRecordingEvents(replayReq); |
| 50 | + |
| 51 | + expect(breadcrumbs).toEqual( |
| 52 | + expect.arrayContaining([ |
| 53 | + { |
| 54 | + category: 'sentry.feedback', |
| 55 | + data: { feedbackId: expect.any(String) }, |
| 56 | + }, |
| 57 | + ]), |
| 58 | + ); |
| 59 | + |
| 60 | + expect(feedbackEvent).toEqual({ |
| 61 | + type: 'feedback', |
| 62 | + contexts: { |
| 63 | + feedback: { |
| 64 | + contact_email: 'janedoe@example.org', |
| 65 | + message: 'my example feedback', |
| 66 | + name: 'Jane Doe', |
| 67 | + replay_id: replayEvent.event_id, |
| 68 | + source: 'widget', |
| 69 | + url: expect.stringContaining('/dist/index.html'), |
| 70 | + }, |
| 71 | + }, |
| 72 | + level: 'info', |
| 73 | + timestamp: expect.any(Number), |
| 74 | + event_id: expect.stringMatching(/\w{32}/), |
| 75 | + environment: 'production', |
| 76 | + sdk: { |
| 77 | + integrations: expect.arrayContaining(['Feedback']), |
| 78 | + version: expect.any(String), |
| 79 | + name: 'sentry.javascript.browser', |
| 80 | + packages: expect.anything(), |
| 81 | + }, |
| 82 | + request: { |
| 83 | + url: expect.stringContaining('/dist/index.html'), |
| 84 | + headers: { |
| 85 | + 'User-Agent': expect.stringContaining(''), |
| 86 | + }, |
| 87 | + }, |
| 88 | + platform: 'javascript', |
| 89 | + }); |
| 90 | +}); |
0 commit comments