Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
*.md
.nxcache
packages/browser-integration-tests/fixtures/loader.js
8 changes: 8 additions & 0 deletions packages/browser-integration-tests/.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,14 @@ module.exports = {
'fixtures/**',
'tmp/**',
],
overrides: [
{
files: ['loader-suites/**/{subject,init}.js'],
globals: {
Sentry: true,
},
},
],
parserOptions: {
sourceType: 'module',
},
Expand Down
2 changes: 1 addition & 1 deletion packages/browser-integration-tests/fixtures/loader.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
import * as Sentry from '@sentry/browser';

window.Sentry = Sentry;
Original file line number Diff line number Diff line change
@@ -1,4 +1 @@
import * as Sentry from '@sentry/browser';

window.Sentry = Sentry;
window._testBaseTimestamp = performance.timeOrigin / 1000;
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
import * as Sentry from '@sentry/browser';

window.Sentry = Sentry;
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ setTimeout(() => {
cdnScript.src = '/cdn.bundle.js';

cdnScript.addEventListener('load', () => {
window.Sentry.init({
Sentry.init({
dsn: 'https://[email protected]/1337',
replaysSessionSampleRate: 0.42,
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import * as Sentry from '@sentry/browser';

window.Sentry = Sentry;

Sentry.onLoad(function () {
// You _have_ to call Sentry.init() before calling Sentry.captureException() in Sentry.onLoad()!
Sentry.init();
Sentry.captureException('Test exception');
});
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,14 @@ import { sentryTest } from '../../../../utils/fixtures';
import { envelopeRequestParser, waitForErrorRequestOnUrl } from '../../../../utils/helpers';

sentryTest('captureException works inside of onLoad', async ({ getLocalTestUrl, page }) => {
await page.route('https://dsn.ingest.sentry.io/**/*', route => {
return route.fulfill({
status: 200,
contentType: 'application/json',
body: JSON.stringify({ id: 'test-id' }),
});
});

const url = await getLocalTestUrl({ testDir: __dirname });
const req = await waitForErrorRequestOnUrl(page, url);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
import * as Sentry from '@sentry/browser';

window.Sentry = Sentry;
window._testBaseTimestamp = performance.timeOrigin / 1000;

Sentry.onLoad(function () {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
window.__sentryOnLoad = 0;

setTimeout(() => {
Sentry.onLoad(function () {
window.__hadSentry = window.sentryIsLoaded();

Sentry.init({
sampleRate: 0.5,
});

window.__sentryOnLoad++;
});
});

window.sentryIsLoaded = () => {
const __sentry = window.__SENTRY__;

// If there is a global __SENTRY__ that means that in any of the callbacks init() was already invoked
return !!(!(typeof __sentry === 'undefined') && __sentry.hub && __sentry.hub.getClient());
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { expect } from '@playwright/test';

import { sentryTest } from '../../../../utils/fixtures';
import { LOADER_CONFIGS } from '../../../../utils/generatePlugin';

const bundle = process.env.PW_BUNDLE || '';
const isLazy = LOADER_CONFIGS[bundle]?.lazy;

sentryTest('always calls onLoad init correctly', async ({ getLocalTestUrl, page }) => {
await page.route('https://dsn.ingest.sentry.io/**/*', route => {
return route.fulfill({
status: 200,
contentType: 'application/json',
body: JSON.stringify({ id: 'test-id' }),
});
});

const url = await getLocalTestUrl({ testDir: __dirname });

await page.goto(url);

// We want to test that if we are _not_ lazy, we are correctly calling onLoad init()
// But if we are lazy and call `forceLoad`, we also call the onLoad init() correctly
if (isLazy) {
expect(await page.evaluate('window.__sentryOnLoad')).toEqual(0);
await page.evaluate('Sentry.forceLoad()');
}

await page.waitForFunction('window.__sentryOnLoad && window.sentryIsLoaded()');

expect(await page.evaluate('window.__hadSentry')).toEqual(false);
expect(await page.evaluate('window.__sentryOnLoad')).toEqual(1);
expect(await page.evaluate('Sentry.getCurrentHub().getClient().getOptions().sampleRate')).toEqual(0.5);
});
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
import * as Sentry from '@sentry/browser';

window.Sentry = Sentry;

class CustomIntegration {
constructor() {
this.name = 'CustomIntegration';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
import * as Sentry from '@sentry/browser';

window.Sentry = Sentry;

class CustomIntegration {
constructor() {
this.name = 'CustomIntegration';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
import * as Sentry from '@sentry/browser';

window.Sentry = Sentry;

Sentry.onLoad(function () {
Sentry.init({
integrations: [
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
import * as Sentry from '@sentry/browser';

window.Sentry = Sentry;

Sentry.onLoad(function () {
Sentry.init({});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Sentry.forceLoad();

setTimeout(() => {
Sentry.onLoad(function () {
Sentry.captureException('Test exception');
});
}, 200);
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { expect } from '@playwright/test';

import { sentryTest } from '../../../../utils/fixtures';
import { envelopeRequestParser, waitForErrorRequestOnUrl } from '../../../../utils/helpers';

sentryTest('late onLoad call is handled', async ({ getLocalTestUrl, page }) => {
await page.route('https://dsn.ingest.sentry.io/**/*', route => {
return route.fulfill({
status: 200,
contentType: 'application/json',
body: JSON.stringify({ id: 'test-id' }),
});
});

const url = await getLocalTestUrl({ testDir: __dirname });
const req = await waitForErrorRequestOnUrl(page, url);

const eventData = envelopeRequestParser(req);

expect(eventData.message).toBe('Test exception');
});
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
import * as Sentry from '@sentry/browser';

window.Sentry = Sentry;
window._testBaseTimestamp = performance.timeOrigin / 1000;

Sentry.onLoad(function () {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
import * as Sentry from '@sentry/browser';

window.Sentry = Sentry;

Sentry.onLoad(function () {
Sentry.init({});
});