Skip to content

Commit

Permalink
Silence logger in tests
Browse files Browse the repository at this point in the history
At the moment, the logger will log to console during tests, which is
noisy and undesirable.

This change adds a test setup file, which silences the logger by setting
all of its methods to no-ops.

This behaviour can be overridden with the `LOGGING` environment
variable:

```bash
LOGGING=true npm test
```
  • Loading branch information
Alec Gibson committed Jan 10, 2020
1 parent 960f5d1 commit ccd53e7
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
1 change: 1 addition & 0 deletions test/mocha.opts
@@ -1,3 +1,4 @@
--reporter spec
--check-leaks
--recursive
--file test/setup.js
10 changes: 10 additions & 0 deletions test/setup.js
@@ -0,0 +1,10 @@
var logger = require('../lib/logger');

if (process.env.LOGGING !== 'true') {
// Silence the logger for tests by setting all its methods to no-ops
logger.setMethods({
info: function() {},
warn: function() {},
error: function() {}
});
}

0 comments on commit ccd53e7

Please sign in to comment.