How to use istanbul-lib-coverage - 10 common examples

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 MarshallOfSound / Google-Play-Music-Desktop-Player-UNOFFICIAL- / test / istanbul-reporter.js View on Github external
runner.on('end', () => {
      const mainReporter = istanbulAPI.createReporter();
      const coverageMap = libCoverage.createCoverageMap();

      const JSONPath = path.resolve(__dirname, '..', 'coverage', 'coverage-final.json');
      const MainJSONPath = path.resolve(__dirname, '..', 'coverage', 'coverage-final-main.json');
      const RendererJSONPath = path.resolve(__dirname, '..', 'coverage', 'coverage-final-renderer.json');

      coverageMap.merge(global.__coverage__ || {});

      mainReporter.addAll(['json']);
      mainReporter.write(coverageMap, {});

      // node_modules\.bin\remap-istanbul -i coverage\coverage-final.json -o coverage\coverage-final.json -t json
      const JSONOutput = fs.readFileSync(JSONPath, 'utf8');
      const JSONObjectString = JSONOutput.replace(/"(.+?\.js)": /gi, (all, match) => `"${match.replace(/\\/g, '\\\\')}": `);
      const JSONObject = JSON.parse(JSONObjectString);
      Object.keys(JSONObject).forEach((JSONKey) => {
        if (/\/src\//g.test(JSONKey) || /\\src\\/g.test(JSONKey)) {
github DefinitelyTyped / DefinitelyTyped / types / istanbul-lib-coverage / istanbul-lib-coverage-tests.ts View on Github external
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();
summary1.merge(summary2);
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 DefinitelyTyped / DefinitelyTyped / types / istanbul-lib-coverage / istanbul-lib-coverage-tests.ts View on Github external
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();
summary1.merge(summary2);

// CoverageMap methods and properties
map1.addFileCoverage('foo.js');
map1.addFileCoverage(fileCoverageData);
map1.files()[0];
map1.fileCoverageFor('foo').path;
map1.filter(name => false);
map1.merge(map2);
map1.merge(coverageMapData);
github DefinitelyTyped / DefinitelyTyped / types / istanbul-lib-coverage / istanbul-lib-coverage-tests.ts View on Github external
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();
summary1.merge(summary2);

// CoverageMap methods and properties
map1.addFileCoverage('foo.js');
map1.addFileCoverage(fileCoverageData);
map1.files()[0];
map1.fileCoverageFor('foo').path;
map1.filter(name => false);
map1.merge(map2);
github DefinitelyTyped / DefinitelyTyped / types / istanbul-lib-coverage / istanbul-lib-coverage-tests.ts View on Github external
};

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();
summary1.merge(summary2);

// CoverageMap methods and properties
map1.addFileCoverage('foo.js');
map1.addFileCoverage(fileCoverageData);
map1.files()[0];
map1.fileCoverageFor('foo').path;
github DefinitelyTyped / DefinitelyTyped / types / istanbul-lib-source-maps / istanbul-lib-source-maps-tests.ts View on Github external
});

store.data['foo'].type.trim();

const sourceMap: RawSourceMap = {
	version: 1 as any as string, // Fixed by https://github.com/mozilla/source-map/pull/293 but the fix is not yet published
	sources: ['foo', 'bar'],
	names: ['foo', 'bar'],
	mappings: 'foo',
	file: 'foo'
};
store.registerMap('foo', sourceMap);

store.registerURL('foo', 'foo');

const map = new CoverageMap({});
const transformed = store.transformCoverage(map);
transformed.map.data;
transformed.sourceFinder('foo').trim();

store.dispose();

store.sourceStore.registerSource('foo', 'bar');
const source = store.sourceStore.getSource('foo');
if (source != null) {
	source.trim();
}
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 istanbuljs / istanbuljs / test / util / verifier.js View on Github external
import Instrumenter from '../../src/instrumenter';
import {classes} from 'istanbul-lib-coverage';
import {assert} from 'chai';
import clone from 'clone';
import readInitialCoverage from '../../src/read-coverage';

var FileCoverage = classes.FileCoverage;

function pad(str, len) {
    var blanks = '                                             ';
    if (str.length >= len) {
        return str;
    }
    return blanks.substring(0, len - str.length) + str;
}

function annotatedCode(code) {
    var codeArray = code.split('\n'),
        line = 0,
        annotated = codeArray.map(function (str) {
            line += 1;
            return pad(line, 6) + ': ' + str;
        });