test: add test for log level exclusiveness

This commit is contained in:
Rainer Killinger
2020-03-10 10:50:09 +01:00
parent 100b921488
commit 3fb99ad896

View File

@@ -311,6 +311,38 @@ export class LoggerSpec {
expect(spy).not.to.have.been.called();
}
@test
'log level exclusiveness'() {
const warnSpy = LoggerSpec.sandbox.on(console, 'warn', () => {
// noop WARN
});
const infoSpy = LoggerSpec.sandbox.on(console, 'info', () => {
// noop INFO
});
const okSpy = LoggerSpec.sandbox.on(console, 'log', () => {
// noop OK
});
// only warn and info = warn + info = 4 + 1 = 5
process.env.STAPPS_LOG_LEVEL = '5';
Logger.warn('Foo');
Logger.info('Bar');
Logger.ok('Baz');
expect(warnSpy).to.have.been.called();
expect(warnSpy.__spy.calls[0][0]).to.contain('[WARN]');
expect(warnSpy.__spy.calls[0][0]).to.contain('Foo');
expect(infoSpy).to.have.been.called();
expect(infoSpy.__spy.calls[0][0]).to.contain('[INFO]');
expect(infoSpy.__spy.calls[0][0]).to.contain('Bar');
expect(okSpy).to.not.have.been.called();
delete process.env.STAPPS_LOG_LEVEL;
}
@test
getLogLevel() {
const savedProcess = process;