Skip to content

Commit

Permalink
chore(scope-managers): return undefined if no scope is found (following
Browse files Browse the repository at this point in the history
  • Loading branch information
vmarchaud committed Dec 10, 2019
1 parent c125012 commit c699f14
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export class AsyncHooksScopeManager implements ScopeManager {
}

active(): unknown {
return this._scopes[asyncHooks.executionAsyncId()] || null;
return this._scopes[asyncHooks.executionAsyncId()] || undefined;
}

with<T extends (...args: unknown[]) => ReturnType<T>>(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ describe('AsyncHooksScopeManager', () => {
setTimeout(() => {
assert.strictEqual(
scopeManager.active(),
null,
undefined,
'should have no scope'
);
return done();
Expand Down Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion packages/opentelemetry-scope-base/src/NoopScopeManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import * as types from './types';

export class NoopScopeManager implements types.ScopeManager {
active(): unknown {
return null;
return undefined;
}

with<T extends (...args: unknown[]) => ReturnType<T>>(
Expand Down
14 changes: 11 additions & 3 deletions packages/opentelemetry-scope-base/test/NoopScopeManager.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ describe('NoopScopeManager', () => {
scopeManager.with(test, () => {
assert.strictEqual(
scopeManager.active(),
null,
undefined,
'should not have scope'
);
return done();
Expand All @@ -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();
});
});
Expand Down

0 comments on commit c699f14

Please sign in to comment.