Skip to content

Commit 0f6619e

Browse files
authored
refactor(instrumentation): change tests to allow use of mocha context (#5591)
Signed-off-by: Adrien Raimbault <[email protected]>
1 parent b018f15 commit 0f6619e

File tree

8 files changed

+105
-105
lines changed

8 files changed

+105
-105
lines changed

experimental/packages/opentelemetry-instrumentation/test/common/Instrumentation.test.ts

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -45,26 +45,26 @@ class TestInstrumentation extends InstrumentationBase<TestInstrumentationConfig>
4545
}
4646
}
4747

48-
describe('BaseInstrumentation', () => {
48+
describe('BaseInstrumentation', function () {
4949
let instrumentation: Instrumentation;
5050
beforeEach(() => {
5151
instrumentation = new TestInstrumentation();
5252
});
5353

54-
it('should create an instance', () => {
54+
it('should create an instance', function () {
5555
assert.ok(instrumentation instanceof InstrumentationBase);
5656
});
5757

58-
it('should have a name', () => {
58+
it('should have a name', function () {
5959
assert.deepStrictEqual(instrumentation.instrumentationName, 'test');
6060
});
6161

62-
it('should have a version', () => {
62+
it('should have a version', function () {
6363
assert.deepStrictEqual(instrumentation.instrumentationVersion, '1.0.0');
6464
});
6565

66-
describe('constructor', () => {
67-
it('should enable instrumentation by default', () => {
66+
describe('constructor', function () {
67+
it('should enable instrumentation by default', function () {
6868
let enableCalled = false;
6969
let updateMetricInstrumentsCalled = false;
7070
class TestInstrumentation2 extends TestInstrumentation {
@@ -81,12 +81,12 @@ describe('BaseInstrumentation', () => {
8181
});
8282
});
8383

84-
describe('setMeterProvider', () => {
84+
describe('setMeterProvider', function () {
8585
let otelTestingMeterProvider: MeterProvider;
8686
beforeEach(() => {
8787
otelTestingMeterProvider = new MeterProvider();
8888
});
89-
it('should call _updateMetricInstruments', () => {
89+
it('should call _updateMetricInstruments', function () {
9090
let called = true;
9191
class TestInstrumentation2 extends TestInstrumentation {
9292
override _updateMetricInstruments() {
@@ -99,8 +99,8 @@ describe('BaseInstrumentation', () => {
9999
});
100100
});
101101

102-
describe('setLoggerProvider', () => {
103-
it('should get a logger from provider', () => {
102+
describe('setLoggerProvider', function () {
103+
it('should get a logger from provider', function () {
104104
let called = true;
105105
class TestLoggerProvider extends LoggerProvider {
106106
override getLogger(name: any, version?: any, options?: any) {
@@ -116,8 +116,8 @@ describe('BaseInstrumentation', () => {
116116
});
117117
});
118118

119-
describe('getConfig', () => {
120-
it('should return instrumentation config, "enabled" should be true by default', () => {
119+
describe('getConfig', function () {
120+
it('should return instrumentation config, "enabled" should be true by default', function () {
121121
const instrumentation: Instrumentation = new TestInstrumentation({
122122
isActive: false,
123123
});
@@ -129,8 +129,8 @@ describe('BaseInstrumentation', () => {
129129
});
130130
});
131131

132-
describe('setConfig', () => {
133-
it('should set a new config for instrumentation', () => {
132+
describe('setConfig', function () {
133+
it('should set a new config for instrumentation', function () {
134134
const instrumentation: Instrumentation = new TestInstrumentation();
135135
const config: TestInstrumentationConfig = {
136136
isActive: true,
@@ -141,7 +141,7 @@ describe('BaseInstrumentation', () => {
141141
assert.strictEqual(configuration.isActive, true);
142142
});
143143

144-
it('should ensure "enabled" defaults to true', () => {
144+
it('should ensure "enabled" defaults to true', function () {
145145
const instrumentation: Instrumentation = new TestInstrumentation();
146146
const config: TestInstrumentationConfig = {
147147
isActive: true,
@@ -154,7 +154,7 @@ describe('BaseInstrumentation', () => {
154154
});
155155
});
156156

157-
describe('getModuleDefinitions', () => {
157+
describe('getModuleDefinitions', function () {
158158
const moduleDefinition: InstrumentationModuleDefinition = {
159159
name: 'foo',
160160
patch: moduleExports => {},
@@ -164,7 +164,7 @@ describe('BaseInstrumentation', () => {
164164
supportedVersions: ['*'],
165165
};
166166

167-
it('should return single module definition from init() as array ', () => {
167+
it('should return single module definition from init() as array ', function () {
168168
class TestInstrumentation2 extends TestInstrumentation {
169169
override init() {
170170
return moduleDefinition;
@@ -177,7 +177,7 @@ describe('BaseInstrumentation', () => {
177177
]);
178178
});
179179

180-
it('should return multiple module definitions from init() as array ', () => {
180+
it('should return multiple module definitions from init() as array ', function () {
181181
class TestInstrumentation2 extends TestInstrumentation {
182182
override init() {
183183
return [moduleDefinition, moduleDefinition, moduleDefinition];
@@ -192,7 +192,7 @@ describe('BaseInstrumentation', () => {
192192
]);
193193
});
194194

195-
it('should return void from init() as empty array ', () => {
195+
it('should return void from init() as empty array ', function () {
196196
class TestInstrumentation2 extends TestInstrumentation {
197197
override init() {
198198
return;
@@ -203,8 +203,8 @@ describe('BaseInstrumentation', () => {
203203
assert.deepStrictEqual(instrumentation.getModuleDefinitions(), []);
204204
});
205205

206-
describe('runInstrumentationEventHook', () => {
207-
it('should call the hook', () => {
206+
describe('runInstrumentationEventHook', function () {
207+
it('should call the hook', function () {
208208
const instrumentation = new TestInstrumentation({});
209209
let called = false;
210210
const hook = () => {
@@ -214,12 +214,12 @@ describe('BaseInstrumentation', () => {
214214
assert.strictEqual(called, true);
215215
});
216216

217-
it('empty hook should work', () => {
217+
it('empty hook should work', function () {
218218
const instrumentation = new TestInstrumentation({});
219219
instrumentation.testRunHook(undefined);
220220
});
221221

222-
it('exception in hook should not crash', () => {
222+
it('exception in hook should not crash', function () {
223223
const instrumentation = new TestInstrumentation({});
224224
const hook = () => {
225225
throw new Error('test');

experimental/packages/opentelemetry-instrumentation/test/common/autoLoader.test.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ class FooInstrumentation extends InstrumentationBase {
5252
override disable() {}
5353
}
5454

55-
describe('autoLoader', () => {
55+
describe('autoLoader', function () {
5656
// eslint-disable-next-line @typescript-eslint/ban-types
5757
let unload: Function | undefined;
5858

@@ -64,8 +64,8 @@ describe('autoLoader', () => {
6464
}
6565
});
6666

67-
describe('registerInstrumentations', () => {
68-
describe('InstrumentationBase', () => {
67+
describe('registerInstrumentations', function () {
68+
describe('InstrumentationBase', function () {
6969
let instrumentation: InstrumentationBase;
7070
let enableSpy: sinon.SinonSpy;
7171
let setTracerProviderSpy: sinon.SinonSpy;
@@ -96,7 +96,7 @@ describe('autoLoader', () => {
9696
}
9797
});
9898

99-
it('should enable disabled instrumentation', () => {
99+
it('should enable disabled instrumentation', function () {
100100
if (typeof unload === 'function') {
101101
unload();
102102
unload = undefined;
@@ -117,23 +117,23 @@ describe('autoLoader', () => {
117117
assert.strictEqual(enableSpy.callCount, 1);
118118
});
119119

120-
it('should NOT enable enabled instrumentation', () => {
120+
it('should NOT enable enabled instrumentation', function () {
121121
assert.strictEqual(enableSpy.callCount, 0);
122122
});
123123

124-
it('should set TracerProvider', () => {
124+
it('should set TracerProvider', function () {
125125
assert.strictEqual(setTracerProviderSpy.callCount, 1);
126126
assert.ok(setTracerProviderSpy.lastCall.args[0] === tracerProvider);
127127
assert.strictEqual(setTracerProviderSpy.lastCall.args.length, 1);
128128
});
129129

130-
it('should set MeterProvider', () => {
130+
it('should set MeterProvider', function () {
131131
assert.strictEqual(setMeterProviderSpy.callCount, 1);
132132
assert.ok(setMeterProviderSpy.lastCall.args[0] === meterProvider);
133133
assert.strictEqual(setMeterProviderSpy.lastCall.args.length, 1);
134134
});
135135

136-
it('should set LoggerProvider', () => {
136+
it('should set LoggerProvider', function () {
137137
assert.strictEqual(setLoggerProviderSpy.callCount, 1);
138138
assert.ok(setLoggerProviderSpy.lastCall.args[0] === loggerProvider);
139139
assert.strictEqual(setLoggerProviderSpy.lastCall.args.length, 1);

experimental/packages/opentelemetry-instrumentation/test/common/semver.test.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ import { satisfies, SatisfiesOptions } from '../../src/semver';
4343
const rangeInclude = require('./third-party/node-semver/range-include.js');
4444
const rangeExclude = require('./third-party/node-semver/range-exclude.js');
4545

46-
describe('SemVer', () => {
47-
describe('satisfies', () => {
46+
describe('SemVer', function () {
47+
describe('satisfies', function () {
4848
function isOptionsSupported(options: any): boolean {
4949
// We don't support
5050
// - boolean typed options
@@ -55,7 +55,7 @@ describe('SemVer', () => {
5555
return true;
5656
}
5757

58-
it('when range is included', () => {
58+
it('when range is included', function () {
5959
rangeInclude.forEach(([range, ver, options]: [string, string, any]) => {
6060
if (!isOptionsSupported(options)) {
6161
return;
@@ -66,7 +66,7 @@ describe('SemVer', () => {
6666
);
6767
});
6868
});
69-
it('when range is not included', () => {
69+
it('when range is not included', function () {
7070
rangeExclude.forEach(([range, ver, options]: [string, string, any]) => {
7171
if (!isOptionsSupported(options)) {
7272
return;
@@ -77,7 +77,7 @@ describe('SemVer', () => {
7777
);
7878
});
7979
});
80-
it('invalid ranges never satisfied (but do not throw)', () => {
80+
it('invalid ranges never satisfied (but do not throw)', function () {
8181
const cases = [
8282
['blerg', '1.2.3'],
8383
['git+https://user:[email protected]/foo', '123.0.0', true],

experimental/packages/opentelemetry-instrumentation/test/common/utils.test.ts

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@ import {
2121
safeExecuteInTheMiddleAsync,
2222
} from '../../src';
2323

24-
describe('isWrapped', () => {
25-
describe('when function is wrapped', () => {
26-
it('should return true', () => {
24+
describe('isWrapped', function () {
25+
describe('when function is wrapped', function () {
26+
it('should return true', function () {
2727
const obj: any = {
2828
wrapMe: function () {},
2929
};
@@ -34,8 +34,8 @@ describe('isWrapped', () => {
3434
assert.deepStrictEqual(isWrapped(obj.wrapMe), true);
3535
});
3636
});
37-
describe('when function is NOT wrapped', () => {
38-
it('should return false', () => {
37+
describe('when function is NOT wrapped', function () {
38+
it('should return false', function () {
3939
const obj: any = {
4040
wrapMe: function () {},
4141
};
@@ -47,8 +47,8 @@ describe('isWrapped', () => {
4747
});
4848
});
4949

50-
describe('safeExecuteInTheMiddle', () => {
51-
it('should not throw error', () => {
50+
describe('safeExecuteInTheMiddle', function () {
51+
it('should not throw error', function () {
5252
safeExecuteInTheMiddle(
5353
() => {
5454
return 'foo';
@@ -59,7 +59,7 @@ describe('safeExecuteInTheMiddle', () => {
5959
true
6060
);
6161
});
62-
it('should throw error', () => {
62+
it('should throw error', function () {
6363
const error = new Error('test');
6464
try {
6565
safeExecuteInTheMiddle(
@@ -74,7 +74,7 @@ describe('safeExecuteInTheMiddle', () => {
7474
assert.deepStrictEqual(error, err);
7575
}
7676
});
77-
it('should return result', () => {
77+
it('should return result', function () {
7878
const result = safeExecuteInTheMiddle(
7979
() => {
8080
return 1;
@@ -88,8 +88,8 @@ describe('safeExecuteInTheMiddle', () => {
8888
});
8989
});
9090

91-
describe('safeExecuteInTheMiddleAsync', () => {
92-
it('should not throw error', () => {
91+
describe('safeExecuteInTheMiddleAsync', function () {
92+
it('should not throw error', function () {
9393
safeExecuteInTheMiddleAsync(
9494
async () => {
9595
await setTimeout(() => {}, 1);
@@ -101,7 +101,7 @@ describe('safeExecuteInTheMiddleAsync', () => {
101101
true
102102
);
103103
});
104-
it('should throw error', async () => {
104+
it('should throw error', async function () {
105105
const error = new Error('test');
106106
try {
107107
await safeExecuteInTheMiddleAsync(
@@ -117,7 +117,7 @@ describe('safeExecuteInTheMiddleAsync', () => {
117117
assert.deepStrictEqual(error, err);
118118
}
119119
});
120-
it('should return result', async () => {
120+
it('should return result', async function () {
121121
const result = await safeExecuteInTheMiddleAsync(
122122
async () => {
123123
await setTimeout(() => {}, 1);

0 commit comments

Comments
 (0)