1

Right now I have a unit testing build environment using node.js and nodeunit. Very happy with these but now I need TCO. I know that TCO has been added into the ES6 standard, but I don't know how to allow it for use with my project. Tried the Harmony flag, but couldn't get it to work with nodeunit. Any help?

Got the idea for using Harmony here: Node.js tail-call optimization: possible or not?

I like the way these guys think, but I can't do the first answer because then other working on the project would also be forced to change their nodeunit.cmd files (which may screw up other projects they are working on) and the second answer doesn't appear to work: NodeUnit enable harmony features

Community
  • 1
  • 1
user3380049
  • 139
  • 1
  • 10

1 Answers1

1

From what I understand, it looks like you want to write unit tests in ES5 using nodeunit to test your code written in ES6.

If I understood well, then you can check out this post which shows how to achieve that.

This solution requires you to npm install traceur and then you can require() your ES6 module from within your tests like so :

var traceur = require('traceur');

traceur.require.makeDefault(function(filename) {
  return filename.indexOf('node_modules') === -1; // Don't parse node modules
});

var myModule = require('./../path/to/my/module.js');

module.exports = {
  // ... tests ...
};

Now you should be able to run that with nodeunit.

Mickäel A.
  • 9,012
  • 5
  • 54
  • 71