Skip to content

Commit 74f44f9

Browse files
committed
feat: setExtra + tests
1 parent 7a3f8fc commit 74f44f9

File tree

7 files changed

+46
-11
lines changed

7 files changed

+46
-11
lines changed

packages/browser/src/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ export {
2525
Hub,
2626
Scope,
2727
setContext,
28-
setExtras,
28+
setExtra,
2929
setTags,
3030
setUser,
3131
withScope,

packages/core/src/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ export {
55
captureMessage,
66
configureScope,
77
setContext,
8-
setExtras,
8+
setExtra,
99
setTags,
1010
setUser,
1111
withScope,

packages/hub/src/hub.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -251,12 +251,12 @@ export class Hub implements HubInterface {
251251
/**
252252
* @inheritDoc
253253
*/
254-
public setExtras(extras: { [key: string]: any }): void {
254+
public setExtra(extra: { [key: string]: any }): void {
255255
const top = this.getStackTop();
256256
if (!top.scope) {
257257
return;
258258
}
259-
top.scope.setExtras(extras);
259+
top.scope.setExtras(extra);
260260
}
261261

262262
/**

packages/minimal/src/index.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -95,10 +95,10 @@ export function setContext(name: string, context: { [key: string]: any } | null)
9595

9696
/**
9797
* Set an object that will be merged sent as extra data with the event.
98-
* @param extras Extras object to merge into current context.
98+
* @param extra Extra object to merge into current context.
9999
*/
100-
export function setExtras(extras: { [key: string]: any }): void {
101-
callOnHub<void>('setExtras', extras);
100+
export function setExtra(extra: { [key: string]: any }): void {
101+
callOnHub<void>('setExtra', extra);
102102
}
103103

104104
/**

packages/minimal/test/lib/minimal.test.ts

+36-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,17 @@
11
import { getCurrentHub, getHubFromCarrier, Scope } from '@sentry/hub';
22
import { Severity } from '@sentry/types';
3-
import { _callOnClient, captureEvent, captureException, captureMessage, configureScope, withScope } from '../../src';
3+
import {
4+
_callOnClient,
5+
captureEvent,
6+
captureException,
7+
captureMessage,
8+
configureScope,
9+
setContext,
10+
setExtras,
11+
setTags,
12+
setUser,
13+
withScope,
14+
} from '../../src';
415
import { init, TestClient, TestClient2 } from '../mocks/client';
516

617
declare var global: any;
@@ -208,4 +219,28 @@ describe('Minimal', () => {
208219
});
209220
expect(global.__SENTRY__.hub._stack).toHaveLength(1);
210221
});
222+
223+
test('setExtra', () => {
224+
init({});
225+
setExtras({ a: 'b' });
226+
expect(global.__SENTRY__.hub._stack[0].scope._extra).toEqual({ a: 'b' });
227+
});
228+
229+
test('setTags', () => {
230+
init({});
231+
setTags({ a: 'b' });
232+
expect(global.__SENTRY__.hub._stack[0].scope._tags).toEqual({ a: 'b' });
233+
});
234+
235+
test('setUser', () => {
236+
init({});
237+
setUser({ id: 'b' });
238+
expect(global.__SENTRY__.hub._stack[0].scope._user).toEqual({ id: 'b' });
239+
});
240+
241+
test('setContext', () => {
242+
init({});
243+
setContext('test', { id: 'b' });
244+
expect(global.__SENTRY__.hub._stack[0].scope._context).toEqual({ test: { id: 'b' } });
245+
});
211246
});

packages/node/src/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ export {
2525
Hub,
2626
Scope,
2727
setContext,
28-
setExtras,
28+
setExtra,
2929
setTags,
3030
setUser,
3131
withScope,

packages/types/src/hub.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -126,9 +126,9 @@ export interface Hub {
126126

127127
/**
128128
* Set an object that will be merged sent as extra data with the event.
129-
* @param extras Extras object to merge into current context.
129+
* @param extra Extra object to merge into current context.
130130
*/
131-
setExtras(extras: { [key: string]: any }): void;
131+
setExtra(extra: { [key: string]: any }): void;
132132

133133
/**
134134
* Sets context data with the given name.

0 commit comments

Comments
 (0)