Skip to content

Commit 626e2d1

Browse files
committed
adjust
1 parent fd1ca9c commit 626e2d1

File tree

3 files changed

+32
-2
lines changed

3 files changed

+32
-2
lines changed

packages/browser-integration-tests/fixtures/loader.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/browser-integration-tests/loader-suites/loader/noOnLoad/sdkLoadedInMeanwhile/subject.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ setTimeout(() => {
55
cdnScript.addEventListener('load', () => {
66
window.Sentry.init({
77
dsn: 'https://[email protected]/1337',
8+
replaysSessionSampleRate: 0.42,
89
});
910

1011
setTimeout(() => {

packages/browser-integration-tests/loader-suites/loader/noOnLoad/sdkLoadedInMeanwhile/test.ts

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,17 @@ sentryTest('it does not download the SDK if the SDK was loaded in the meanwhile'
1616
}
1717

1818
let cdnLoadedCount = 0;
19+
let sentryEventCount = 0;
20+
21+
await page.route('https://dsn.ingest.sentry.io/**/*', route => {
22+
sentryEventCount++;
23+
24+
return route.fulfill({
25+
status: 200,
26+
contentType: 'application/json',
27+
body: JSON.stringify({ id: 'test-id' }),
28+
});
29+
});
1930

2031
await page.route(`${TEST_HOST}/*.*`, route => {
2132
const file = route.request().url().split('/').pop();
@@ -37,7 +48,25 @@ sentryTest('it does not download the SDK if the SDK was loaded in the meanwhile'
3748

3849
const eventData = envelopeRequestParser(await req);
3950

51+
await waitForFunction(() => cdnLoadedCount === 2);
52+
53+
// Still loaded the CDN bundle twice
54+
expect(cdnLoadedCount).toBe(2);
55+
56+
// But only sent to Sentry once
57+
expect(sentryEventCount).toBe(1);
58+
59+
// Ensure loader does not overwrite init/config
60+
const options = await page.evaluate(() => (window as any).Sentry.getCurrentHub().getClient()?.getOptions());
61+
expect(options?.replaysSessionSampleRate).toBe(0.42);
62+
4063
expect(eventData.exception?.values?.length).toBe(1);
4164
expect(eventData.exception?.values?.[0]?.value).toBe('window.doSomethingWrong is not a function');
42-
expect(cdnLoadedCount).toBe(1);
4365
});
66+
67+
async function waitForFunction(cb: () => boolean, timeout = 2000, increment = 100) {
68+
while (timeout > 0 && !cb()) {
69+
await new Promise(resolve => setTimeout(resolve, increment));
70+
await waitForFunction(cb, timeout - increment, increment);
71+
}
72+
}

0 commit comments

Comments
 (0)