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

Transformation error; return original code #68

Open
almeynman opened this issue Sep 22, 2015 · 24 comments
Open

Transformation error; return original code #68

almeynman opened this issue Sep 22, 2015 · 24 comments

Comments

@almeynman
Copy link

Hello,

when I run

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

I get the following error:

Transformation error; return original code
{ [Error: Line 1: Unexpected token ILLEGAL]
  lineNumber: 1,
  description: 'Unexpected token ILLEGAL',
  index: 0 }
Creating a pool connected to localhost:28015

Although tests pass and report is generated after the error...

I downgraded from 3.0.4 to 3.0.2 and error disappered.

Thanks

@gausie
Copy link

gausie commented Oct 3, 2015

I am also experiencing this error.

@impy88
Copy link

impy88 commented Oct 5, 2015

+1

2 similar comments
@mtlima
Copy link

mtlima commented Oct 6, 2015

+1

@razvanip
Copy link

+1

@hden
Copy link

hden commented Oct 18, 2015

Using the .istanbul.yml from #47 (comment) solves it.

@douglasduteil
Copy link
Owner

I'll have to investigate if I can solve this without .istanbul.yml

@douglasduteil
Copy link
Owner

Similar to #47

@kishorevarma
Copy link

I am also facing the same issue +1

@douglasduteil
Copy link
Owner

Hi @almasakchabayev

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

@kishorevarma
Copy link

I am still facing same issue, even though I have changed as you mentioned

 babel-node ./node_modules/.bin/isparta cover ./node_modules/mocha/bin/_mocha -- --require ./tests/test_helper.js tests/**/*.js
Transformation error; return original code
{ [Error: Line 1: Unexpected token ILLEGAL]
  lineNumber: 1,
  description: 'Unexpected token ILLEGAL',
  index: 0 }

.babelrc

{
  "presets": ["es2015"]
}

@douglasduteil
Copy link
Owner

Aie @kishorevarma
I 🆙 the below TonicDev
./node_modules/mocha/bin/_mocha is not working either (ಠ ∩ಠ)

@kishorevarma
Copy link

@douglasduteil , oh yeah I missed that part in TonicDev , yeah now I am using as follow

 babel-node ./node_modules/.bin/isparta cover node_modules/mocha/bin/_mocha -- --require ./tests/test_helper.js tests/**/*.js

but now there is no error, its silently exiting, when I change .babelrc to as follow, it actually run the tests but won't generate the report because stage option not recognisable (unknown option)

{ "stage: 0 }

so If I am using as follow, it not running tests and not giving report and not giving error :(

 {
    "presets": ["es2015"]
 }

@kishorevarma
Copy link

@douglasduteil ignore I think its some problem with babel versions. I will try to find out the issue
thanks :)

@kishorevarma
Copy link

@douglasduteil, I sorted out the issues but got struck with decorators trnasformation in babel 6. but the above issue got resolved thanks, I am using with out babel-node as shown in your example
node_modules/.bin/isparta cover --verbose --include-all-sources --excludes '**<some folder>**' --report lcov --report html node_modules/mocha/bin/_mocha -- tests/**/*.js

Thanks
Kishore

@ngduc
Copy link

ngduc commented Dec 13, 2015

I have the same issue, tried all above tips but they didn't work for me.
Is this fixed yet? Thanks.

@chimico
Copy link

chimico commented Dec 18, 2015

+1

@tarciosaraiva
Copy link

I have the same issue but it doesn't seem to affect the end result. Here's the command I'm running:

./node_modules/.bin/babel-node ./node_modules/.bin/isparta cover --report lcov ./node_modules/mocha/bin/_mocha -- ./test/unit

What I found is that by adding the configuration below to .istanbul.yml fixes it, as if telling ispartan to look for the files to instrument.

instrumentation:
  root: <src_dir>

That did the trick for me.

@pvdz
Copy link

pvdz commented Mar 3, 2016

FYI;

The reason (as described above) is a default inclusion pattern.

The solution is passing on a root where files are checked only. This may also speed up the whole thing depending on your setup (since it won't have to cover your entire repo but just your source files).

You also don't need a yml file for this as root is a cli param;

./node_modules/.bin/babel-node ./node_modules/.bin/isparta cover --root src/  ./node_modules/mocha/bin/_mocha -- ./test/unit 

@montogeek
Copy link

@qfox Your solution worked, thank you :)

@ngduc
Copy link

ngduc commented Mar 10, 2016

@montogeek @qfox solution does not work for me.
This command works for me:

NODE_PATH=./src babel-node $(npm bin)/isparta cover --verbose --report text --report html $(npm bin)/_mocha -- --require ./tools/test/test-init src/**/*.spec.js

https://github.com/ngduc/react-setup/blob/master/package.json

@mwshortt
Copy link

@qfox Thank you so much! Your solution works for me. That error was driving me crazy. Also after adding that my coverage went up by 6%, has anyone else seen a coverage spike like that upon fixing this error?

pithu added a commit to js-joda/js-joda that referenced this issue Mar 15, 2016
ModuloM pushed a commit to kodokojo/kodokojo-ui that referenced this issue Mar 22, 2016
jbinto added a commit to jbinto/frig that referenced this issue Apr 13, 2016
* Add npm script `cover`, which calls istanbul:
  * Do not execute `istanbul` via `babel-node`, this is deprecated, instead use `babel-register` as an argument to `mocha` (credit: gotwarlost/istanbul#594 (comment))
  * Use `--root src/` to fix issue where istanbul also attempts to cover `mocha` (credit: douglasduteil/isparta#68 (comment))
  * Use `--include-all-sources` to make the coverage percentages actually meaningful by including sources that didn't get executed

* In `src/higher_order_components/errors_normalizer.js`, make minor change to return statement. This form: `if (foo) return { a: 'b' }` seems to have confused Istanbul's coverage highlighter. There are other cases like this, that are bugs in Istanbul (e.g. gotwarlost/istanbul#557). Probably worth making a repro case for this and reporting to them.
jbinto added a commit to jbinto/frig that referenced this issue Apr 13, 2016
* Add npm script `cover`, which calls istanbul:
  * Do not execute `istanbul` via `babel-node`, this is deprecated, instead use `babel-register` as an argument to `mocha` (credit: gotwarlost/istanbul#594 (comment))
  * Use `--root src/` to fix issue where istanbul also attempts to cover `mocha` (credit: douglasduteil/isparta#68 (comment))
  * Use `--include-all-sources` to make the coverage percentages actually meaningful by including sources that didn't get executed

* In `src/higher_order_components/errors_normalizer.js`, make minor change to return statement. This form: `if (foo) return { a: 'b' }` seems to have confused Istanbul's coverage highlighter. There are other cases like this, that are bugs in Istanbul (e.g. gotwarlost/istanbul#557). Probably worth making a repro case for this and reporting to them.
@rodoabad
Copy link

rodoabad commented May 6, 2016

This is still going on for me.

"coverage": "babel-node ./node_modules/isparta/bin/isparta cover --report html ./node_modules/mocha/bin/_mocha -- test/unit",

@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!

@ziyofun
Copy link

ziyofun commented Sep 6, 2018

undering [email protected] and [email protected], I find that if variable's name is same as function's name will throw this error. such as:

function foo() {
    const foo = 'bar';
}

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

No branches or pull requests