Skip to content

Commit e8a37d2

Browse files
HazATkamilogorek
andauthored
fix: Call bindClient in the hub (getsentry#2665)
Co-authored-by: Kamil Ogórek <kamil.ogorek@gmail.com>
1 parent e13fc0c commit e8a37d2

File tree

7 files changed

+45
-45
lines changed

7 files changed

+45
-45
lines changed

CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
- [react] feat: Add @sentry/react package (#2631)
77
- [react] feat: Add Error Boundary component (#2647)
88
- [react] feat: Add useProfiler hook (#2659)
9+
- [core] feat: Export `makeMain` (#2665)
10+
- [core] fix: Call `bindClient` when creating new `Hub` to make integrations work automatically (#2665)
911

1012
## 5.17.0
1113

packages/browser/src/exports.ts

+1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ export {
2525
getHubFromCarrier,
2626
getCurrentHub,
2727
Hub,
28+
makeMain,
2829
Scope,
2930
startTransaction,
3031
setContext,

packages/core/src/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ export {
1313
setUser,
1414
withScope,
1515
} from '@sentry/minimal';
16-
export { addGlobalEventProcessor, getCurrentHub, getHubFromCarrier, Hub, Scope } from '@sentry/hub';
16+
export { addGlobalEventProcessor, getCurrentHub, getHubFromCarrier, Hub, makeMain, Scope } from '@sentry/hub';
1717
export { API } from './api';
1818
export { BaseClient } from './baseclient';
1919
export { BackendClass, BaseBackend } from './basebackend';

packages/hub/src/hub.ts

+1
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ export class Hub implements HubInterface {
6161
*/
6262
public constructor(client?: Client, scope: Scope = new Scope(), private readonly _version: number = API_VERSION) {
6363
this._stack.push({ client, scope });
64+
this.bindClient(client);
6465
}
6566

6667
/**

packages/hub/test/hub.test.ts

+38-10
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,18 @@ const clientFn: any = jest.fn();
66

77
describe('Hub', () => {
88
afterEach(() => {
9-
jest.resetAllMocks();
9+
jest.restoreAllMocks();
1010
jest.useRealTimers();
1111
});
1212

13+
test('call bindClient with provided client when constructing new instance', () => {
14+
const testClient: any = { setupIntegrations: jest.fn() };
15+
const spy = jest.spyOn(Hub.prototype, 'bindClient');
16+
// tslint:disable-next-line:no-unused-expression
17+
new Hub(testClient);
18+
expect(spy).toHaveBeenCalledWith(testClient);
19+
});
20+
1321
test('push process into stack', () => {
1422
const hub = new Hub();
1523
expect(hub.getStack()).toHaveLength(1);
@@ -51,15 +59,35 @@ describe('Hub', () => {
5159
expect(hub.getStack()[1].client).toBe(testClient);
5260
});
5361

54-
test('bindClient', () => {
55-
const testClient: any = { bla: 'a' };
56-
const hub = new Hub(testClient);
57-
const ndClient: any = { foo: 'bar' };
58-
hub.pushScope();
59-
hub.bindClient(ndClient);
60-
expect(hub.getStack()).toHaveLength(2);
61-
expect(hub.getStack()[0].client).toBe(testClient);
62-
expect(hub.getStack()[1].client).toBe(ndClient);
62+
describe('bindClient', () => {
63+
test('should override curent client', () => {
64+
const testClient: any = { setupIntegrations: jest.fn() };
65+
const nextClient: any = { setupIntegrations: jest.fn() };
66+
const hub = new Hub(testClient);
67+
hub.bindClient(nextClient);
68+
expect(hub.getStack()).toHaveLength(1);
69+
expect(hub.getStack()[0].client).toBe(nextClient);
70+
});
71+
72+
test('should bind client to the top-most layer', () => {
73+
const testClient: any = { bla: 'a' };
74+
const nextClient: any = { foo: 'bar' };
75+
const hub = new Hub(testClient);
76+
hub.pushScope();
77+
hub.bindClient(nextClient);
78+
expect(hub.getStack()).toHaveLength(2);
79+
expect(hub.getStack()[0].client).toBe(testClient);
80+
expect(hub.getStack()[1].client).toBe(nextClient);
81+
});
82+
83+
test('should call setupIntegration method of passed client', () => {
84+
const testClient: any = { setupIntegrations: jest.fn() };
85+
const nextClient: any = { setupIntegrations: jest.fn() };
86+
const hub = new Hub(testClient);
87+
hub.bindClient(nextClient);
88+
expect(testClient.setupIntegrations).toHaveBeenCalled();
89+
expect(nextClient.setupIntegrations).toHaveBeenCalled();
90+
});
6391
});
6492

6593
test('inherit processors', () => {

packages/node/src/index.ts

+1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ export {
2525
getHubFromCarrier,
2626
getCurrentHub,
2727
Hub,
28+
makeMain,
2829
Scope,
2930
startTransaction,
3031
setContext,

yarn.lock

+1-34
Original file line numberDiff line numberDiff line change
@@ -1810,32 +1810,11 @@ after@0.8.2:
18101810
version "0.8.2"
18111811
resolved "https://registry.yarnpkg.com/after/-/after-0.8.2.tgz#fedb394f9f0e02aa9768e702bda23b505fae7e1f"
18121812

1813-
agent-base@4, agent-base@^4.3.0:
1814-
version "4.3.0"
1815-
resolved "https://registry.yarnpkg.com/agent-base/-/agent-base-4.3.0.tgz#8165f01c436009bccad0b1d122f05ed770efc6ee"
1816-
integrity sha512-salcGninV0nPrwpGNn4VTXBb1SOuXQBiqbrNXoeizJsHrsL6ERFM2Ne3JUSBWRE6aeNJI2ROP/WEEIDUiDe3cg==
1817-
dependencies:
1818-
es6-promisify "^5.0.0"
1819-
1820-
agent-base@5:
1813+
agent-base@4, agent-base@5, agent-base@6, agent-base@^4.3.0, agent-base@~4.2.0:
18211814
version "5.1.1"
18221815
resolved "https://registry.yarnpkg.com/agent-base/-/agent-base-5.1.1.tgz#e8fb3f242959db44d63be665db7a8e739537a32c"
18231816
integrity sha512-TMeqbNl2fMW0nMjTEPOwe3J/PRFP4vqeoNuQMG0HlMrtm5QxKqdvAkZ1pRBQ/ulIyDD5Yq0nJ7YbdD8ey0TO3g==
18241817

1825-
agent-base@6:
1826-
version "6.0.0"
1827-
resolved "https://registry.yarnpkg.com/agent-base/-/agent-base-6.0.0.tgz#5d0101f19bbfaed39980b22ae866de153b93f09a"
1828-
integrity sha512-j1Q7cSCqN+AwrmDd+pzgqc0/NpC655x2bUf5ZjRIO77DcNBFmh+OgRNzF6OKdCC9RSCb19fGd99+bhXFdkRNqw==
1829-
dependencies:
1830-
debug "4"
1831-
1832-
agent-base@~4.2.0:
1833-
version "4.2.1"
1834-
resolved "https://registry.yarnpkg.com/agent-base/-/agent-base-4.2.1.tgz#d89e5999f797875674c07d87f260fc41e83e8ca9"
1835-
integrity sha512-JVwXMr9nHYTUXsBFKUqhJwvlcYU/blreOEUkhNR2eXZIvwd+c+o5V4MgDPKWnMS/56awN3TRzIP+KoPn+roQtg==
1836-
dependencies:
1837-
es6-promisify "^5.0.0"
1838-
18391818
agentkeepalive@^3.4.1:
18401819
version "3.5.2"
18411820
resolved "https://registry.yarnpkg.com/agentkeepalive/-/agentkeepalive-3.5.2.tgz#a113924dd3fa24a0bc3b78108c450c2abee00f67"
@@ -4553,18 +4532,6 @@ es-to-primitive@^1.1.1, es-to-primitive@^1.2.0:
45534532
is-date-object "^1.0.1"
45544533
is-symbol "^1.0.2"
45554534

4556-
es6-promise@^4.0.3:
4557-
version "4.2.8"
4558-
resolved "https://registry.yarnpkg.com/es6-promise/-/es6-promise-4.2.8.tgz#4eb21594c972bc40553d276e510539143db53e0a"
4559-
integrity sha512-HJDGx5daxeIvxdBxvG2cb9g4tEvwIk3i8+nhX0yGrYmZUzbkdg8QbDevheDB8gd0//uPj4c1EQua8Q+MViT0/w==
4560-
4561-
es6-promisify@^5.0.0:
4562-
version "5.0.0"
4563-
resolved "https://registry.yarnpkg.com/es6-promisify/-/es6-promisify-5.0.0.tgz#5109d62f3e56ea967c4b63505aef08291c8a5203"
4564-
integrity sha1-UQnWLz5W6pZ8S2NQWu8IKRyKUgM=
4565-
dependencies:
4566-
es6-promise "^4.0.3"
4567-
45684535
escape-html@~1.0.3:
45694536
version "1.0.3"
45704537
resolved "https://registry.yarnpkg.com/escape-html/-/escape-html-1.0.3.tgz#0258eae4d3d0c0974de1c169188ef0051d1d1988"

0 commit comments

Comments
 (0)