Skip to content

Commit 3131ecc

Browse files
committed
feat: add more tests to improve coverage
1 parent 60cf4bf commit 3131ecc

1 file changed

Lines changed: 57 additions & 0 deletions

File tree

test/profile.more.branches.spec.ts

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
/*!
2+
* Additional profile.ts branch coverage tests
3+
*/
4+
import './mocks';
5+
import { expect } from 'chai';
6+
import * as sinon from 'sinon';
7+
import * as mock from 'mock-require';
8+
9+
// We re-require the module inside tests to pick up env changes when needed
10+
11+
describe('profile.ts additional branches', () => {
12+
afterEach(() => {
13+
mock.stopAll();
14+
delete (process as any).env.IMQ_LOG_TIME_FORMAT;
15+
});
16+
17+
it('logDebugInfo: should not attempt to call missing log method (no-op path)', () => {
18+
const { logDebugInfo, LogLevel } = mock.reRequire('../src/profile');
19+
const fakeLogger: any = {
20+
// intentionally no 'log' or 'info' method for selected level
21+
error: sinon.spy(),
22+
};
23+
const options = {
24+
debugTime: true,
25+
debugArgs: true,
26+
className: 'X',
27+
args: [1, { a: 2 }],
28+
methodName: 'm',
29+
start: (process.hrtime as any).bigint(),
30+
logger: fakeLogger,
31+
logLevel: LogLevel.LOG,
32+
};
33+
expect(() => logDebugInfo(options)).to.not.throw();
34+
// ensures error not called due to serialization success
35+
expect(fakeLogger.error.called).to.equal(false);
36+
});
37+
38+
it('logDebugInfo: should call logger.error on JSON.stringify error (BigInt arg)', () => {
39+
const { logDebugInfo, LogLevel } = mock.reRequire('../src/profile');
40+
const fakeLogger: any = {
41+
error: sinon.spy(),
42+
};
43+
const args = [BigInt(1)]; // JSON.stringify throws on BigInt
44+
const options = {
45+
debugTime: false,
46+
debugArgs: true,
47+
className: 'Y',
48+
args,
49+
methodName: 'n',
50+
start: (process.hrtime as any).bigint(),
51+
logger: fakeLogger,
52+
logLevel: LogLevel.INFO,
53+
};
54+
logDebugInfo(options);
55+
expect(fakeLogger.error.calledOnce).to.equal(true);
56+
});
57+
});

0 commit comments

Comments
 (0)