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

I get coverage reports on browserify code #3

Open
michaelkantor opened this issue Sep 26, 2014 · 1 comment
Open

I get coverage reports on browserify code #3

michaelkantor opened this issue Sep 26, 2014 · 1 comment

Comments

@michaelkantor
Copy link

Hi, this has been very useful. I do have on issue that if others are seeing, would be nice to have addressed: I get a coverage report such as:

coverage/ | 82.15 | 58.46 | 80.36 | 74.45 |
mybrowserified.js | 82.15 | 58.46 | 80.36 | 74.45 |
mylib/js/ | 94.75 | 81.21 | 95.74 | 96.28 |
file1.js | 100 | 100 | 100 | 100 |
file2.js | 90.57 | 90 | 86.96 | 90.2 |
.....
I want to run istanbul on file1.js and file2.js, not on the code added by the browserify process. According to the report above, my files have 81% statement coverage, but after adding in the browserify code, its only 58%. Which then throws errors in my system for terrible coverage.

@michaelkantor
Copy link
Author

I tried this out... not really a grunt developer though, so might be worth having someone sanity check that this is worth having. Two changes:

  1. checkThresholds now supports an ignoreFiles array
  2. The call to checkThresholds now passes the entire options object and not options.thresholds

Using an options that contains: {ignoreFiles: ["coverage/mybrowserified.js"]} it now just reports on the other files.

if (context.options.thresholds) {
    checkThresholds(collector, context.options);  // Was context.options.threshold
}

....

var checkThresholds = function (collector, options) {
var summaries = [];

    // CHANGES START HERE
var thresholds = options.thresholds;
var ignoreFiles = options.ignoreFiles;
var files = collector.files().filter(function (file) {
    return (!ignoreFiles || ignoreFiles.indexOf(file) == -1);
});

files.forEach(function(file) {
    summaries.push(istanbul.utils.summarizeFileCoverage(
            collector.fileCoverageFor(file)));
});
   // CHANGES END HERE

var finalSummary = istanbul.utils.mergeSummaryObjects.apply(null,
        summaries);
grunt.util._.each(thresholds, function (threshold, metric) {
    var actual = finalSummary[metric];
    if(!actual) {
        grunt.warn('unrecognized metric: ' + metric);
    }
    if(actual.pct < threshold) {
        grunt.warn('expected ' + metric + ' coverage to be at least '
                + threshold + '% but was ' + actual.pct + '%');
    }
});
};

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant