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

fix: Call bindClient in the hub #2665

Merged
merged 6 commits into from Jun 10, 2020
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Expand Up @@ -6,6 +6,8 @@
- [react] feat: Add @sentry/react package (#2631)
- [react] feat: Add Error Boundary component (#2647)
- [react] feat: Add useProfiler hook (#2659)
- [core] feat: Export `makeMain` (#2665)
kamilogorek marked this conversation as resolved.
Show resolved Hide resolved
- [core] fix: Call `bindClient` when creating new `Hub` to make integrations work automatically (#2665)

## 5.17.0

Expand Down
1 change: 1 addition & 0 deletions packages/browser/src/exports.ts
Expand Up @@ -25,6 +25,7 @@ export {
getHubFromCarrier,
getCurrentHub,
Hub,
makeMain,
Scope,
startTransaction,
setContext,
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/index.ts
Expand Up @@ -13,7 +13,7 @@ export {
setUser,
withScope,
} from '@sentry/minimal';
export { addGlobalEventProcessor, getCurrentHub, getHubFromCarrier, Hub, Scope } from '@sentry/hub';
export { addGlobalEventProcessor, getCurrentHub, getHubFromCarrier, Hub, makeMain, Scope } from '@sentry/hub';
export { API } from './api';
export { BaseClient } from './baseclient';
export { BackendClass, BaseBackend } from './basebackend';
Expand Down
1 change: 1 addition & 0 deletions packages/hub/src/hub.ts
Expand Up @@ -61,6 +61,7 @@ export class Hub implements HubInterface {
*/
public constructor(client?: Client, scope: Scope = new Scope(), private readonly _version: number = API_VERSION) {
this._stack.push({ client, scope });
this.bindClient(client);
}

/**
Expand Down
48 changes: 38 additions & 10 deletions packages/hub/test/hub.test.ts
Expand Up @@ -6,10 +6,18 @@ const clientFn: any = jest.fn();

describe('Hub', () => {
afterEach(() => {
jest.resetAllMocks();
jest.restoreAllMocks();
jest.useRealTimers();
});

test('call bindClient with provided client when constructing new instance', () => {
const testClient: any = { setupIntegrations: jest.fn() };
const spy = jest.spyOn(Hub.prototype, 'bindClient');
// tslint:disable-next-line:no-unused-expression
new Hub(testClient);
expect(spy).toHaveBeenCalledWith(testClient);
});

test('push process into stack', () => {
const hub = new Hub();
expect(hub.getStack()).toHaveLength(1);
Expand Down Expand Up @@ -51,15 +59,35 @@ describe('Hub', () => {
expect(hub.getStack()[1].client).toBe(testClient);
});

test('bindClient', () => {
const testClient: any = { bla: 'a' };
const hub = new Hub(testClient);
const ndClient: any = { foo: 'bar' };
hub.pushScope();
hub.bindClient(ndClient);
expect(hub.getStack()).toHaveLength(2);
expect(hub.getStack()[0].client).toBe(testClient);
expect(hub.getStack()[1].client).toBe(ndClient);
describe('bindClient', () => {
test('should override curent client', () => {
const testClient: any = { setupIntegrations: jest.fn() };
const nextClient: any = { setupIntegrations: jest.fn() };
const hub = new Hub(testClient);
hub.bindClient(nextClient);
expect(hub.getStack()).toHaveLength(1);
expect(hub.getStack()[0].client).toBe(nextClient);
});

test('should bind client to the top-most layer', () => {
const testClient: any = { bla: 'a' };
const nextClient: any = { foo: 'bar' };
const hub = new Hub(testClient);
hub.pushScope();
hub.bindClient(nextClient);
expect(hub.getStack()).toHaveLength(2);
expect(hub.getStack()[0].client).toBe(testClient);
expect(hub.getStack()[1].client).toBe(nextClient);
});

test('should call setupIntegration method of passed client', () => {
const testClient: any = { setupIntegrations: jest.fn() };
const nextClient: any = { setupIntegrations: jest.fn() };
const hub = new Hub(testClient);
hub.bindClient(nextClient);
expect(testClient.setupIntegrations).toHaveBeenCalled();
expect(nextClient.setupIntegrations).toHaveBeenCalled();
});
});

test('inherit processors', () => {
Expand Down
1 change: 1 addition & 0 deletions packages/node/src/index.ts
Expand Up @@ -25,6 +25,7 @@ export {
getHubFromCarrier,
getCurrentHub,
Hub,
makeMain,
Scope,
startTransaction,
setContext,
Expand Down
35 changes: 1 addition & 34 deletions yarn.lock
Expand Up @@ -1810,32 +1810,11 @@ after@0.8.2:
version "0.8.2"
resolved "https://registry.yarnpkg.com/after/-/after-0.8.2.tgz#fedb394f9f0e02aa9768e702bda23b505fae7e1f"

agent-base@4, agent-base@^4.3.0:
version "4.3.0"
resolved "https://registry.yarnpkg.com/agent-base/-/agent-base-4.3.0.tgz#8165f01c436009bccad0b1d122f05ed770efc6ee"
integrity sha512-salcGninV0nPrwpGNn4VTXBb1SOuXQBiqbrNXoeizJsHrsL6ERFM2Ne3JUSBWRE6aeNJI2ROP/WEEIDUiDe3cg==
dependencies:
es6-promisify "^5.0.0"

agent-base@5:
agent-base@4, agent-base@5, agent-base@6, agent-base@^4.3.0, agent-base@~4.2.0:
version "5.1.1"
resolved "https://registry.yarnpkg.com/agent-base/-/agent-base-5.1.1.tgz#e8fb3f242959db44d63be665db7a8e739537a32c"
integrity sha512-TMeqbNl2fMW0nMjTEPOwe3J/PRFP4vqeoNuQMG0HlMrtm5QxKqdvAkZ1pRBQ/ulIyDD5Yq0nJ7YbdD8ey0TO3g==

agent-base@6:
version "6.0.0"
resolved "https://registry.yarnpkg.com/agent-base/-/agent-base-6.0.0.tgz#5d0101f19bbfaed39980b22ae866de153b93f09a"
integrity sha512-j1Q7cSCqN+AwrmDd+pzgqc0/NpC655x2bUf5ZjRIO77DcNBFmh+OgRNzF6OKdCC9RSCb19fGd99+bhXFdkRNqw==
dependencies:
debug "4"

agent-base@~4.2.0:
version "4.2.1"
resolved "https://registry.yarnpkg.com/agent-base/-/agent-base-4.2.1.tgz#d89e5999f797875674c07d87f260fc41e83e8ca9"
integrity sha512-JVwXMr9nHYTUXsBFKUqhJwvlcYU/blreOEUkhNR2eXZIvwd+c+o5V4MgDPKWnMS/56awN3TRzIP+KoPn+roQtg==
dependencies:
es6-promisify "^5.0.0"

agentkeepalive@^3.4.1:
version "3.5.2"
resolved "https://registry.yarnpkg.com/agentkeepalive/-/agentkeepalive-3.5.2.tgz#a113924dd3fa24a0bc3b78108c450c2abee00f67"
Expand Down Expand Up @@ -4553,18 +4532,6 @@ es-to-primitive@^1.1.1, es-to-primitive@^1.2.0:
is-date-object "^1.0.1"
is-symbol "^1.0.2"

es6-promise@^4.0.3:
version "4.2.8"
resolved "https://registry.yarnpkg.com/es6-promise/-/es6-promise-4.2.8.tgz#4eb21594c972bc40553d276e510539143db53e0a"
integrity sha512-HJDGx5daxeIvxdBxvG2cb9g4tEvwIk3i8+nhX0yGrYmZUzbkdg8QbDevheDB8gd0//uPj4c1EQua8Q+MViT0/w==

es6-promisify@^5.0.0:
version "5.0.0"
resolved "https://registry.yarnpkg.com/es6-promisify/-/es6-promisify-5.0.0.tgz#5109d62f3e56ea967c4b63505aef08291c8a5203"
integrity sha1-UQnWLz5W6pZ8S2NQWu8IKRyKUgM=
dependencies:
es6-promise "^4.0.3"

escape-html@~1.0.3:
version "1.0.3"
resolved "https://registry.yarnpkg.com/escape-html/-/escape-html-1.0.3.tgz#0258eae4d3d0c0974de1c169188ef0051d1d1988"
Expand Down