Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test(node): Add setContext integration tests. #4787

Merged
merged 1 commit into from
Mar 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import * as Sentry from '@sentry/node';

Sentry.init({
dsn: 'https://public@dsn.ingest.sentry.io/1337',
release: '1.0',
});

Sentry.setContext('context_1', {
foo: 'bar',
baz: {
qux: 'quux',
},
});

Sentry.setContext('context_2', {
1: 'foo',
bar: false,
});

Sentry.setContext('context_3', null);

Sentry.captureMessage('multiple_contexts');
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { Event } from '@sentry/node';

import { assertSentryEvent, getEventRequest, runServer } from '../../../../utils';

test('should record multiple contexts', async () => {
const url = await runServer(__dirname);
const requestBody = await getEventRequest(url);

assertSentryEvent(requestBody, {
message: 'multiple_contexts',
contexts: {
context_1: {
foo: 'bar',
baz: { qux: 'quux' },
},
context_2: { 1: 'foo', bar: false },
},
});

expect((requestBody as Event).contexts?.context_3).not.toBeDefined();
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import * as Sentry from '@sentry/node';

Sentry.init({
dsn: 'https://public@dsn.ingest.sentry.io/1337',
release: '1.0',
});

type Circular = {
self?: Circular;
};

const objCircular: Circular = {};
objCircular.self = objCircular;

Sentry.setContext('non_serializable', objCircular);

Sentry.captureMessage('non_serializable');
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { Event } from '@sentry/node';

import { assertSentryEvent, getEventRequest, runServer } from '../../../../utils';

test('should normalize non-serializable context', async () => {
const url = await runServer(__dirname);
const requestBody = await getEventRequest(url);

assertSentryEvent(requestBody, {
message: 'non_serializable',
contexts: {},
});

expect((requestBody as Event).contexts?.context_3).not.toBeDefined();
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import * as Sentry from '@sentry/node';

Sentry.init({
dsn: 'https://public@dsn.ingest.sentry.io/1337',
release: '1.0',
});

Sentry.setContext('foo', { bar: 'baz' });
Sentry.captureMessage('simple_context_object');
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { Event } from '@sentry/node';

import { assertSentryEvent, getEventRequest, runServer } from '../../../../utils';

test('should set a simple context', async () => {
const url = await runServer(__dirname);
const requestBody = await getEventRequest(url);

assertSentryEvent(requestBody, {
message: 'simple_context_object',
contexts: {
foo: {
bar: 'baz',
},
},
});

expect((requestBody as Event).contexts?.context_3).not.toBeDefined();
});