In my test directory, I have a file mocha.opts
containing the following:
--harmony
--recursive
--growl
--reporter spec
--require should
When I run mocha
, I get the following error:
/project/server/utilities/encryption.js:3
const
^^^^^
SyntaxError: Use of const in strict mode.
This is, of course, because my use of const
requires ES6 Harmony. When I run mocha --harmony
, my tests execute just fine. And the other entries in my mocha.opts
file work as expected.
Does the mocha.opts
file ignore the --harmony
argument for some reason? Or am I doing it wrong? The Mocha docs don't elaborate and I haven't been able to find the answer here or anywhere else.
The asker asks:
When I run
mocha --harmony
, my tests execute just fine. [...]Does the
mocha.opts
file ignore the--harmony
argument for some reason?
Yes, mocha.opts
ignores the --harmony
argument. The --harmony
option is not a Mocha option but a Node.js option. This is an option that must be passed to Node.js before it starts executing. However, mocha.opts
is read after Node.js has started and so even if Mocha was able to understand the option, it would not be able to do anything about it.
But why does it work on the command line? Shouldn't it be the case that when I run mocha --harmony
, Mocha has to first start before parsing the --harmony
option? No, because mocha
is script that starts the "real" Mocha. The shell script detects --harmony
and makes sure it is passed to Node.js when it starts the "real" Mocha.
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