all files / src/ remap.js

100% Statements 7/7
100% Branches 4/4
100% Functions 2/2
100% Lines 6/6
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33                                          15× 15×   15× 13×     13×      
const { CoverageTransformer } = require('./CoverageTransformer');
 
/**
 * Remaps coverage data based on the source maps it discovers in the
 * covered files and returns a coverage Collector that contains the remappped
 * data.
 * @param  {Array|Object} coverage The coverage (or array of coverages) that need to be
 *                                                 remapped
 * @param  {Object} options A configuration object:
 *       exclude?  - a string or Regular Expression that filters out
 *                   any coverage where the file path matches
 *       readFile? - a function that can read a file
 *                   syncronously
 *       readJSON? - a function that can read and parse a
 *                   JSON file syncronously
 *       sources?  - a Istanbul store where inline sources will be
 *                   added
 *       warn?     - a function that logs warnings
 * @return {Object}         The remapped collector
 */
 
function remap(coverage, options = {}) {
  const smc = new CoverageTransformer(options);
 
  coverage.forEach(item => {
    smc.addCoverage(item);
  });
 
  return smc.getFinalCoverage();
}
 
module.exports = remap;