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