jeffrifwald / babel-istanbul

Yet another JS code coverage tool that computes statement, line, function and branch coverage with module loader hooks to transparently add coverage when running tests. Supports all JS coverage use cases including unit tests, server side functional tests and browser tests. Built for scale.
Other
144 stars 23 forks source link

SyntaxError: Unexpected reserved word with import #67

Closed nicolas-zozol closed 8 years ago

nicolas-zozol commented 8 years ago

It looks like babel-istanbul doesn't want to babelize my code.

My code start in src/test/index.js with

import optionTest from './data/option_test';
import tryTest from './data/try_test';

export {
    optionTest, tryTest
}

I launch with :

"scripts": {
    "compile": "babel src --out-dir dist  --source-maps",
    "test": "npm run compile && nodeunit dist/test/index.js",

    "cover": "rm -rf ./coverage && babel-node  ./node_modules/.bin/babel-istanbul cover --dir coverage/istanbul src/test/index.js"
  },
  "devDependencies": {
    "babel-cli": "^6.10.1",
    "babel-core": "^6.10.4",
    "babel-istanbul": "^0.8.0",
    "nodeunit": "~0.9.0",
    ....
  },

And I have

import optionTest from './data/option_test'; ^^^^^^

SyntaxError: Unexpected reserved word

It does the same launching directly >.\node_modules\.bin\babel-istanbul cover --dir coverage\istanbul src\test\index.js

I have ssen that a fellow lauched >.\node_modules\.bin\babel-babel-node .\node_modules\.bin\babel-istanbul cover --dir coverage\istanbul src\test\index.js ; It fails quckly, and I don't feel your lib is written to be launched with babel-node, but it launches it directly. Is it ?

jeffrifwald commented 8 years ago

You'll need you run your tests with babel-node. The babel-instabul package is only compiling during the instrumentation of your code. When it is actually running, it also needs to be compiled. Your test command should look something like this:

babel-node node_modules/.bin/babel-istanbul cover nodeunit -- dist/test/index.js

nicolas-zozol commented 8 years ago

Then I guess it doesn't work on windows :) I have an unexpected token found in the babel-istanbul.cmd file. I will check tomorrow on linux and see.

jeffrifwald commented 8 years ago

Your unexpected token error is likely just being thrown from the babel-istanbul cli. The library itself is written in es5, so it should work if you run your test code with babel-node.