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

Recommended way to strip flow type annotations from tests? #74

Closed mynameistechno closed 8 years ago

mynameistechno commented 8 years ago

Hi there. We want to use flow type annotations in our tests and it appears as if these don't get stripped out before running cover. We use the babel plugin babel-plugin-transform-flow-strip-types to strip them from source/tests, but when running babel-istanbul seems like it only strips it from the source files. This is our .babelrc e.g.

{ "presets": ["es2015"],
  "plugins": ["transform-flow-strip-types"]
}

For the tests we use babel-tape-runner, and that strips out from both source/tests. Am i doing something wrong? Is there a recommended way to address it? If there isn't I'll just add a step that strips them from the test files before running them though babel-istanbul. Thanks!

jeffrifwald commented 8 years ago

By default, istanbul ignores the test directory.

https://github.com/gotwarlost/istanbul/blob/ad8ab1d7a5284407efb83d0d7a8b32eb6fbd93c4/test/cli-helper.js#L11

My initial thought is that your test directory is called test and istanbul is ignoring it, so babel-istanbul never knows about it. Can you try to set up custom excludes in your .istanbul.yml file or changing the name of the test directory and see if that fixes the issue?

mynameistechno commented 8 years ago

Good call. This works although now the test files are included in the coverage report which is not ideal. Is there a way to exclude them from the report? If not, no worries. Thanks for your help.

jeffrifwald commented 8 years ago

I'm not sure how babel-tape-runner works, but I usually run tests with babel-node instead of node. That ensures the tests are being compiled and istanbul doesn't need to know.

Besides that, I think your only options are to precompile or deal with tests in the coverage report.