I use Morgan (default express generator request logger), and I'm trying to disable it during unit testing.
Currently I'm using the default configuration, which loads Morgan in app.js
const logger = require('morgan');
...
const app = express();
...
app.use(logger('dev'));
I tried moving the code to bin/www
(which imports the express app and starts the server), but it wouldn't work...
Any ideas?
You can use skip option of morgan
like this:
const logger = require('morgan');
const app = express();
app.use(logger('dev', { skip: (req, res) => process.env.NODE_ENV === 'test' }));
When you run the unit test, the process.env.NODE_ENV
will be set to 'test'. See Environment Variables
NODE_ENV - Set to 'test' if it's not already set to something else.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With