Joined July 2012
·

Forbes Lindesay

Cambridge, UK
·
·
·

Posted to Auto-run tests in Node.js over 1 year ago

Your package.json could be written as:

"scripts": {
  "autotest": "supervisor -q -n exit -x mocha -- -b"
},
"devDependencies": {
  "mocha": "~1.10.0",
  "supervisor": "~0.5.2"
}

and would behave the same because npm is super clever

I'd recommend something like Q because it's compatible with ES6 generators. That means that once the next version of JS comes out you'll be able to write code like:

spawn(function* () {
  var result = yield webRequestAsync('http://foo.com');
  //Do something with result
  console.log(JSON.parse(result).name);
});

which looks just like the sync equivalent, except for the yield keyword. It would then be exactly equivalent to:

function () {
  return webRequestAsync('http://foo.com')
    .then(function (result) {
      //Do something with result
      console.log(JSON.parse(result).name);
    });
}();

Consider that yield also works perfectly inside try catch statements etc. and you're onto a winner.

Achievements
122 Karma
937 Total ProTip Views