While unit-testing my node.js application (which is basically a REST backend) using mocha and supertest, I need only the test-specific message on the screen, but the stdout
In your app.js:
if (process.env.NODE_ENV !== 'test') {
app.use(express.logger());
}
At the top of each of your mocha files:
process.env.NODE_ENV = 'test';
Update:
We use this function in our import code:
function logExceptOnTest(string) {
if (process.env.NODE_ENV !== 'test') {
console.log(string);
}
}
Then, replace all your console.log('it worked') with logExceptOnTest('it worked'). The basic trick is to use environment variables as a global flag as to the level of logging you want.