Skip to content

Commit

Permalink
test(browser): Add integration tests for new XHR Transport (#4814)
Browse files Browse the repository at this point in the history
add integration tests to test the new XHR transport introduced in #4803

* the tests are very similar to the new Fetch transport integration tests introduced in #4765. The only difference is that they disable the browsers' Fetch API by setting window.fetch = undefined. This way, the SDK falls back to the XHR transport.
  • Loading branch information
Lms24 authored Mar 29, 2022
1 parent fa58281 commit 8035b14
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// deactivate fetch s.t. the SDK falls back to XHR transport
window.fetch = undefined;

Sentry.captureException(new Error('this is an error'));
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { expect } from '@playwright/test';
import { Event } from '@sentry/types';

import { sentryTest } from '../../../utils/fixtures';
import { getFirstSentryEnvelopeRequest } from '../../../utils/helpers';

sentryTest('should capture an error with the new fetch transport', async ({ getLocalTestPath, page }) => {
const url = await getLocalTestPath({ testDir: __dirname });

const eventData = await getFirstSentryEnvelopeRequest<Event>(page, url);

expect(eventData.exception?.values).toHaveLength(1);
expect(eventData.exception?.values?.[0]).toMatchObject({
type: 'Error',
value: 'this is an error',
mechanism: {
type: 'generic',
handled: true,
},
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// deactivate fetch s.t. the SDK falls back to XHR transport
window.fetch = undefined;

const transaction = Sentry.startTransaction({ name: 'test_transaction_1' });
transaction.finish();
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { expect } from '@playwright/test';
import { Event } from '@sentry/types';

import { sentryTest } from '../../../utils/fixtures';
import { getFirstSentryEnvelopeRequest } from '../../../utils/helpers';

sentryTest('should report a transaction with the new XHR transport', async ({ getLocalTestPath, page }) => {
const url = await getLocalTestPath({ testDir: __dirname });
const transaction = await getFirstSentryEnvelopeRequest<Event>(page, url);

expect(transaction.transaction).toBe('test_transaction_1');
expect(transaction.spans).toBeDefined();
});

0 comments on commit 8035b14

Please sign in to comment.