Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Document how to use --harmony* flags with _mocha #2665

Closed
BrandonZacharie opened this issue Jan 11, 2017 · 11 comments
Closed

Document how to use --harmony* flags with _mocha #2665

BrandonZacharie opened this issue Jan 11, 2017 · 11 comments
Labels
area: documentation anything involving docs or mochajs.org

Comments

@BrandonZacharie
Copy link

I expect these flags to work because

➜ node_modules/.bin/_mocha --help               

  ...

  Options:

    ...
    --harmony<_classes,_generators,...>     all node --harmony* flags are available

However, as of

➜ node_modules/.bin/_mocha --version
3.2.0

I get

➜ node_modules/.bin/_mocha --harmony_async_await

  error: unknown option `--harmony_async_await'
@BrandonZacharie BrandonZacharie changed the title --harmony* flags not working with _mocha (error: unknown option) --harmony* flags not working with _mocha Jan 11, 2017
@ScottFreeCode
Copy link
Contributor

I'm not sure off the top of my head whether there's a way to give mocha and _mocha separate help messages. I am fairly sure that the main reason for the two separate files is specifically so that mocha can pass the Node flags (such as --harmony*) to Node while calling the actual _mocha under the hood. This would presumably be improved/fixed by #2517... Or, depending on why you're using _mocha, we may be able to figure out how to call it so as to get the --harmony* flags to Node directly, rather than sending them through Mocha at all.

@BrandonZacharie
Copy link
Author

BrandonZacharie commented Jan 11, 2017

If there's any other way to get --harmony_async_await working, i'm for it. I'm using _mocha with istanbul.

@ScottFreeCode
Copy link
Contributor

Does node --harmony_async_await node_modules/istanbul/lib/cli.js <command> node_modules/mocha/bin/_mocha still work? (Found here: gotwarlost/istanbul#44 (comment) the next thing after that on google is https://www.npmjs.com/package/istanbul-harmony...)

@BrandonZacharie
Copy link
Author

➜ node --harmony_async_await node_modules/.bin/istanbul cover node_modules/.bin/_mocha
node_modules/mocha/lib/mocha.js:79
  this.files = [];
             ^

TypeError: Cannot set property 'files' of undefined
    at Mocha (node_modules/mocha/lib/mocha.js:79:14)
    at Object.<anonymous> (test/index.js:10:13)
    at Module._compile (module.js:571:32)
    at Object.Module._extensions..js (module.js:580:10)
    at Object.Module._extensions.(anonymous function) [as .js] (node_modules/istanbul/lib/hook.js:109:37)
    ...

@BrandonZacharie
Copy link
Author

BrandonZacharie commented Jan 12, 2017

I think I understand now... I tried your script on other repos that use istanbul and it worked perfectly. The one i'm working with now spills out a bunch of errors like

Transformation error; return original code
{ Error: Line 26: Unexpected token =>
    at constructError (node_modules/esprima/esprima.js:2407:21)
    at createError (node_modules/esprima/esprima.js:2426:17)
    at unexpectedTokenError (node_modules/esprima/esprima.js:2500:13)
    ...
  lineNumber: 26,
  description: 'Unexpected token =>',
  index: 560 }

I believe this is related to istanbul and ES8 syntax. The others that tested fine with your script, like this one, only use ES6 syntax.

With that said, I think it would still be A Good Idea™ to go forward with #2517 and maybe document this workaround somewhere in the meantime.

@ScottFreeCode
Copy link
Contributor

With that said, I think it would still be A Good Idea™ to go forward with #2517 and maybe document this workaround somewhere in the meantime.

Yeah, I'm a little surprised myself that it's this tricky, so we should definitely document this until we can test that #2517 doesn't break anything (depending on how it works, it might have the same problem running Istanbul as using mocha rather than _mocha does now...). Since we've got issue #2517 to track the potential simplification, mind if we use this ticket to track the lack of documentation for the workaround?

@BrandonZacharie
Copy link
Author

BrandonZacharie commented Jan 12, 2017

Sounds good. On that note, is the Wiki the appropriate place to put something like this? If so, maybe we could add a Known Issues section and put this there.

@ScottFreeCode
Copy link
Contributor

It should be in theory, but I don't know how up to date it is.

@ScottFreeCode ScottFreeCode changed the title --harmony* flags not working with _mocha Document how to use --harmony* flags with _mocha Jan 12, 2017
@Munter
Copy link
Contributor

Munter commented Jan 12, 2017

@BrandonZacharie You might have better luck with using nyc for code coverage rather than istanbul

@sabakugaara
Copy link

sabakugaara commented Jan 21, 2017

I just use node --harmony ./node_modules/.bin/istanbul cover ./node_modules/.bin/_mocha -- tests/*, it works well

istanbul ^1.0.0-alpha.2
mocha ^3.2.0

@drazisil drazisil added the area: documentation anything involving docs or mochajs.org label Mar 30, 2017
@juergba
Copy link
Contributor

juergba commented Sep 3, 2019

The _mocha executable does not support Node flags and there are no plans to do so in future.

You have two options:

  • use the mocha executable which detects the Node flags and spawns a child-process.
  • pass the Node flags directly to Node (not via Mocha) as shown above by @sabakugaara

see docu

@juergba juergba closed this as completed Sep 3, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: documentation anything involving docs or mochajs.org
Projects
None yet
Development

No branches or pull requests

6 participants