shhh
![Coverage Status](https://coveralls.io/repos/github/akupila/shhh/badge.svg?branch=master)
Allows temporarily disabling console output, for instance when used with noisy unit tests.
While you can disable logging in production with this it's recommend to use a library specifically designed for that purpose.
For instance for node check out Winston
Installation
npm install --save shhh
Usage
const shhh = require('shhh');
console.log('This is visible');
shhh.enable();
console.log('This is hidden');
console.error('This is hidden too');
console.time('timer');
console.timeEnd('timer');
shhh.disable();
console.info('This is visible again');
Usage in mocha tests
dummyMath.js
module.exports.add = function(val1, val2) {
console.log('Doing some math..');
console.log('Adding ' + val1 + ' + ' + val2);
const result = val1 + val2;
console.log('Result is ' + result);
return result;
}
test.js
const shhh = require('shhh');
const dummyMath = require('./dummyMath');
describe('Some noisy module', function() {
before(function() {
console.log('Starting tests');
shhh.enable();
console.log('Tests about to run..');
});
after(function() {
console.log('Tests finished');
shhh.disable();
console.log('done');
});
it('should do stuff without console being annoying', function() {
const result = dummyMath.add(1, 1);
if (result !== 2) {
throw new Error('1 + 1 should be 2');
}
});
})
Tests
npm run test
Run test coverage
npm run cover