diff --git a/dev-packages/browser-integration-tests/loader-suites/loader/noOnLoad/addBreadcrumb/subject.js b/dev-packages/browser-integration-tests/loader-suites/loader/noOnLoad/addBreadcrumb/subject.js new file mode 100644 index 000000000000..5248f5438b8b --- /dev/null +++ b/dev-packages/browser-integration-tests/loader-suites/loader/noOnLoad/addBreadcrumb/subject.js @@ -0,0 +1,6 @@ +Sentry.addBreadcrumb({ + category: 'auth', + message: 'testing loader', + level: 'error', +}); +Sentry.captureMessage('test'); diff --git a/dev-packages/browser-integration-tests/loader-suites/loader/noOnLoad/addBreadcrumb/test.ts b/dev-packages/browser-integration-tests/loader-suites/loader/noOnLoad/addBreadcrumb/test.ts new file mode 100644 index 000000000000..ac8297d6b9f3 --- /dev/null +++ b/dev-packages/browser-integration-tests/loader-suites/loader/noOnLoad/addBreadcrumb/test.ts @@ -0,0 +1,22 @@ +import { expect } from '@playwright/test'; + +import { sentryTest } from '../../../../utils/fixtures'; +import { envelopeRequestParser, waitForErrorRequestOnUrl } from '../../../../utils/helpers'; + +sentryTest('should add breadcrumb to message', async ({ getLocalTestUrl, page }) => { + const url = await getLocalTestUrl({ testDir: __dirname }); + const req = await waitForErrorRequestOnUrl(page, url); + + const eventData = envelopeRequestParser(req); + + expect(eventData.message).toBe('test'); + expect(eventData.breadcrumbs?.length).toBe(1); + expect(eventData.breadcrumbs).toEqual([ + { + category: 'auth', + level: 'error', + message: 'testing loader', + timestamp: expect.any(Number), + }, + ]); +}); diff --git a/dev-packages/browser-integration-tests/loader-suites/loader/onLoad/addBreadcrumb/init.js b/dev-packages/browser-integration-tests/loader-suites/loader/onLoad/addBreadcrumb/init.js new file mode 100644 index 000000000000..19552be67987 --- /dev/null +++ b/dev-packages/browser-integration-tests/loader-suites/loader/onLoad/addBreadcrumb/init.js @@ -0,0 +1,8 @@ +Sentry.onLoad(function () { + Sentry.init({}); + Sentry.addBreadcrumb({ + category: 'auth', + message: 'testing loader', + level: 'error', + }); +}); diff --git a/dev-packages/browser-integration-tests/loader-suites/loader/onLoad/addBreadcrumb/subject.js b/dev-packages/browser-integration-tests/loader-suites/loader/onLoad/addBreadcrumb/subject.js new file mode 100644 index 000000000000..8dc5b1eeb966 --- /dev/null +++ b/dev-packages/browser-integration-tests/loader-suites/loader/onLoad/addBreadcrumb/subject.js @@ -0,0 +1 @@ +Sentry.captureMessage('test'); diff --git a/dev-packages/browser-integration-tests/loader-suites/loader/onLoad/addBreadcrumb/test.ts b/dev-packages/browser-integration-tests/loader-suites/loader/onLoad/addBreadcrumb/test.ts new file mode 100644 index 000000000000..4df22bc99288 --- /dev/null +++ b/dev-packages/browser-integration-tests/loader-suites/loader/onLoad/addBreadcrumb/test.ts @@ -0,0 +1,22 @@ +import { expect } from '@playwright/test'; + +import { sentryTest } from '../../../../utils/fixtures'; +import { envelopeRequestParser, waitForErrorRequestOnUrl } from '../../../../utils/helpers'; + +sentryTest('should add breadcrumb from onLoad callback to message', async ({ getLocalTestUrl, page }) => { + const url = await getLocalTestUrl({ testDir: __dirname }); + const req = await waitForErrorRequestOnUrl(page, url); + + const eventData = envelopeRequestParser(req); + + expect(eventData.message).toBe('test'); + expect(eventData.breadcrumbs?.length).toBe(1); + expect(eventData.breadcrumbs).toEqual([ + { + category: 'auth', + level: 'error', + message: 'testing loader', + timestamp: expect.any(Number), + }, + ]); +}); diff --git a/dev-packages/browser-integration-tests/loader-suites/loader/onLoad/captureException/test.ts b/dev-packages/browser-integration-tests/loader-suites/loader/onLoad/captureException/test.ts index 09a10464c22e..f79d659b16f0 100644 --- a/dev-packages/browser-integration-tests/loader-suites/loader/onLoad/captureException/test.ts +++ b/dev-packages/browser-integration-tests/loader-suites/loader/onLoad/captureException/test.ts @@ -11,3 +11,12 @@ sentryTest('captureException works', async ({ getLocalTestUrl, page }) => { expect(eventData.message).toBe('Test exception'); }); + +sentryTest('should set SENTRY_SDK_SOURCE value', async ({ getLocalTestUrl, page }) => { + const url = await getLocalTestUrl({ testDir: __dirname }); + const req = await waitForErrorRequestOnUrl(page, url); + + const eventData = envelopeRequestParser(req); + + expect(eventData.sdk?.packages?.[0].name).toBe('loader:@sentry/browser'); +}); diff --git a/dev-packages/browser-integration-tests/loader-suites/loader/onLoad/captureExceptionInOnLoad/test.ts b/dev-packages/browser-integration-tests/loader-suites/loader/onLoad/captureExceptionInOnLoad/test.ts index b3cf79bde5c2..90868c3e2e8f 100644 --- a/dev-packages/browser-integration-tests/loader-suites/loader/onLoad/captureExceptionInOnLoad/test.ts +++ b/dev-packages/browser-integration-tests/loader-suites/loader/onLoad/captureExceptionInOnLoad/test.ts @@ -19,3 +19,20 @@ sentryTest('captureException works inside of onLoad', async ({ getLocalTestUrl, expect(eventData.message).toBe('Test exception'); }); + +sentryTest('should set SENTRY_SDK_SOURCE value', 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.sdk?.packages?.[0].name).toBe('loader:@sentry/browser'); +}); diff --git a/packages/browser/test/integration/suites/loader-specific.js b/packages/browser/test/integration/suites/loader-specific.js deleted file mode 100644 index 6ebfd3fb84ab..000000000000 --- a/packages/browser/test/integration/suites/loader-specific.js +++ /dev/null @@ -1,43 +0,0 @@ -var loaderVariants = ['loader-with-no-global-init', 'loader-with-no-global-init-lazy-no']; - -for (var idx in loaderVariants) { - (function () { - describe(loaderVariants[idx], function () { - this.timeout(60000); - this.retries(3); - - var sandbox; - - beforeEach(function (done) { - sandbox = createSandbox(done, loaderVariants[idx]); - }); - - afterEach(function () { - document.body.removeChild(sandbox); - }); - - describe('Loader Specific Tests - With no Global init() call', function () { - it('should add breadcrumb from onLoad callback from undefined error', function () { - return runInSandbox(sandbox, function () { - Sentry.onLoad(function () { - initSDK(); - Sentry.addBreadcrumb({ - category: 'auth', - message: 'testing loader', - level: 'error', - }); - }); - setTimeout(function () { - Sentry.captureMessage('test'); - }); - undefinedMethod(); - }).then(function (summary) { - assert.ok(summary.breadcrumbs); - assert.lengthOf(summary.breadcrumbs, 1); - assert.equal(summary.breadcrumbs[0].message, 'testing loader'); - }); - }); - }); - }); - })(); -} diff --git a/packages/browser/test/integration/suites/loader.js b/packages/browser/test/integration/suites/loader.js deleted file mode 100644 index 55809f81e383..000000000000 --- a/packages/browser/test/integration/suites/loader.js +++ /dev/null @@ -1,67 +0,0 @@ -if (IS_LOADER) { - describe('Loader Specific Tests', function () { - it('should add breadcrumb from onLoad callback from undefined error', function () { - return runInSandbox(sandbox, function () { - Sentry.onLoad(function () { - Sentry.addBreadcrumb({ - category: 'auth', - message: 'testing loader', - level: 'error', - }); - }); - setTimeout(function () { - Sentry.captureMessage('test'); - }); - undefinedMethod(); - }).then(function (summary) { - if (IS_ASYNC_LOADER) { - assert.notOk(summary.events[0].breadcrumbs); - } else { - if (summary.events[0].breadcrumbs) { - assert.ok(summary.events[0].breadcrumbs); - assert.lengthOf(summary.events[0].breadcrumbs, 1); - assert.equal(summary.events[0].breadcrumbs[0].message, 'testing loader'); - } else { - // This seems to be happening only in chrome - assert.notOk(summary.events[0].breadcrumbs); - } - } - }); - }); - - it('should add breadcrumb from onLoad callback from undefined error with custom init()', function () { - return runInSandbox(sandbox, function () { - Sentry.onLoad(function () { - Sentry.init({ debug: true }); - Sentry.addBreadcrumb({ - category: 'auth', - message: 'testing loader', - level: 'error', - }); - }); - setTimeout(function () { - Sentry.captureMessage('test'); - }); - undefinedMethod(); // trigger error - }).then(function (summary) { - assert.ok(summary.events[0].breadcrumbs); - assert.lengthOf(summary.events[0].breadcrumbs, 1); - assert.equal(summary.events[0].breadcrumbs[0].message, 'testing loader'); - }); - }); - - it('should set SENTRY_SDK_SOURCE value', () => { - return runInSandbox(sandbox, function () { - Sentry.onLoad(function () { - Sentry.init({ debug: true }); - }); - setTimeout(function () { - Sentry.captureMessage('test'); - }); - undefinedMethod(); // trigger error - }).then(function (summary) { - assert.equal(summary.events[0].sdk.packages[0].name, 'loader:@sentry/browser'); - }); - }); - }); -} diff --git a/packages/browser/test/integration/suites/shell.js b/packages/browser/test/integration/suites/shell.js index bec3ab7a8768..c8dcdb490104 100644 --- a/packages/browser/test/integration/suites/shell.js +++ b/packages/browser/test/integration/suites/shell.js @@ -24,7 +24,6 @@ function runVariant(variant) { */ {{ suites/onunhandledrejection.js }} // biome-ignore format: No trailing commas {{ suites/builtins.js }} // biome-ignore format: No trailing commas - {{ suites/loader.js }} // biome-ignore format: No trailing commas }); } @@ -33,5 +32,3 @@ for (var idx in variants) { runVariant(variants[idx]); })(); } - -{{ suites/loader-specific.js }} // biome-ignore format: No trailing commas