Skip to content
This repository has been archived by the owner on Dec 31, 2019. It is now read-only.

Babel can't parse _mocha #47

Open
leebyron opened this issue Jul 7, 2015 · 14 comments
Open

Babel can't parse _mocha #47

leebyron opened this issue Jul 7, 2015 · 14 comments
Labels

Comments

@leebyron
Copy link

leebyron commented Jul 7, 2015

When running

babel-node node_modules/.bin/isparta cover --report html node_modules/.bin/_mocha

As suggested by the README, I encounter this error:

Transformation error; return original code
{ [SyntaxError: /Users/leebyron/src/graphql-js/node_modules/mocha/bin/_mocha: 'return' outside of function (392:2)]
  pos: 9902,
  loc: { line: 392, column: 2 },
  raisedAt: 9908,
  _babel: true,
  codeFrame: '  390 |   \u001b[32m}\u001b[39m\u001b[34m\u001b[1m)\u001b[22m\u001b[39m\u001b[1m;\u001b[22m\n  391 | \n> 392 |   \u001b[36mreturn\u001b[39m\u001b[1m;\u001b[22m\n      |   ^\n  393 | \u001b[32m}\u001b[39m\n  394 | \n  395 | \u001b[90m// load\u001b[39m' }
@loganfsmyth
Copy link

Looked into this a bit since it was also reported to Babel and it seems like something has changed in istanbul between 0.3.14 and 0.3.15? ispartas instrumentSync handler is being called on the _mocha file.

@loganfsmyth
Copy link

Looks like mocha has merged mochajs/mocha#1787 so this shouldn't be an issue in the future.

@leebyron Looking at this a bit more after playing with it myself, if you have your code in a subfolder, it seems setting the instrumentation root avoids this too.

.istanbul.yml

instrumentation:
    root: src

@leebyron
Copy link
Author

Thanks for the investigation! This has been very helpful


Sent from Mailbox

On Mon, Jul 13, 2015 at 11:23 AM, Logan Smyth notifications@github.com
wrote:

Looks like mocha has merged mochajs/mocha#1787 so this shouldn't be an issue in the future.
@leebyron Looking at this a bit more after playing with it myself, if you have your code in a subfolder, it seems setting the instrumentation root avoids this too.

.istanbul.yml

instrumentation:
    root: src

Reply to this email directly or view it on GitHub:
#47 (comment)

@screendriver
Copy link

Thank you @loganfsmyth . Your .istanbul.yml helped me out! 👍

@Swaagie
Copy link

Swaagie commented Oct 19, 2015

Still getting transpile errors with mocha@2.3 and the istanbul config file does little to resolve this.

➜  table git:(master) ✗ babel-node ./node_modules/.bin/isparta cover ./node_modules/.bin/mocha
Transformation error; return original code
{ [Error: Line 1: Unexpected token ILLEGAL]
  lineNumber: 1,
  description: 'Unexpected token ILLEGAL',
  index: 0 }

import TestUtils from 'react-addons-test-utils';
^^^^^^

weird thing is that it is working when npm is in charge of running the command (another Component) but that same command fails from the CLI and altered slightly to work without npm.

@douglasduteil
Copy link
Owner

Hi @leebyron

After some code surfing 🏄
I found out that the problem comes form the istanbul default exclusion pattern that don't match for node_modules/.bin/_mocha

Here is deduction http://tonicdev.com/douglasduteil/isparta-68-transformation-error-return-original-code

@jamesplease
Copy link

Is this still a problem? I was unable to reproduce it.

@chromakode
Copy link

Yes, just ran into this. Following @douglasduteil's suggestion, I changed my invocation from:

babel-node $(npm bin)/isparta cover $(npm bin)/_mocha

to:

babel-node $(npm bin)/isparta cover node_modules/mocha/bin/_mocha

and no longer get this error.

jbinto added a commit to jbinto/thirtyone-server that referenced this issue Jan 9, 2016
jbinto added a commit to jbinto/thirtyone-server that referenced this issue Jan 9, 2016
jbinto added a commit to jbinto/thirtyone-server that referenced this issue Jan 9, 2016
@glebmachine
Copy link

Hi everyone)

I using isparta as @chromakode said few days ago:
./node_modules/.bin/babel-node node_modules/isparta/bin/isparta cover ./node_modules/mocha/bin/_mocha
But nothing changes, it still throw this errors (test passed successfully, everything ok, except this erorr)

@patrickheeney
Copy link

The workaround of node_modules/mocha/bin/_mocha in my case will not work because my mocha lives up a directory so I must use ../node_modules/mocha/bin/_mocha which has this same problem.

@glebmachine
Copy link

Node already support es6, just call like this:
./node_modules/.bin/_mocha --compilers js:babel-core/register test/index.js

Thats all you need)

@patrickheeney
Copy link

@glebmachine Not sure I follow, my current command is: ../../node_modules/.bin/babel-node ../../node_modules/isparta/bin/isparta cover ../../node_modules/mocha/bin/_mocha which results in the same error you are experiencing. The workaround of node_modules/mocha/bin/_mocha mentioned above will not work in my case. Am I missing something?

@glebmachine
Copy link

Sorry for misunderstanding!

Everything i ok. I'm using like u said, and everything fine:
node_modules/.bin/babel-node node_modules/isparta/bin/isparta cover --report text --report html node_modules/mocha/bin/_mocha.

Please, ignore my prev comment)

@niftylettuce
Copy link

It is now working with istanbul@^1.1.0-alpha.1. See my setup here https://github.com/niftylettuce/koa-ratelimit-promises and my code coverage report here https://codecov.io/gh/niftylettuce/koa-ratelimit-promises. Thanks!

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

No branches or pull requests

10 participants