How to use the nyc/node_modules/istanbul-lib-coverage.createCoverageMap function in nyc

To help you get started, we’ve selected a few nyc 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 blackflux / js-gardener / lib / subtasks / nyc.js View on Github external
nyc.reset();
  if (wrap) {
    nyc.wrap();
  }
  testFilesAbs.forEach((f) => {
    safeDeleteCache(f);
    mocha.addFile(f);
  });
  srcFilesAbs.forEach((f) => {
    logger.info(`Loading ${f}`);
    // eslint-disable-next-line global-require, import/no-dynamic-require
    require(`${f}`);
  });

  // eslint-disable-next-line no-underscore-dangle
  const coverageSaved = libCoverage.createCoverageMap(global.__coverage__);
  let success = true;
  const runner = mocha.run((failures) => {
    success = success && failures === 0;
  });
  runner.on('end', () => {
    nyc.writeCoverageFile();
    nyc.report();
    nyc.checkCoverage({
      lines: 100,
      statements: 100,
      functions: 100,
      branches: 100
    }, false);
    /* eslint-disable no-underscore-dangle */
    coverageSaved.merge(global.__coverage__);
    global.__coverage__ = coverageSaved.toJSON();
github SSENSE / node-cucumber-testrail-sync / tests / coverage / merge.js View on Github external
libCoverage = require('nyc/node_modules/istanbul-lib-coverage'),
    libReport = require('nyc/node_modules/istanbul-lib-report'),
    reports = require('nyc/node_modules/istanbul-reports');

var rootFolder = __dirname;
var mergeIntoFolder = 'final';
var files = fs.readdirSync(rootFolder);
var mergedCoverageMap = null;

for (var i = 0; i < files.length; i++) {
    var fullPath = path.resolve(rootFolder, files[i]);

    if (files[i] !== mergeIntoFolder && fs.statSync(fullPath).isDirectory()) {
        fullPath = path.resolve(fullPath, 'coverage-final.json');

        var map = libCoverage.createCoverageMap(JSON.parse(fs.readFileSync(fullPath, 'utf8')));
        if (mergedCoverageMap !== null) {
            mergedCoverageMap.merge(map);
        }
        else {
            mergedCoverageMap = map;
        }
    }
}

if (mergedCoverageMap === null) {
    console.warn('Warning: No cover files to be merged');
    return;
}

var context = libReport.createContext({
    dir: path.join(rootFolder, mergeIntoFolder)