From c699f14be5f958a59f3203efaba3acc6d10c5702 Mon Sep 17 00:00:00 2001 From: vmarchaud Date: Tue, 10 Dec 2019 14:00:59 +0100 Subject: [PATCH] chore(scope-managers): return undefined if no scope is found (following #569) --- .../src/AsyncHooksScopeManager.ts | 2 +- .../test/AsyncHooksScopeManager.test.ts | 4 ++-- .../src/NoopScopeManager.ts | 2 +- .../test/NoopScopeManager.test.ts | 14 +++++++++++--- 4 files changed, 15 insertions(+), 7 deletions(-) diff --git a/packages/opentelemetry-scope-async-hooks/src/AsyncHooksScopeManager.ts b/packages/opentelemetry-scope-async-hooks/src/AsyncHooksScopeManager.ts index a8a5b1f13d3..f3f4ee7f786 100644 --- a/packages/opentelemetry-scope-async-hooks/src/AsyncHooksScopeManager.ts +++ b/packages/opentelemetry-scope-async-hooks/src/AsyncHooksScopeManager.ts @@ -50,7 +50,7 @@ export class AsyncHooksScopeManager implements ScopeManager { } active(): unknown { - return this._scopes[asyncHooks.executionAsyncId()] || null; + return this._scopes[asyncHooks.executionAsyncId()] || undefined; } with ReturnType>( diff --git a/packages/opentelemetry-scope-async-hooks/test/AsyncHooksScopeManager.test.ts b/packages/opentelemetry-scope-async-hooks/test/AsyncHooksScopeManager.test.ts index fa6d85cef81..c5333786f40 100644 --- a/packages/opentelemetry-scope-async-hooks/test/AsyncHooksScopeManager.test.ts +++ b/packages/opentelemetry-scope-async-hooks/test/AsyncHooksScopeManager.test.ts @@ -135,7 +135,7 @@ describe('AsyncHooksScopeManager', () => { setTimeout(() => { assert.strictEqual( scopeManager.active(), - null, + undefined, 'should have no scope' ); return done(); @@ -228,7 +228,7 @@ describe('AsyncHooksScopeManager', () => { const patchedEe = scopeManager.bind(ee, scope); const handler = () => { setImmediate(() => { - assert.deepStrictEqual(scopeManager.active(), null); + assert.deepStrictEqual(scopeManager.active(), undefined); patchedEe.removeAllListeners('test'); assert.strictEqual(patchedEe.listeners('test').length, 0); return done(); diff --git a/packages/opentelemetry-scope-base/src/NoopScopeManager.ts b/packages/opentelemetry-scope-base/src/NoopScopeManager.ts index 348e84cd507..ac32db311f5 100644 --- a/packages/opentelemetry-scope-base/src/NoopScopeManager.ts +++ b/packages/opentelemetry-scope-base/src/NoopScopeManager.ts @@ -18,7 +18,7 @@ import * as types from './types'; export class NoopScopeManager implements types.ScopeManager { active(): unknown { - return null; + return undefined; } with ReturnType>( diff --git a/packages/opentelemetry-scope-base/test/NoopScopeManager.test.ts b/packages/opentelemetry-scope-base/test/NoopScopeManager.test.ts index 735a578cfc7..4767f5793f4 100644 --- a/packages/opentelemetry-scope-base/test/NoopScopeManager.test.ts +++ b/packages/opentelemetry-scope-base/test/NoopScopeManager.test.ts @@ -48,7 +48,7 @@ describe('NoopScopeManager', () => { scopeManager.with(test, () => { assert.strictEqual( scopeManager.active(), - null, + undefined, 'should not have scope' ); return done(); @@ -66,12 +66,20 @@ describe('NoopScopeManager', () => { describe('.active()', () => { it('should always return null (when enabled)', () => { - assert.strictEqual(scopeManager.active(), null, 'should not have scope'); + assert.strictEqual( + scopeManager.active(), + undefined, + 'should not have scope' + ); }); it('should always return null (when disabled)', () => { scopeManager.disable(); - assert.strictEqual(scopeManager.active(), null, 'should not have scope'); + assert.strictEqual( + scopeManager.active(), + undefined, + 'should not have scope' + ); scopeManager.enable(); }); });