bcoe / c8

output coverage reports using Node.js' built in coverage
ISC License
2k stars 91 forks source link

Running with karma #175

Open benmccann opened 4 years ago

benmccann commented 4 years ago

Is it possible to use c8 with karma? The repo I'm trying against is https://github.com/chartjs/Chart.js. It shows me coverage of the test setup files, but not the actual source code and I'm not quite sure how to address.

$ c8 npx karma start
-------------------|----------|----------|----------|----------|-------------------|
File               |  % Stmts | % Branch |  % Funcs |  % Lines | Uncovered Line #s |
-------------------|----------|----------|----------|----------|-------------------|
All files          |    92.16 |    53.85 |      100 |    92.16 |                   |
 karma.conf.js     |    95.74 |       50 |      100 |    95.74 |       18,19,92,93 |
 rollup.plugins.js |    89.09 |       55 |      100 |    89.09 |... 45,89,90,95,96 |
-------------------|----------|----------|----------|----------|-------------------|
j03m commented 4 years ago

I believe c8 is not currently set up to do this. Right now we expect that v8 coverage data is dumped to some interim directory (in this case by nodejs). From there we slurp up that data and transform it into something that istanbul reporters can consume.

In the case of Karma, the value proposition is that the actual tests and thus the coverage data you really want are being executed inside of a real browser. However, there is nothing to my knowledge that will signal the browser to dump the coverage data to a tmp directory.

I believe the results you are seeing are the js files being loaded by karma itself by node.

**Edit to add - After a quick check it looks like you can manually have chrome export the raw coverage.json files. This is supported by protocol.json and therefore is potentially something we could do. But the feature would need design etc.

CC: @bcoe for comment since I'm pretty new to the project myself.