4

I'd like to automatically execute clear between each test iteration with mocha --watch. Is there a nice way to automatically execute a command before (re)running mocha?

Ashley Coolman
  • 11,095
  • 5
  • 59
  • 81

2 Answers2

10

Mocha supports different reporters, and the min reporter does exactly what you are looking for:

mocha run --recursive dist/tests --reporter min

It's especially helpful if used together with the --watch flag, as then the tests run constantly on file changes.

k0pernikus
  • 60,309
  • 67
  • 216
  • 347
2

The way I ended up doing it is using --delay, which lets you run your own async code before beginning the tests (using global.run(). Docs here

_.tests.js:

var exec = require('child_process').exec;
var child;
child = exec('clear', function (error, stdout, stderr) {
    console.log(stdout);
    console.log(stderr);
    if (error !== null) {
        console.log('exec error: ' + error);
    }
    global.run();
});
Ashley Coolman
  • 11,095
  • 5
  • 59
  • 81