Skip to content

Commit 8d5c306

Browse files
authored
test(loader): Improve loader tests & update loader (#9245)
This updates the loader based on this PR: getsentry/sentry#58070 and also actually fixes/improves the loader tests by avoiding importing `@sentry/browser`. This is not needed and actually obfuscates the "real"/"normal" behavior (just look at the generated `dist` folder for a test. Instead, I added an eslint rule to allow `Sentry` as a global for these cases, and just access them directly. This also uncovered an incorrect test, which I adjusted so it works. I also added a new test to ensure custom config works.
1 parent aea3905 commit 8d5c306

File tree

21 files changed

+103
-39
lines changed

21 files changed

+103
-39
lines changed

.prettierignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
*.md
22
.nxcache
3+
packages/browser-integration-tests/fixtures/loader.js

packages/browser-integration-tests/.eslintrc.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,14 @@ module.exports = {
1313
'fixtures/**',
1414
'tmp/**',
1515
],
16+
overrides: [
17+
{
18+
files: ['loader-suites/**/{subject,init}.js'],
19+
globals: {
20+
Sentry: true,
21+
},
22+
},
23+
],
1624
parserOptions: {
1725
sourceType: 'module',
1826
},

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.
Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1 @@
1-
import * as Sentry from '@sentry/browser';
21

3-
window.Sentry = Sentry;
Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1 @@
1-
import * as Sentry from '@sentry/browser';
2-
3-
window.Sentry = Sentry;
41
window._testBaseTimestamp = performance.timeOrigin / 1000;
Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1 @@
1-
import * as Sentry from '@sentry/browser';
21

3-
window.Sentry = Sentry;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ setTimeout(() => {
33
cdnScript.src = '/cdn.bundle.js';
44

55
cdnScript.addEventListener('load', () => {
6-
window.Sentry.init({
6+
Sentry.init({
77
dsn: 'https://[email protected]/1337',
88
replaysSessionSampleRate: 0.42,
99
});
Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
1-
import * as Sentry from '@sentry/browser';
2-
3-
window.Sentry = Sentry;
4-
51
Sentry.onLoad(function () {
2+
// You _have_ to call Sentry.init() before calling Sentry.captureException() in Sentry.onLoad()!
3+
Sentry.init();
64
Sentry.captureException('Test exception');
75
});

packages/browser-integration-tests/loader-suites/loader/onLoad/captureExceptionInOnLoad/test.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,14 @@ import { sentryTest } from '../../../../utils/fixtures';
44
import { envelopeRequestParser, waitForErrorRequestOnUrl } from '../../../../utils/helpers';
55

66
sentryTest('captureException works inside of onLoad', async ({ getLocalTestUrl, page }) => {
7+
await page.route('https://dsn.ingest.sentry.io/**/*', route => {
8+
return route.fulfill({
9+
status: 200,
10+
contentType: 'application/json',
11+
body: JSON.stringify({ id: 'test-id' }),
12+
});
13+
});
14+
715
const url = await getLocalTestUrl({ testDir: __dirname });
816
const req = await waitForErrorRequestOnUrl(page, url);
917

packages/browser-integration-tests/loader-suites/loader/onLoad/customBrowserTracing/init.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
import * as Sentry from '@sentry/browser';
2-
3-
window.Sentry = Sentry;
41
window._testBaseTimestamp = performance.timeOrigin / 1000;
52

63
Sentry.onLoad(function () {

0 commit comments

Comments
 (0)