npm

Need private packages and team management tools?Check out npm Orgs. »

shhh

1.0.3 • Public • Published

shhh

Coverage Status

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'); // nothing shows up here either
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');       // printed to console
    shhh.enable();
    console.log('Tests about to run..'); // not printed to console
  });
 
  after(function() {
    console.log('Tests finished');       // not printed to console
    shhh.disable();
    console.log('done');                 // printed to console
  });
 
  it('should do stuff without console being annoying', function() {
    // The function is very noisy but that stuff won't show up in test output
    const result = dummyMath.add(1, 1);
    // No assertion library for simplicity
    if (result !== 2) {
      throw new Error('1 + 1 should be 2');
    }
  });
})

Tests

npm run test

Run test coverage

npm run cover

install

npm i shhh

Downloadsweekly downloads

496

version

1.0.3

license

MIT

homepage

github.com

repository

Gitgithub

last publish

collaborators

  • avatar
Report a vulnerability