Skip to content

Commit

Permalink
test: Port loader tests from karma to playwright (#11688)
Browse files Browse the repository at this point in the history
This ports `packages/browser/test/integration/suites/loader.js` and
`packages/browser/test/integration/suites/loader-specific.js` to
playwright. Specifically it just adds tests for SDK source and
breadcrumbs, which were missing previously.

ref #11084
  • Loading branch information
AbhiPrasad authored Apr 19, 2024
1 parent 3a45a3c commit fce8e8c
Show file tree
Hide file tree
Showing 10 changed files with 85 additions and 113 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Sentry.addBreadcrumb({
category: 'auth',
message: 'testing loader',
level: 'error',
});
Sentry.captureMessage('test');
Original file line number Diff line number Diff line change
@@ -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),
},
]);
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
Sentry.onLoad(function () {
Sentry.init({});
Sentry.addBreadcrumb({
category: 'auth',
message: 'testing loader',
level: 'error',
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Sentry.captureMessage('test');
Original file line number Diff line number Diff line change
@@ -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),
},
]);
});
Original file line number Diff line number Diff line change
Expand Up @@ -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');
});
Original file line number Diff line number Diff line change
Expand Up @@ -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');
});
43 changes: 0 additions & 43 deletions packages/browser/test/integration/suites/loader-specific.js

This file was deleted.

67 changes: 0 additions & 67 deletions packages/browser/test/integration/suites/loader.js

This file was deleted.

3 changes: 0 additions & 3 deletions packages/browser/test/integration/suites/shell.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
});
}

Expand All @@ -33,5 +32,3 @@ for (var idx in variants) {
runVariant(variants[idx]);
})();
}

{{ suites/loader-specific.js }} // biome-ignore format: No trailing commas

0 comments on commit fce8e8c

Please sign in to comment.