How to use the istanbul-lib-coverage.createCoverageSummary function in istanbul-lib-coverage

To help you get started, we’ve selected a few istanbul-lib-coverage examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github DefinitelyTyped / DefinitelyTyped / types / istanbul-lib-coverage / istanbul-lib-coverage-tests.ts View on Github external
path: 'foo',
	statementMap: {},
	fnMap: {},
	branchMap: {},
	s: {},
	f: {},
	b: {}
};

const summary1 = createCoverageSummary(summaryData);
summary1.data;
summary1.branches;
summary1.lines;
summary1.functions;
summary1.statements;
const summary2 = createCoverageSummary(summary1);

const map1 = createCoverageMap(coverageMapData);
map1.data;
const map2 = createCoverageMap(map1);
map2.data;

const fileCoverage1 = createFileCoverage('path/to/foo');
fileCoverage1.data;
const fileCoverage2 = createFileCoverage(fileCoverage1.data);
fileCoverage2.data;
const fileCoverage3 = createFileCoverage(fileCoverageData);
fileCoverage3.data;

// CoverageSummary methods and properties
summary1.isEmpty();
summary1.toJSON();
github vivlabs / coverage-github-reporter / src / coverage / parse.js View on Github external
exports.coverageJsonToReport = function (json, base) {
  const map = libCoverage.createCoverageMap(json)
  const globalSummary = libCoverage.createCoverageSummary()

  const report = { '*': {} }

  const summaries = {}
  let commonRoot

  // inspect and summarize all file coverage objects in the map
  for (const file of map.files()) {
    const folder = relative(base, dirname(file)) + '/'
    const path = new Path(folder)
    commonRoot = commonRoot ? commonRoot.commonPrefixPath(path) : path

    if (!summaries[folder]) {
      summaries[folder] = libCoverage.createCoverageSummary()
      report[folder] = { files: {} }
    }
github vivlabs / coverage-github-reporter / src / coverage / parse.js View on Github external
const map = libCoverage.createCoverageMap(json)
  const globalSummary = libCoverage.createCoverageSummary()

  const report = { '*': {} }

  const summaries = {}
  let commonRoot

  // inspect and summarize all file coverage objects in the map
  for (const file of map.files()) {
    const folder = relative(base, dirname(file)) + '/'
    const path = new Path(folder)
    commonRoot = commonRoot ? commonRoot.commonPrefixPath(path) : path

    if (!summaries[folder]) {
      summaries[folder] = libCoverage.createCoverageSummary()
      report[folder] = { files: {} }
    }
    const fileSummary = map.fileCoverageFor(file).toSummary()
    globalSummary.merge(fileSummary)
    summaries[folder].merge(fileSummary)

    report[folder].files[basename(file)] = getSimpleCoverage(fileSummary)
  }
  report['*'] = getSimpleCoverage(globalSummary)

  const folders = Object.keys(summaries)

  while (folders.length > 1 && summaries[commonRoot.toString() + '/']) {
    commonRoot = commonRoot.parent()
  }
github DefinitelyTyped / DefinitelyTyped / types / istanbul-lib-coverage / istanbul-lib-coverage-tests.ts View on Github external
branches: { total: 0, covered: 0, skipped: 0, pct: 0 }
};

const coverageMapData: CoverageMapData = {};

const fileCoverageData: FileCoverageData = {
	path: 'foo',
	statementMap: {},
	fnMap: {},
	branchMap: {},
	s: {},
	f: {},
	b: {}
};

const summary1 = createCoverageSummary(summaryData);
summary1.data;
summary1.branches;
summary1.lines;
summary1.functions;
summary1.statements;
const summary2 = createCoverageSummary(summary1);

const map1 = createCoverageMap(coverageMapData);
map1.data;
const map2 = createCoverageMap(map1);
map2.data;

const fileCoverage1 = createFileCoverage('path/to/foo');
fileCoverage1.data;
const fileCoverage2 = createFileCoverage(fileCoverage1.data);
fileCoverage2.data;
github zordius / gulp-jsx-coverage / index.js View on Github external
}

            if (!covCfg.reporters || !covCfg.reporters.forEach) {
                this.emit('error', new (require('gulp-util').PluginError)({
                    plugin: pluginName,
                    message: 'Bad config! Check your options.coverage.reports, it should be an array.'
                }));
            }

            context = report.createContext({
                dir: covCfg.directory
            });
            map = coverage.createCoverageMap(global[coverageVariable]);
            tree = report.summarizers.pkg(map);

            finalSummary = coverage.createCoverageSummary();

            map.files().forEach(function (F) {
                finalSummary.merge(map.fileCoverageFor(F).toSummary());
            });

            covCfg.reporters.forEach(function (R) {
                try {
                    tree.visit(reporters.create(R), context);
                } catch (E) {
                    this.emit('error', new (require('gulp-util').PluginError)({
                        plugin: pluginName,
                        message: 'ERROR when generate instanbul report ' + R + ':' + E.message
                    }));
                }
            });
github karma-runner / karma-coverage / lib / reporter.js View on Github external
},
      each: {
        statements: 0,
        branches: 0,
        lines: 0,
        functions: 0,
        excludes: [],
        overrides: {}
      }
    }

    var thresholds = helper.merge({}, defaultThresholds, config.check)

    var globalTrackedFiles = getTrackedFiles(coverageMap, thresholds.global.excludes)
    var eachTrackedFiles = getTrackedFiles(coverageMap, thresholds.each.excludes)
    var globalResults = istanbulLibCoverage.createCoverageSummary()
    var eachResults = {}
    globalTrackedFiles.forEach(function (f) {
      var fileCoverage = coverageMap.fileCoverageFor(f)
      var summary = fileCoverage.toSummary()
      globalResults.merge(summary)
    })
    eachTrackedFiles.forEach(function (f) {
      var fileCoverage = coverageMap.fileCoverageFor(f)
      var summary = fileCoverage.toSummary()
      eachResults[f] = summary
    })

    var coverageFailed = false

    function check (name, thresholds, actuals) {
      var keys = [
github istanbuljs / istanbuljs / packages / istanbul-lib-report / lib / summarizer-factory.js View on Github external
getCoverageSummary(filesOnly) {
        const cacheProp = `c_${filesOnly ? 'files' : 'full'}`;
        let summary;

        if (Object.prototype.hasOwnProperty.call(this, cacheProp)) {
            return this[cacheProp];
        }

        if (!this.isSummary()) {
            summary = this.getFileCoverage().toSummary();
        } else {
            let count = 0;
            summary = coverage.createCoverageSummary();
            this.getChildren().forEach(child => {
                if (filesOnly && child.isSummary()) {
                    return;
                }
                count += 1;
                summary.merge(child.getCoverageSummary(filesOnly));
            });
            if (count === 0 && filesOnly) {
                summary = null;
            }
        }
        this[cacheProp] = summary;
        return summary;
    }
}
github monounity / karma-typescript / packages / karma-typescript / src / istanbul / threshold.ts View on Github external
if (threshold < 0 && threshold * -1 < uncovered) {
                    passedThreshold = false;
                    this.log.error("%s: Expected max %s uncovered %s, got %s (%s)",
                        browser.name, (-1 * threshold), key, uncovered, name);
                }
                else if (result.pct < threshold) {
                    passedThreshold = false;
                    this.log.error("%s: Expected %s% coverage for %s, got %s% (%s)",
                        browser.name, threshold, key, result.pct, name);
                }
            });
        };

        const thresholdConfig = this.config.coverageOptions.threshold;
        const globalSummary = istanbulCoverage.createCoverageSummary();
        const globalSummaries = this.toSummaries(coverageMap, thresholdConfig.global.excludes);
        const fileSummaries = this.toSummaries(coverageMap, thresholdConfig.file.excludes);

        Object.keys(globalSummaries).forEach((filename) => {
            globalSummary.merge(globalSummaries[filename]);
        });

        checkThresholds("global", thresholdConfig.global, globalSummary);

        Object.keys(fileSummaries).forEach((filename) => {
            const relativeFilename = FileUtils.getRelativePath(filename, this.config.karma.basePath);
            const thresholds = merge(thresholdConfig.file, this.getFileOverrides(relativeFilename));
            checkThresholds(filename, thresholds, fileSummaries[filename]);
        });

        return passedThreshold;