|
15 | 15 | */
|
16 | 16 |
|
17 | 17 | import * as assert from 'assert';
|
18 |
| -import { Instrumentation, InstrumentationBase } from '../../src'; |
| 18 | +import { |
| 19 | + Instrumentation, |
| 20 | + InstrumentationBase, |
| 21 | + InstrumentationConfig, |
| 22 | +} from '../../src'; |
| 23 | + |
| 24 | +interface TestInstrumentationConfig extends InstrumentationConfig { |
| 25 | + isActive?: boolean; |
| 26 | +} |
19 | 27 |
|
20 | 28 | class TestInstrumentation extends InstrumentationBase {
|
21 |
| - constructor() { |
22 |
| - super('test', '1.0.0'); |
| 29 | + constructor(config: TestInstrumentationConfig & InstrumentationConfig = {}) { |
| 30 | + super('test', '1.0.0', Object.assign({}, config)); |
23 | 31 | }
|
24 | 32 | enable() {}
|
25 | 33 | disable() {}
|
@@ -56,4 +64,29 @@ describe('BaseInstrumentation', () => {
|
56 | 64 | assert.strictEqual(called, true);
|
57 | 65 | });
|
58 | 66 | });
|
| 67 | + |
| 68 | + describe('getConfig', () => { |
| 69 | + it('should return instrumentation config', () => { |
| 70 | + const instrumentation: Instrumentation = new TestInstrumentation({ |
| 71 | + isActive: false, |
| 72 | + }); |
| 73 | + const configuration = |
| 74 | + instrumentation.getConfig() as TestInstrumentationConfig; |
| 75 | + assert.notStrictEqual(configuration, null); |
| 76 | + assert.strictEqual(configuration.isActive, false); |
| 77 | + }); |
| 78 | + }); |
| 79 | + |
| 80 | + describe('setConfig', () => { |
| 81 | + it('should set a new config for instrumentation', () => { |
| 82 | + const instrumentation: Instrumentation = new TestInstrumentation(); |
| 83 | + const config: TestInstrumentationConfig = { |
| 84 | + isActive: true, |
| 85 | + }; |
| 86 | + instrumentation.setConfig(config); |
| 87 | + const configuration = |
| 88 | + instrumentation.getConfig() as TestInstrumentationConfig; |
| 89 | + assert.strictEqual(configuration.isActive, true); |
| 90 | + }); |
| 91 | + }); |
59 | 92 | });
|
0 commit comments