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

"compilers" does not compile fork scripts #2519

Closed
maxclaus opened this issue Oct 5, 2016 · 3 comments
Closed

"compilers" does not compile fork scripts #2519

maxclaus opened this issue Oct 5, 2016 · 3 comments

Comments

@maxclaus
Copy link

maxclaus commented Oct 5, 2016

Running a project that depend on some features not available in the latest Node js yet such as async await I use --compilers js:babel-register on mocha to compile my code during the tests. This works really well in most cases. But this does not work if I have a fork process which also use async.

If I run babel-node over the main script it will by default compile the fork scripts as well.
But running mocha with --compilers js:babel-register it does not happen. I was expecting it would work the same way babel-node does.

Here is the a project to help reproduce the problem: https://github.com/maxcnunes/problem-fork-with-babel-node

@boneskull
Copy link
Contributor

boneskull commented Oct 5, 2016

(--compilers isn't needed here; you can use --require babel-register; see docs)

process.execPath must be babel-node for any forked process to run babel-node. --require and --compilers have no interaction with this.

three potential workarounds off the top of my head:

  • run Mocha with babel-node /path/to/mocha (the mocha executable forks the _mocha executable; it should retain process.execPath, but if it doesn't, babel-node _mocha would work instead)
  • in your test or test fixture, manually set process.execPath to /path/to/babel-node (though this may have unintended consequences)
  • manually set the execPath option when forking to /path/to/babel-node

related: #2517

@maxclaus
Copy link
Author

maxclaus commented Oct 6, 2016

Thanks @boneskull. From all your suggestions the only one I had not tried before was babel-node /path/to/mocha. Which by the way is the only one works 😄

So running babel-node node_modules/mocha/bin/_mocha test.js applies by default the compiler to the child process.

PS: Once you run the mocha with babel-node there is no need to pass --require or --compilers.

@boneskull
Copy link
Contributor

as I understand babel-node is especially slow versus other methods. have you found this to be true?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants