How to use the istanbul-lib-coverage.createCoverageMap 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 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 nextapps-de / mikado / test / merge-coverage.js View on Github external
const libCoverage = require('istanbul-lib-coverage');
const { createReporter } = require('istanbul-api');

const coverage_1 = require('./.nyc_output/coverage.json');
const coverage_2 = require('./.nyc_output/coverage2.json');

const normalizeJestCoverage = (obj) => {
  const result = obj;
  Object.entries(result).forEach(([k, v]) => {
    if (v.data) result[k] = v.data;
  });
  return result;
};

const map = libCoverage.createCoverageMap();
map.merge(normalizeJestCoverage(coverage_1));
map.merge(normalizeJestCoverage(coverage_2));

const reporter = createReporter();
reporter.addAll(['html', 'json', 'lcov', 'text']);
reporter.write(map);
github xwp / wp-foo-bar / tests / merge-coverage.js View on Github external
async function main() {
	const coverageMap = istanbulCoverage.createCoverageMap( {} );

	const reports = [ rootDir + '/e2e/coverage-final.json' ];

	if ( false !== args.js ) {
		reports.push( rootDir + '/js/coverage-final.json' );
	}

	if ( Array.isArray( reports ) ) {
		mergeAllReports( coverageMap, reports );
		generateReport( coverageMap, args.reporter || 'lcov' );
	}
}
github artsy / positron / scripts / normalize-jest-coverage.js View on Github external
const libCoverage = require("istanbul-lib-coverage")
const { createReporter } = require("istanbul-api")
const fs = require("fs")
const path = require("path")

const normalizeJestCoverage = result => {
  Object.entries(result).forEach(([k, v]) => {
    if (v.data) result[k] = v.data
  })

  return result
}

const map = libCoverage.createCoverageMap()
const jestCoverage = require("../.nyc_output/coverage-final.json")

map.merge(normalizeJestCoverage(jestCoverage))

const reporter = createReporter()
reporter.addAll(["json"])
reporter.write(map)

fs.copyFile(
  "./coverage/coverage-final.json",
  "./.nyc_output/coverage-final.json",
  error => error && console.log(error)
)
github istanbuljs / nyc / lib / source-maps.js View on Github external
async remapCoverage (obj) {
    const transformed = await this._sourceMapCache.transformCoverage(
      libCoverage.createCoverageMap(obj)
    )
    return transformed.data
  }
github istanbuljs / istanbuljs / packages / istanbul-api / lib / run-reports.js View on Github external
function run(formats, config, opts, callback) {
    if (!callback && typeof opts === 'function') {
        callback = opts;
        opts = {};
    }
    opts = opts || {};
    const coverageMap = libCoverage.createCoverageMap();
    const includePattern = opts.include || '**/coverage*.raw.json';
    const reporter = new Reporter(config);

    if (!formats || formats.length === 0) {
        formats = config.reporting.reports();
    }
    try {
        reporter.addAll(formats);
    } catch (ex) {
        ex.inputError = true;
        return callback(ex);
    }

    const root = opts.root || process.cwd();
    filesFor(
        {
github cypress-io / code-coverage / task.js View on Github external
combineCoverage (coverage) {
    fixSourcePathes(coverage)
    const previous = existsSync(nycFilename)
      ? JSON.parse(readFileSync(nycFilename))
      : istanbul.createCoverageMap({})
    const coverageMap = istanbul.createCoverageMap(previous)
    coverageMap.merge(coverage)
    saveCoverage(coverageMap)
    debug('wrote coverage file %s', nycFilename)

    return null
  },
github chialab / rna-cli / commands / unit / action.js View on Github external
server.on('run_start', () => {
                    reportMap = require('istanbul-lib-coverage').createCoverageMap({});
                });
                server.on('coverage_complete', (browser, coverageReport) => {