Skip to content

Commit 29cf397

Browse files
committed
better tests for bundle etc.
1 parent d5cda61 commit 29cf397

File tree

6 files changed

+114
-104
lines changed

6 files changed

+114
-104
lines changed

.github/workflows/build.yml

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -622,21 +622,20 @@ jobs:
622622
- bundle
623623
- bundle_min
624624
- bundle_replay
625-
- bundle_replay_min
626625
- bundle_tracing
627-
- bundle_tracing_min
628626
- bundle_tracing_replay
629-
- bundle_tracing_replay_min
627+
- bundle_tracing_replay_feedback
628+
- bundle_tracing_replay_feedback_min
630629
project:
631630
- chromium
632631
include:
633632
# Only check all projects for esm & full bundle
634633
# We also shard the tests as they take the longest
635-
- bundle: bundle_tracing_replay_min
634+
- bundle: bundle_tracing_replay_feedback_min
636635
project: ''
637636
shard: 1
638637
shards: 2
639-
- bundle: bundle_tracing_replay_min
638+
- bundle: bundle_tracing_replay_feedback_min
640639
project: ''
641640
shard: 2
642641
shards: 2
@@ -653,7 +652,7 @@ jobs:
653652
shards: 3
654653
exclude:
655654
# Do not run the default chromium-only tests
656-
- bundle: bundle_tracing_replay_min
655+
- bundle: bundle_tracing_replay_feedback_min
657656
project: 'chromium'
658657
- bundle: esm
659658
project: 'chromium'

dev-packages/browser-integration-tests/package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
"test:bundle:replay:min": "PW_BUNDLE=bundle_replay_min yarn test",
2424
"test:bundle:tracing": "PW_BUNDLE=bundle_tracing yarn test",
2525
"test:bundle:tracing:min": "PW_BUNDLE=bundle_tracing_min yarn test",
26+
"test:bundle:full": "PW_BUNDLE=bundle_tracing_replay_feedback yarn test",
27+
"test:bundle:full:min": "PW_BUNDLE=bundle_tracing_replay_feedback_min yarn test",
2628
"test:cjs": "PW_BUNDLE=cjs yarn test",
2729
"test:esm": "PW_BUNDLE=esm yarn test",
2830
"test:loader": "npx playwright test -c playwright.loader.config.ts --project='chromium'",

dev-packages/browser-integration-tests/suites/feedback/captureFeedback/test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import { expect } from '@playwright/test';
22

33
import { sentryTest } from '../../../utils/fixtures';
4-
import { envelopeRequestParser, getEnvelopeType } from '../../../utils/helpers';
4+
import { envelopeRequestParser, getEnvelopeType, shouldSkipFeedbackTest } from '../../../utils/helpers';
55

6-
sentryTest('should capture feedback (@sentry-internal/feedback import)', async ({ getLocalTestPath, page }) => {
7-
if (process.env.PW_BUNDLE) {
6+
sentryTest('should capture feedback', async ({ getLocalTestPath, page }) => {
7+
if (shouldSkipFeedbackTest()) {
88
sentryTest.skip();
99
}
1010

Lines changed: 90 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -1,107 +1,109 @@
11
import { expect } from '@playwright/test';
22

33
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';
611

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+
}
1316

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();
1922

20-
const postData = req.postData();
21-
if (!postData) {
22-
return false;
23-
}
23+
const postData = req.postData();
24+
if (!postData) {
25+
return false;
26+
}
2427

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+
});
3134

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' }),
3840
});
41+
});
3942

40-
const url = await getLocalTestPath({ testDir: __dirname });
43+
const url = await getLocalTestPath({ testDir: __dirname });
4144

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]);
4346

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');
4851

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]);
5154

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+
]);
5760

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);
6366

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+
);
7477

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',
9988
url: expect.stringContaining('/dist/index.html'),
100-
headers: {
101-
'User-Agent': expect.stringContaining(''),
102-
},
10389
},
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+
});

dev-packages/browser-integration-tests/utils/generatePlugin.ts

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,21 +26,14 @@ const useLoader = bundleKey.startsWith('loader');
2626
// In this case, if we encounter this import, we want to add this CDN bundle file instead
2727
const IMPORTED_INTEGRATION_CDN_BUNDLE_PATHS: Record<string, string> = {
2828
httpClientIntegration: 'httpclient',
29-
HttpClient: 'httpclient',
3029
captureConsoleIntegration: 'captureconsole',
3130
CaptureConsole: 'captureconsole',
3231
debugIntegration: 'debug',
33-
Debug: 'debug',
3432
rewriteFramesIntegration: 'rewriteframes',
35-
RewriteFrames: 'rewriteframes',
3633
contextLinesIntegration: 'contextlines',
37-
ContextLines: 'contextlines',
3834
extraErrorDataIntegration: 'extraerrordata',
39-
ExtraErrorData: 'extraerrordata',
4035
reportingObserverIntegration: 'reportingobserver',
41-
ReportingObserver: 'reportingobserver',
4236
sessionTimingIntegration: 'sessiontiming',
43-
SessionTiming: 'sessiontiming',
4437
};
4538

4639
const BUNDLE_PATHS: Record<string, Record<string, string>> = {
@@ -55,6 +48,8 @@ const BUNDLE_PATHS: Record<string, Record<string, string>> = {
5548
bundle_tracing_min: 'build/bundles/bundle.tracing.min.js',
5649
bundle_tracing_replay: 'build/bundles/bundle.tracing.replay.js',
5750
bundle_tracing_replay_min: 'build/bundles/bundle.tracing.replay.min.js',
51+
bundle_tracing_replay_feedback: 'build/bundles/bundle.tracing.replay.feedback.js',
52+
bundle_tracing_replay_feedback_min: 'build/bundles/bundle.tracing.replay.feedback.min.js',
5853
loader_base: 'build/bundles/bundle.min.js',
5954
loader_eager: 'build/bundles/bundle.min.js',
6055
loader_debug: 'build/bundles/bundle.debug.min.js',

dev-packages/browser-integration-tests/utils/helpers.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,18 @@ export function shouldSkipTracingTest(): boolean {
189189
return bundle != null && !bundle.includes('tracing') && !bundle.includes('esm') && !bundle.includes('cjs');
190190
}
191191

192+
/**
193+
* We can only test replay tests in certain bundles/packages:
194+
* - NPM (ESM, CJS)
195+
* - CDN bundles that contain the Replay integration
196+
*
197+
* @returns `true` if we should skip the feedback test
198+
*/
199+
export function shouldSkipFeedbackTest(): boolean {
200+
const bundle = process.env.PW_BUNDLE as string | undefined;
201+
return bundle != null && !bundle.includes('feedback') && !bundle.includes('esm') && !bundle.includes('cjs');
202+
}
203+
192204
/**
193205
* Waits until a number of requests matching urlRgx at the given URL arrive.
194206
* If the timout option is configured, this function will abort waiting, even if it hasn't reveived the configured

0 commit comments

Comments
 (0)