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

using with the require hook #34

Closed jonathanong closed 8 years ago

jonathanong commented 8 years ago

i noticed that if i use this or istanbul with babel's require hook, it does not report the coverage correctly. http://babeljs.io/docs/usage/require/

do you know how to get around that?

jeffrifwald commented 8 years ago

I always run tests with babel-node instead of node, which manages the require hook automatically. I think it ultimately has to do with multiple processes and how istanbul handles those. What is your test command?

jonathanong commented 8 years ago

ah i c. i'm reluctant to use babel-node because it makes all the test commands a little more confusing, and i'd prefer to just one day remove the require hook vs. rewriting all the test commands.

currently, this is what i have, which worked until i used the node require hook.

{
  "scripts": {
    "test": "./bin/reseed && NODE_ENV=test mocha lib/__tests/index.js server/__tests/index.js",
    "test-cov": "./bin/reseed && NODE_ENV=test istanbul cover node_modules/mocha/bin/_mocha -- lib/__tests/index.js server/__tests/index.js"
  }
}

do you mind adding your test commands to the readme? that would be super helpful.

jonathanong commented 8 years ago

sidenote: would be nice if you did babel: '^6.0.0' as there are various bugs in 6.0 that were fixed in 6.1. https://github.com/ambitioninc/babel-istanbul/blob/c58405488ed18ca4fe2c72bf0fa403f6444a9f4e/package.json#L91

jeffrifwald commented 8 years ago

I'll bump babel. I haven't published any test commands because everyone is going to have a different setup. Each person needs to understand their test requirements and how each of the tools they use interact with each other. In this case, I believe it is impossible to use the require hook and istanbul in the way that you want because of how instabul works.

I think your command will work if you do something like this:

./bin/reseed && NODE_ENV=test babel-node node_modules/.bin/babel-istanbul cover node_modules/.bin/_mocha -- lib/__tests/index.js server/__tests/index.js
jonathanong commented 8 years ago

cool thanks