faq labelnode node_modules/.bin/mocha --version(Local) and mocha --version(Global). We recommend avoiding the use of globally installed Mocha.I try to run Mocha with a CoffeeScript compiler and I get Unexpected token import.
Below is my command which I'm trying to run:
node_modules/mocha/bin/mocha --require coffeescript/register app/server/lib/server_tests/*.test.coffee --reporter mochawesome
Here is the error stack trace
````
import should from 'should';
^^^^^^
SyntaxError: Unexpected token import
at new Script (vm.js:51:7)
at createScript (vm.js:136:10)
at Object.runInThisContext (vm.js:197:10)
at Module._compile (module.js:613:28)
at Object.loadFile (/Users/timofte/Documents/work/projects/sonar/node_modules/coffeescript/lib/coffeescript/register.js:18:19)
at Module.load (/Users/timofte/Documents/work/projects/sonar/node_modules/coffeescript/lib/coffeescript/register.js:53:36)
at tryModuleLoad (module.js:501:12)
at Function.Module._load (module.js:493:3)
at Module.require (module.js:593:17)
at require (internal/module.js:11:18)
at /Users/timofte/Documents/work/projects/sonar/node_modules/mocha/lib/mocha.js:250:27
at Array.forEach (
at Mocha.loadFiles (/Users/timofte/Documents/work/projects/sonar/node_modules/mocha/lib/mocha.js:247:14)
at Mocha.run (/Users/timofte/Documents/work/projects/sonar/node_modules/mocha/lib/mocha.js:576:10)
at Object.
at Module._compile (module.js:649:30)
at Object.Module._extensions..js (module.js:660:10)
at Module.load (module.js:561:32)
at tryModuleLoad (module.js:501:12)
at Function.Module._load (module.js:493:3)
at Function.Module.runMain (module.js:690:10)
at startup (bootstrap_node.js:194:16)
at bootstrap_node.js:666:3
```
It works if I change that line toshould = require 'should'`
mocha --version and node node_modules/.bin/mocha --version: 5.2.0node --version:v9.8.0About halfway down the stacktrace ("mocha.js:250"), Mocha attempts to load your "require'd" coffeescript registration - it blows up during that processing here.
My current CoffeeScript experience is with v1.12.7, where my code uses the style documented here (i.e., like your "It works if I" code). Think your import should from 'should'; is invalid CoffeeScript which is why it implodes.
CoffeeScript 2 supports import. I use that code in other places in my meteor app and it works. If I run these tests from meteor with mocha it works just fine.
My problem came when I've tried to use mochawesome as a reporter and I have to run mocha command for that.
So it does, I now see.
Does it work with the "spec" reporter?
Mocha works in Meteor environment, but only with the terminal reporter, with this command: "TEST_WATCH=1 meteor test --port 3100 --driver-package meteortesting:mocha",
The web one is an empty page as follows:

That's why I'm tying to add a custom reporter, running mocha command as described in the issue.
Assuming what you're calling the terminal reporter is the same as "spec" reporter. What happens when you use the "html" reporter then?
If I run node_modules/mocha/bin/mocha --require coffeescript/register app/server/lib/server_tests/*.test.coffee --reporter html, I get the same error.
I meteor I'm not able to pass any mocha arguments to my meteor test command.
I'm not sure if this helps.
Thanks for your time and patience.
Well, at least that eliminates "mochawesome" reporter from the issue.
And you could specify arguments in "mocha.opts", if we knew what.
Could be bootstrapping issue (code that CS would use to make use of import not loaded at point where initial compilation attempted). Maybe try --require something else prior to CoffeeScript registration.
How about:
$ node_modules/mocha/bin/mocha --require should --require coffeescript/register app/server/lib/server_tests/*.test.coffee --reporter html
@elisei-timofte Do you have any updates regarding this?
I do not think this is a mocha issue, rather than how you are configuring coffee script to run through mocha.
Hi, I don't have any updates on this yet.
It could be just a CoffeeScript issue. I'll have to investigate more when I got some time.
Thanks for your help. If I'll find a solution I'll post it here, maybe it will help others.
Most helpful comment
Hi, I don't have any updates on this yet.
It could be just a CoffeeScript issue. I'll have to investigate more when I got some time.
Thanks for your help. If I'll find a solution I'll post it here, maybe it will help others.