2

I currently use nodemon or supervisor for automatic server restarting and automatic test cases execution. But currently my requirement is to run specific test cases when certain files are changed. For example if app\models\user.js is modified, I want test\model\user-test.js to be executed.

I order to achieve that I need to identify which are the files that are modified. How can I achieve that using nodemon or supervisor?

Rahul
  • 44,892
  • 25
  • 73
  • 103

1 Answers1

2

I dont know if you can do that with nodemon or supervisor, but you always could write your own:

var watch = require('watch');

function methodToDoTestOnFile(file) {
  //IMPLEMENT
}

watch.createMonitor(filesToWatch, function (monitor) {
  monitor.on('changed', function (f) {
    //do some test on f
    methodToDoTestOnFile(f)
  });
});
Jesús Quintana
  • 1,803
  • 13
  • 18
  • It works but is there a way to set the time interval for the monitor? Currently it takes couple of seconds to emit the event. – Rahul Oct 27 '15 at 12:10
  • The library use fs.watchFile, and the option interval is in the api. I guess that if you call watch.createMonitor(filesToWatch, {interval: milisecondTime}, cb), must work. – Jesús Quintana Oct 27 '15 at 12:20