Write your mocha tests in ES6

Even if you're not ready to commit to converting your main codebase to ES6 quite yet, there's a less invasive way to add it to your workflow – use it for writing tests.

Thanks to the mocha-traceur compiler (which is basically just traceur-runner) you can seamlessly run your ES6 mocha tests any production environment. All you need to do is run

npm install mocha-traceur --save-dev  
mocha --compilers js:mocha-traceur  

intead of just mocha.

A few ES6 features to try

If you haven't taken the time to look through the many features of ES6 supported in traceur, you definitely should. Here are a few to get you started:

Arrow functions

Arrow functions are concise and bind automatically to the parent this context, which is pretty useful

var add5 = myArray.map(item => item + 5);

this.whatever = function () { ... };  
checkSomething(options, (err) => {  
    if (err) this.whatever(500);
});

ES6 template strings

If you're running any shell commands/child processes from your tests, template strings can save you from having to hardcode paths.

var srcFile = './src/js/index.js';  
var destFile = './dest/bundle.js';  
var command = `webpack ${srcFile} ${destFile} -p`;  

Destructuring Assignment

Destructuring assignment allows you to assign multiple variables at once.

var {user, product} = require('./stubs');  
// equivalent to
// var stubs = require('./stubs');
// var user = stubs.user;
// var product = stubs.product;

Rest Parameters

You can use rest parameters to accept a variable number of arguments as an Array:

function eatFood(name, ...foods) {  
    var foodString = foods.join(', ');
    return `${name} eats ${foodString}`;
}