-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(node): Add
setContext
integration tests (#4787)
- Loading branch information
1 parent
398976c
commit 37b14bf
Showing
6 changed files
with
103 additions
and
0 deletions.
There are no files selected for viewing
22 changes: 22 additions & 0 deletions
22
packages/node-integration-tests/suites/public-api/setContext/multiple-contexts/scenario.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'); |
21 changes: 21 additions & 0 deletions
21
packages/node-integration-tests/suites/public-api/setContext/multiple-contexts/test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
}); |
17 changes: 17 additions & 0 deletions
17
.../node-integration-tests/suites/public-api/setContext/non-serializable-context/scenario.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'); |
15 changes: 15 additions & 0 deletions
15
...ages/node-integration-tests/suites/public-api/setContext/non-serializable-context/test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
}); |
9 changes: 9 additions & 0 deletions
9
packages/node-integration-tests/suites/public-api/setContext/simple-context/scenario.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'); |
19 changes: 19 additions & 0 deletions
19
packages/node-integration-tests/suites/public-api/setContext/simple-context/test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
}); |