javascriptnode.jsautomationnodemonnode-supervisor

Node.js: Identifying the file that is modified for automated test case execution


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?


Solution

  • 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)
      });
    });