I'm trying to create a grunt custom task that runs mocha tests but I can't figure out how to have grunt take the colored output from mocha and display it as it does when running the mocha command directly. Ie: grunt strips out the colors or does not pass them through. Here's the grunt task:
var exec = require("child_process").exec;
grunt.registerTask('mocha', 'Run unit (Mocha) tests.', function () {
var done = this.async();
var cmd = "mocha -R Spec tests/mocha/*.js";
exec(cmd, function (error, stdout, stderr) {
if (stdout) {
grunt.verbose.or.write(stdout);
done();
}
});
});
I realize there's a grunt-mocha plugin I could use (and have used) but I'm trying to eliminate dependencies and will also be doing some customization on this task.
Thanks!
This is mostly a duplicate of this question.
You need to add --colors to force Mocha to output ANSI color codes, otherwise it disables colors automatically since it isn't outputting to an actual terminal.
var cmd = "mocha --colors -R Spec tests/mocha/*.js";