Skip to content

Instantly share code, notes, and snippets.

@richardprior
Last active August 29, 2015 13:56
Show Gist options
  • Save richardprior/8795490 to your computer and use it in GitHub Desktop.
Save richardprior/8795490 to your computer and use it in GitHub Desktop.
Webstorm: Workaround to enable --harmony flag on node mocha tests

#Workaround to enable --harmony flag on node mocha tests

  1. Create a shell script which runs node with the harmony flag and passes along any other command line arguments sent to the shell script. Mark this script as executable (chmod +x). See 'node-wrapper' for an example bash script.
  2. Edit you Mocha 'Run/Debug Configuration' to use the wrapper script as the node interpreter.
'use strict';
var expect = require('chai').expect;
function* fibonacci(limit) {
let previous = 0;
let current = 1;
while(previous + current < limit) {
let temp = previous;
previous = current;
yield current = temp + current;
}
}
// Contrived test to make sure harmony flag is set
describe('harmony', function () {
it('should have generators', function (done) {
var expected = [1,2,3,5,8,13,21,34,55,89,144,233,377,610,987];
var i = 0;
for (let value of fibonacci(1000)) {
expect(value).to.equal(expected[i++]);
}
expect(i).to.equal(15);
done();
});
});
#!/bin/bash
node --harmony $@
@innerdaze
Copy link

Nice one =]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment