8000 test(browser): Add integration tests for new XHR Transport (#4814) · michax/sentry-javascript@8035b14 · GitHub
[go: up one dir, main page]

Skip to content

Commit 8035b14

Browse files
authored
test(browser): Add integration tests for new XHR Transport (getsentry#4814)
add integration tests to test the new XHR transport introduced in getsentry#4803 * the tests are very similar to the new Fetch transport integration tests introduced in getsentry#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.
1 parent fa58281 commit 8035b14

File tree

4 files changed

+43
-0
lines changed

4 files changed

+43
-0
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
// deactivate fetch s.t. the SDK falls back to XHR transport
2+
window.fetch = undefined;
3+
4+
Sentry.captureException(new Error('this is an error'));
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import { expect } from '@playwright/test';
2+
import { Event } from '@sentry/types';
3+
4+
import { sentryTest } from '../../../utils/fixtures';
5+
import { getFirstSentryEnvelopeRequest } from '../../../utils/helpers';
6+
7+
sentryTest('should capture an error with the new fetch transport', async ({ getLocalTestPath, page }) => {
8+
const url = await getLocalTestPath({ testDir: __dirname });
9+
10+
const eventData = await getFirstSentryEnvelopeRequest<Event>(page, url);
11+
12+
expect(eventData.exception?.values).toHaveLength(1);
13+
expect(eventData.exception?.values?.[0]).toMatchObject({
14+
type: 'Error',
15+
value: 'this is an error',
16+
mechanism: {
17+
type: 'generic',
18+
handled: true,
19+
},
20+
});
21+
});
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
// deactivate fetch s.t. the SDK falls back to XHR transport
2+
window.fetch = undefined;
3+
4+
const transaction = Sentry.startTransaction({ name: 'test_transaction_1' });
5+
transaction.finish();
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { expect } from '@playwright/test';
2+
import { Event } from '@sentry/types';
3+
4+
import { sentryTest } from '../../../utils/fixtures';
5+
import { getFirstSentryEnvelopeRequest } from '../../../utils/helpers';
6+
7+
sentryTest('should report a transaction with the new XHR transport', async ({ getLocalTestPath, page }) => {
8+
const url = await getLocalTestPath({ testDir: __dirname });
9+
const transaction = await getFirstSentryEnvelopeRequest<Event>(page, url);
10+
11+
expect(transaction.transaction).toBe('test_transaction_1');
12+
expect(transaction.spans).toBeDefined();
13+
});

0 commit comments

Comments
 (0)
0