Skip to content

Commit 8efa39e

Browse files
authored
test(node): Add captureException integration tests (#4783)
1 parent b52afc9 commit 8efa39e

File tree

6 files changed

+76
-4
lines changed

6 files changed

+76
-4
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import * as Sentry from '@sentry/node';
2+
3+
Sentry.init({
4+
dsn: 'https://public@dsn.ingest.sentry.io/1337',
5+
release: '1.0',
6+
});
7+
8+
try {
9+
throw new Error('catched_error');
10+
} catch (err) {
11+
Sentry.captureException(err);
12+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import { assertSentryEvent, getEventRequest, runServer } from '../../../../utils';
2+
3+
test('should work inside catch block', async () => {
4+
const url = await runServer(__dirname);
5+
const requestBody = await getEventRequest(url);
6+
7+
assertSentryEvent(requestBody, {
8+
exception: {
9+
values: [
10+
{
11+
type: 'Error',
12+
value: 'catched_error',
13+
mechanism: {
14+
type: 'generic',
15+
handled: true,
16+
},
17+
stacktrace: {
18+
frames: expect.any(Array),
19+
},
20+
},
21+
],
22+
},
23+
});
24+
});

packages/node-integration-tests/suites/public-api/capture-exception/scenario.ts renamed to packages/node-integration-tests/suites/public-api/captureException/empty-obj/scenario.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@ Sentry.init({
55
release: '1.0',
66
});
77

8-
Sentry.captureException(new Error('Captured Error'));
8+
Sentry.captureException({});

packages/node-integration-tests/suites/public-api/capture-exception/test.ts renamed to packages/node-integration-tests/suites/public-api/captureException/empty-obj/test.ts

+7-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import { assertSentryEvent, getEventRequest, runServer } from '../../../utils';
1+
import { assertSentryEvent, getEventRequest, runServer } from '../../../../utils';
22

3-
test('should send captureException', async () => {
3+
test('should capture an empty object', async () => {
44
const url = await runServer(__dirname);
55
const requestBody = await getEventRequest(url);
66

@@ -9,7 +9,11 @@ test('should send captureException', async () => {
99
values: [
1010
{
1111
type: 'Error',
12-
value: 'Captured Error',
12+
value: 'Non-Error exception captured with keys: [object has no keys]',
13+
mechanism: {
14+
type: 'generic',
15+
handled: true,
16+
},
1317
},
1418
],
1519
},
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import * as Sentry from '@sentry/node';
2+
3+
Sentry.init({
4+
dsn: 'https://public@dsn.ingest.sentry.io/1337',
5+
release: '1.0',
6+
});
7+
8+
Sentry.captureException(new Error('test_simple_error'));
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import { assertSentryEvent, getEventRequest, runServer } from '../../../../utils';
2+
3+
test('should capture a simple error with message', async () => {
4+
const url = await runServer(__dirname);
5+
const requestBody = await getEventRequest(url);
6+
7+
assertSentryEvent(requestBody, {
8+
exception: {
9+
values: [
10+
{
11+
type: 'Error',
12+
value: 'test_simple_error',
13+
mechanism: {
14+
type: 'generic',
15+
handled: true,
16+
},
17+
stacktrace: {
18+
frames: expect.any(Array),
19+
},
20+
},
21+
],
22+
},
23+
});
24+
});

0 commit comments

Comments
 (0)