Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Option for excluding mappings #51

Open
otbe opened this issue Apr 29, 2016 · 3 comments
Open

Option for excluding mappings #51

otbe opened this issue Apr 29, 2016 · 3 comments

Comments

@otbe
Copy link

otbe commented Apr 29, 2016

Hi

let me explain what Im doing at the moment. I have a quite large electron app written in typescript. The only way to run tests for me in electron as a karma "browser" (at moment of writing) is to bundle all tests files. Im using webpack for this. This works great so far. Now I want to add coverage statistics to my test setup and remap-istanbul comes over the rainbow. Great tool so far. 👍

Passing the json output of karma-coverage to remap-istanbul produces the following html output:
bildschirmfoto 2016-04-29 um 16 26 02
The only entry thats interesting is src/utils/. The json generated by karma-coverage contains only one entry and this is my generated test bundle.

What I want to do is:
remap-istanbul --exclude-mapping=~/,tests/,webpack,__root__/
The generated html would only contain one entry for src/utils/

Is there a way to archive this?

Thank you :)

Another thought on this:
The generated json by remap-istanbul contains all files listed in the picture above. Can I execute a reporter based on this json? So it would be possible to "clean" the json from undesired files.

@kitsonk
Copy link
Contributor

kitsonk commented May 3, 2016

I suspect the remap-istanbul --exclude option is not sufficient?

I think what you are saying is that while you get one big bundle of original coverage, that breaks out into a load of other files when remapped, of which you are only interested in the subset, and because of your build pipeline and tooling, it isn't easy to not collect the coverage information in the first place.

@otbe
Copy link
Author

otbe commented May 3, 2016

Yes your assumptions are right.. remap-istanbul --exclude is not sufficient.

I found a working solution for me:

  1. create test.bundle.js with webpack
  2. create coverage with karma-coverage by using test.bundle.js > coverage-final.json
  3. run remap-istanbul and produce coverage-remapped.json
  4. execute the following script:
var istanbul = require('istanbul');
var collector = new istanbul.Collector();
var reporter = new istanbul.Reporter();

var remappedJson = require('./../generated/coverage-remapped.json');
var keys = Object.keys(remappedJson);
var coverage = {};

for (var i = 0; i < keys.length; i++) {
  if (keys[ i ].startsWith('src/')) {
    coverage[ keys[ i ] ] = remappedJson[ keys[ i ] ];
  }
}

collector.add(coverage);

reporter.add('html');
reporter.write(collector, true, function() {});

@kitsonk kitsonk added this to the 0.7.0 milestone May 3, 2016
@jas-chen
Copy link

jas-chen commented May 5, 2016

@otbe thanks for your solution, I added it to my project karma-sourcemap-writer. And it lets karma + webpack + babel work.

+1 for this feature!

@dylans dylans modified the milestones: 0.7.0, 0.8.0 Nov 1, 2016
@dylans dylans modified the milestones: 0.8.0, 0.9.0 Jan 11, 2017
@dylans dylans modified the milestones: 0.9.0, 0.10.0 Feb 22, 2017
@dylans dylans removed this from the 0.10.0 milestone Jan 11, 2018
@dylans dylans removed the question label Oct 27, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants