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
Another way would be using mocha-suppress-logs
to hide logs generated by successuful tests but still keep the ones generated by failed tests to ease debugging.
Install:
npm install --save-dev mocha-suppress-logs
Then use it like this:
const suppressLogs = require('mocha-suppress-logs');
describe('Something', () => {
suppressLogs();
it('should do something', () => {
// test code
});
});
You can also do so globally for the entire test suite.
Here's a link to the module itself:
https://www.npmjs.com/package/mocha-suppress-logs