Skip to content

Commit

Permalink
chore(plugin-mongodb-core): add missing codecov script (#601)
Browse files Browse the repository at this point in the history
* chore(plugin-mongodb-core): add missing codecov script

* fix(mongodb-plugin): check currentSpan against undefined

* chore(scope-managers): return undefined if no scope is found (following #569)
  • Loading branch information
mayurkale22 authored Dec 10, 2019
1 parent 54879ab commit 6e22fd5
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 11 deletions.
5 changes: 3 additions & 2 deletions packages/opentelemetry-plugin-mongodb-core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"repository": "open-telemetry/opentelemetry-js",
"scripts": {
"test": "nyc ts-mocha -p tsconfig.json 'test/**/*.ts'",
"codecov": "nyc report --reporter=json && codecov -f coverage/*.json -p ../../",
"tdd": "yarn test -- --watch-extensions ts --watch",
"clean": "rimraf build/*",
"check": "gts check",
Expand Down Expand Up @@ -40,8 +41,8 @@
"access": "public"
},
"devDependencies": {
"@opentelemetry/node": "^0.1.1",
"@opentelemetry/tracing": "^0.1.1",
"@opentelemetry/node": "^0.2.0",
"@opentelemetry/tracing": "^0.2.0",
"@types/mocha": "^5.2.7",
"@types/mongodb": "^3.2.3",
"@types/node": "^12.7.2",
Expand Down
4 changes: 2 additions & 2 deletions packages/opentelemetry-plugin-mongodb-core/src/mongodb.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ export class MongoDBCorePlugin extends BasePlugin<typeof mongodb> {
const resultHandler =
typeof options === 'function' ? options : callback;
if (
currentSpan === null ||
currentSpan === undefined ||
typeof resultHandler !== 'function' ||
typeof commands !== 'object'
) {
Expand Down Expand Up @@ -208,7 +208,7 @@ export class MongoDBCorePlugin extends BasePlugin<typeof mongodb> {
): mongodb.Cursor {
const currentSpan = plugin._tracer.getCurrentSpan();
const resultHandler = args[0];
if (currentSpan === null || typeof resultHandler !== 'function') {
if (currentSpan === undefined || typeof resultHandler !== 'function') {
return original.apply(this, args);
}
const span = plugin._tracer.startSpan(`mongodb.query`, {
Expand Down
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 6e22fd5

Please sign in to comment.