Skip to content

Commit 31e9fe7

Browse files
committed
rename tests & add breadcrumb tests
1 parent 56910d2 commit 31e9fe7

File tree

18 files changed

+198
-11
lines changed

18 files changed

+198
-11
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
const xhr = new XMLHttpRequest();
2+
3+
fetch('http://localhost:7654/foo').then(() => {
4+
Sentry.captureException('test error');
5+
});
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import type { Event } from '@sentry/types';
44
import { sentryTest } from '../../../../../utils/fixtures';
55
import { getFirstSentryEnvelopeRequest } from '../../../../../utils/helpers';
66

7-
sentryTest('adds a breadcrumb for basic fetch GET request', async ({ getLocalTestPath, page }) => {
7+
sentryTest('captures Breadcrumb for basic GET request', async ({ getLocalTestPath, page }) => {
88
const url = await getLocalTestPath({ testDir: __dirname });
99

1010
await page.route('**/foo', route => {
@@ -30,7 +30,6 @@ sentryTest('adds a breadcrumb for basic fetch GET request', async ({ getLocalTes
3030
type: 'http',
3131
data: {
3232
method: 'GET',
33-
response_body_size: 29,
3433
status_code: 200,
3534
url: 'http://localhost:7654/foo',
3635
},
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import * as Sentry from '@sentry/browser';
2+
3+
window.Sentry = Sentry;
4+
5+
Sentry.init({
6+
dsn: 'https://[email protected]/1337',
7+
defaultIntegrations: false,
8+
integrations: [new Sentry.Integrations.Breadcrumbs()],
9+
sampleRate: 1,
10+
});
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
const xhr = new XMLHttpRequest();
2+
3+
fetch('http://localhost:7654/foo', {
4+
method: 'POST',
5+
body: '{"my":"body"}',
6+
headers: {
7+
Accept: 'application/json',
8+
'Content-Type': 'application/json',
9+
Cache: 'no-cache',
10+
},
11+
}).then(() => {
12+
Sentry.captureException('test error');
13+
});
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import { expect } from '@playwright/test';
2+
import type { Event } from '@sentry/types';
3+
4+
import { sentryTest } from '../../../../../utils/fixtures';
5+
import { getFirstSentryEnvelopeRequest } from '../../../../../utils/helpers';
6+
7+
sentryTest('captures Breadcrumb for POST request', async ({ getLocalTestPath, page }) => {
8+
const url = await getLocalTestPath({ testDir: __dirname });
9+
10+
await page.route('**/foo', route => {
11+
return route.fulfill({
12+
status: 200,
13+
body: JSON.stringify({
14+
userNames: ['John', 'Jane'],
15+
}),
16+
headers: {
17+
'Content-Type': 'application/json',
18+
},
19+
});
20+
});
21+
22+
const eventData = await getFirstSentryEnvelopeRequest<Event>(page, url);
23+
24+
expect(eventData.exception?.values).toHaveLength(1);
25+
26+
expect(eventData?.breadcrumbs?.length).toBe(1);
27+
expect(eventData!.breadcrumbs![0]).toEqual({
28+
timestamp: expect.any(Number),
29+
category: 'fetch',
30+
type: 'http',
31+
data: {
32+
method: 'POST',
33+
status_code: 200,
34+
url: 'http://localhost:7654/foo',
35+
},
36+
});
37+
});
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
const xhr = new XMLHttpRequest();
2+
3+
xhr.open('GET', 'http://localhost:7654/foo');
4+
xhr.send();
5+
6+
xhr.addEventListener('readystatechange', function () {
7+
if (xhr.readyState === 4) {
8+
Sentry.captureException('test error');
9+
}
10+
});
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import type { Event } from '@sentry/types';
44
import { sentryTest } from '../../../../../utils/fixtures';
55
import { getFirstSentryEnvelopeRequest } from '../../../../../utils/helpers';
66

7-
sentryTest('adds a breadcrumb for basic XHR GET request', async ({ getLocalTestPath, page }) => {
7+
sentryTest('captures Breadcrumb for basic GET request', async ({ getLocalTestPath, page }) => {
88
const url = await getLocalTestPath({ testDir: __dirname });
99

1010
await page.route('**/foo', route => {
@@ -15,6 +15,7 @@ sentryTest('adds a breadcrumb for basic XHR GET request', async ({ getLocalTestP
1515
}),
1616
headers: {
1717
'Content-Type': 'application/json',
18+
'Content-Length': '',
1819
},
1920
});
2021
});
@@ -30,7 +31,6 @@ sentryTest('adds a breadcrumb for basic XHR GET request', async ({ getLocalTestP
3031
type: 'http',
3132
data: {
3233
method: 'GET',
33-
response_body_size: 29,
3434
status_code: 200,
3535
url: 'http://localhost:7654/foo',
3636
},
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import * as Sentry from '@sentry/browser';
2+
3+
window.Sentry = Sentry;
4+
5+
Sentry.init({
6+
dsn: 'https://[email protected]/1337',
7+
defaultIntegrations: false,
8+
integrations: [new Sentry.Integrations.Breadcrumbs()],
9+
sampleRate: 1,
10+
});
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
const xhr = new XMLHttpRequest();
2+
3+
xhr.open('POST', 'http://localhost:7654/foo');
4+
xhr.setRequestHeader('Accept', 'application/json');
5+
xhr.setRequestHeader('Content-Type', 'application/json');
6+
xhr.send('{"my":"body"}');
7+
8+
xhr.addEventListener('readystatechange', function () {
9+
if (xhr.readyState === 4) {
10+
Sentry.captureException('test error');
11+
}
12+
});
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import { expect } from '@playwright/test';
2+
import type { Event } from '@sentry/types';
3+
4+
import { sentryTest } from '../../../../../utils/fixtures';
5+
import { getFirstSentryEnvelopeRequest } from '../../../../../utils/helpers';
6+
7+
sentryTest('captures Breadcrumb for POST request', async ({ getLocalTestPath, page }) => {
8+
const url = await getLocalTestPath({ testDir: __dirname });
9+
10+
await page.route('**/foo', route => {
11+
return route.fulfill({
12+
status: 200,
13+
body: JSON.stringify({
14+
userNames: ['John', 'Jane'],
15+
}),
16+
headers: {
17+
'Content-Type': 'application/json',
18+
},
19+
});
20+
});
21+
22+
const eventData = await getFirstSentryEnvelopeRequest<Event>(page, url);
23+
24+
expect(eventData.exception?.values).toHaveLength(1);
25+
26+
expect(eventData?.breadcrumbs?.length).toBe(1);
27+
expect(eventData!.breadcrumbs![0]).toEqual({
28+
timestamp: expect.any(Number),
29+
category: 'xhr',
30+
type: 'http',
31+
data: {
32+
method: 'POST',
33+
status_code: 200,
34+
url: 'http://localhost:7654/foo',
35+
},
36+
});
37+
});

packages/integration-tests/suites/integrations/ExtendedNetworkBreadcrumbs/fetch/post/test.ts renamed to packages/integration-tests/suites/integrations/ExtendedNetworkBreadcrumbs/fetch/noContentLengthHeader/test.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import type { Event } from '@sentry/types';
44
import { sentryTest } from '../../../../../utils/fixtures';
55
import { getFirstSentryEnvelopeRequest } from '../../../../../utils/helpers';
66

7-
sentryTest('adds a breadcrumb for basic fetch POST request', async ({ getLocalTestPath, page }) => {
7+
sentryTest('does not capture response_body_size without Content-Length header', async ({ getLocalTestPath, page }) => {
88
const url = await getLocalTestPath({ testDir: __dirname });
99

1010
await page.route('**/foo', route => {
@@ -30,9 +30,7 @@ sentryTest('adds a breadcrumb for basic fetch POST request', async ({ getLocalTe
3030
category: 'fetch',
3131
type: 'http',
3232
data: {
33-
method: 'POST',
34-
request_body_size: 13,
35-
// No response_body_size without Content-Length header!
33+
method: 'GET',
3634
status_code: 200,
3735
url: 'http://localhost:7654/foo',
3836
},
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import { expect } from '@playwright/test';
2+
import type { Event } from '@sentry/types';
3+
4+
import { sentryTest } from '../../../../../utils/fixtures';
5+
import { getFirstSentryEnvelopeRequest } from '../../../../../utils/helpers';
6+
7+
sentryTest('captures request_body_size when body is sent', async ({ getLocalTestPath, page }) => {
8+
const url = await getLocalTestPath({ testDir: __dirname });
9+
10+
await page.route('**/foo', route => {
11+
return route.fulfill({
12+
status: 200,
13+
body: JSON.stringify({
14+
userNames: ['John', 'Jane'],
15+
}),
16+
headers: {
17+
'Content-Type': 'application/json',
18+
},
19+
});
20+
});
21+
22+
const eventData = await getFirstSentryEnvelopeRequest<Event>(page, url);
23+
24+
expect(eventData.exception?.values).toHaveLength(1);
25+
26+
expect(eventData?.breadcrumbs?.length).toBe(1);
27+
expect(eventData!.breadcrumbs![0].data!.request_body_size).toEqual(13);
28+
});

packages/integration-tests/suites/integrations/ExtendedNetworkBreadcrumbs/xhr/post/test.ts renamed to packages/integration-tests/suites/integrations/ExtendedNetworkBreadcrumbs/xhr/noContentLengthHeader/test.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import type { Event } from '@sentry/types';
44
import { sentryTest } from '../../../../../utils/fixtures';
55
import { getFirstSentryEnvelopeRequest } from '../../../../../utils/helpers';
66

7-
sentryTest('adds a breadcrumb for basic XHR POST request', async ({ getLocalTestPath, page }) => {
7+
sentryTest('captures response_body_size without Content-Length header', async ({ getLocalTestPath, page }) => {
88
const url = await getLocalTestPath({ testDir: __dirname });
99

1010
await page.route('**/foo', route => {
@@ -30,8 +30,7 @@ sentryTest('adds a breadcrumb for basic XHR POST request', async ({ getLocalTest
3030
category: 'xhr',
3131
type: 'http',
3232
data: {
33-
method: 'POST',
34-
request_body_size: 13,
33+
method: 'GET',
3534
response_body_size: 29,
3635
status_code: 200,
3736
url: 'http://localhost:7654/foo',
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import { expect } from '@playwright/test';
2+
import type { Event } from '@sentry/types';
3+
4+
import { sentryTest } from '../../../../../utils/fixtures';
5+
import { getFirstSentryEnvelopeRequest } from '../../../../../utils/helpers';
6+
7+
sentryTest('captures request_body_size when body is sent', async ({ getLocalTestPath, page }) => {
8+
const url = await getLocalTestPath({ testDir: __dirname });
9+
10+
await page.route('**/foo', route => {
11+
return route.fulfill({
12+
status: 200,
13+
body: JSON.stringify({
14+
userNames: ['John', 'Jane'],
15+
}),
16+
headers: {
17+
'Content-Type': 'application/json',
18+
'Content-Length': '',
19+
},
20+
});
21+
});
22+
23+
const eventData = await getFirstSentryEnvelopeRequest<Event>(page, url);
24+
25+
expect(eventData.exception?.values).toHaveLength(1);
26+
27+
expect(eventData?.breadcrumbs?.length).toBe(1);
28+
expect(eventData!.breadcrumbs![0].data!.request_body_size).toEqual(13);
29+
});

0 commit comments

Comments
 (0)