As per the title, I'm trying to test some AMD modules written in ES6 JS, running from nodejs.
I tried first with Intern: even after enabling --harmony
in nodejs, I ended up facing Intern's dependency chain, where I was not able to enable Harmony in e.g. Istanbul, esprima and others (I opened an issue for that).
I then moved onto mocha, and here I'm stuck ... strangely. I enabled Harmony both for nodejs and mocha itself, here's the package.json
test script:
"test": "node --harmony node_modules\\mocha\\bin\\mocha tests --harmony --recursive"
that I run from command prompt as npm test my_test_folder
. Still, some ES6 constructs (like const
) pass ok, but then it chokes on destructuring assignment. Here are the first output lines:
const { log, dir } = require('../consoleLogger.js');
^
SyntaxError: Unexpected token {
at Module._compile (module.js:439:25)
at Object.Module._extensions..js (module.js:474:10)
[...continues...]
I've also checked this SO thread and heard about transpilers, but I don't really know if they could work and I'm now trying to make transpilers work in this case.
Any idea on how to solve this, without resorting to change all ES6 bits spread in code? TA.
I've been using
npm install mocha-traceur
mocha ./tests/* --compilers js:mocha-traceur
and it's been working like a charm !
V8 does not implement destructuring yet, so it won't be available in node for a while. Block scoping (including const) is mostly implemented, but be aware that a pre-ES6 version of const was always available, so you might want to double check what you are actually observing -- you could try 'let' declarations for less ambiguity.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With