Skip to content

Commit

Permalink
refactor: unit tests (open-telemetry#198)
Browse files Browse the repository at this point in the history
  • Loading branch information
mayurkale22 authored Aug 14, 2019
1 parent a27536e commit f75ae54
Show file tree
Hide file tree
Showing 8 changed files with 49 additions and 45 deletions.
6 changes: 5 additions & 1 deletion .nycrc
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@
"exclude": [
"**/*.d.ts",
"build/**/**/*.js",
"src/index.ts"
"src/index.ts",
"karma.conf.js",
"src/platform/browser/*.ts",
"test/index-webpack.ts",
"webpack/*.js"
],
"all": true
}
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ describe('BinaryTraceContext', () => {
},
];

describe('toBytes', () => {
describe('.toBytes()', () => {
testCases.forEach(
testCase =>
testCase.structured &&
Expand All @@ -127,7 +127,7 @@ describe('BinaryTraceContext', () => {
);
});

describe('fromBytes', () => {
describe('.fromBytes()', () => {
testCases.forEach(testCase =>
it(`should deserialize ${testCase.description}`, () => {
assert.deepStrictEqual(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ describe('HttpTraceContext', () => {
carrier = {};
});

describe('inject', () => {
describe('.inject()', () => {
it('should set traceparent header', () => {
const spanContext: SpanContext = {
traceId: 'd4cda95b652f4a1592b449d5929fda1b',
Expand Down Expand Up @@ -64,7 +64,7 @@ describe('HttpTraceContext', () => {
});
});

describe('extract', () => {
describe('.extract()', () => {
it('should extract context of a sampled span from carrier', () => {
carrier[TRACE_PARENT_HEADER] =
'00-0af7651916cd43dd8448eb211c80319c-b7ad6b7169203331-01';
Expand Down
66 changes: 33 additions & 33 deletions packages/opentelemetry-core/test/trace/TracerDelegate.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,44 +65,44 @@ describe('TracerDelegate', () => {
tracerDelegate.startSpan('foo');
assert.deepStrictEqual(dummyTracer.spyCounter, 1);
});
});

describe('.start/stop()', () => {
it('should use the fallback tracer when stop is called', () => {
const dummyTracerUser = new DummyTracer();
const dummyTracerFallback = new DummyTracer();
const tracerDelegate = new TracerDelegate(
dummyTracerUser,
dummyTracerFallback
);
describe('.start/.stop()', () => {
it('should use the fallback tracer when stop is called', () => {
const dummyTracerUser = new DummyTracer();
const dummyTracerFallback = new DummyTracer();
const tracerDelegate = new TracerDelegate(
dummyTracerUser,
dummyTracerFallback
);

tracerDelegate.stop();
tracerDelegate.startSpan('fallback');
assert.deepStrictEqual(dummyTracerUser.spyCounter, 0);
assert.deepStrictEqual(dummyTracerFallback.spyCounter, 1);
});
tracerDelegate.stop();
tracerDelegate.startSpan('fallback');
assert.deepStrictEqual(dummyTracerUser.spyCounter, 0);
assert.deepStrictEqual(dummyTracerFallback.spyCounter, 1);
});

it('should use the user tracer when start is called', () => {
const dummyTracerUser = new DummyTracer();
const dummyTracerFallback = new DummyTracer();
const tracerDelegate = new TracerDelegate(
dummyTracerUser,
dummyTracerFallback
);
it('should use the user tracer when start is called', () => {
const dummyTracerUser = new DummyTracer();
const dummyTracerFallback = new DummyTracer();
const tracerDelegate = new TracerDelegate(
dummyTracerUser,
dummyTracerFallback
);

tracerDelegate.stop();
tracerDelegate.startSpan('fallback');
assert.deepStrictEqual(dummyTracerUser.spyCounter, 0);
assert.deepStrictEqual(dummyTracerFallback.spyCounter, 1);
tracerDelegate.stop();
tracerDelegate.startSpan('fallback');
assert.deepStrictEqual(dummyTracerUser.spyCounter, 0);
assert.deepStrictEqual(dummyTracerFallback.spyCounter, 1);

tracerDelegate.start();
tracerDelegate.startSpan('user');
assert.deepStrictEqual(dummyTracerUser.spyCounter, 1);
assert.deepStrictEqual(
dummyTracerFallback.spyCounter,
1,
'Only user tracer counter is incremented'
);
});
tracerDelegate.start();
tracerDelegate.startSpan('user');
assert.deepStrictEqual(dummyTracerUser.spyCounter, 1);
assert.deepStrictEqual(
dummyTracerFallback.spyCounter,
1,
'Only user tracer counter is incremented'
);
});
});

Expand Down
4 changes: 2 additions & 2 deletions packages/opentelemetry-core/test/trace/tracestate.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import * as assert from 'assert';
import { TraceState } from '../../src/trace/TraceState';

describe('TraceState', () => {
describe('serialize', () => {
describe('.serialize()', () => {
it('returns serialize string', () => {
const state = new TraceState('a=1,b=2');
assert.deepStrictEqual(state.serialize(), 'a=1,b=2');
Expand Down Expand Up @@ -52,7 +52,7 @@ describe('TraceState', () => {
});
});

describe('parse', () => {
describe('.parse()', () => {
it('must successfully parse valid state value', () => {
const state = new TraceState(
'vendorname2=opaqueValue2,vendorname1=opaqueValue1'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ describe('PluginLoader', () => {
Object.keys(require.cache).forEach(key => delete require.cache[key]);
});

describe('state()', () => {
describe('.state()', () => {
it('returns UNINITIALIZED when first called', () => {
const pluginLoader = new PluginLoader(tracer, logger);
assert.strictEqual(pluginLoader['_hookState'], HookState.UNINITIALIZED);
Expand All @@ -59,7 +59,7 @@ describe('PluginLoader', () => {
});
});

describe('load()', () => {
describe('.load()', () => {
it('sanity check', () => {
// Ensure that module fixtures contain values that we expect.
const simpleModule = require('simple-module');
Expand Down Expand Up @@ -107,7 +107,7 @@ describe('PluginLoader', () => {
});
});

describe('unload()', () => {
describe('.unload()', () => {
it('should unload the plugins and unpatch the target module when unloads', () => {
const pluginLoader = new PluginLoader(tracer, logger);
assert.strictEqual(pluginLoader['_plugins'].length, 0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*/

import * as assert from 'assert';
import { AsyncHooksScopeManager } from '../../src';
import { AsyncHooksScopeManager } from '../src';

describe('AsyncHooksScopeManager', () => {
let scopeManager: AsyncHooksScopeManager;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*/

import * as assert from 'assert';
import { NoopScopeManager } from '../../src';
import { NoopScopeManager } from '../src';

describe('NoopScopeManager', () => {
let scopeManager: NoopScopeManager;
Expand Down

0 comments on commit f75ae54

Please sign in to comment.