Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

istanbul-lib-coverage

Package Overview
Dependencies
Maintainers
3
Versions
29
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

istanbul-lib-coverage - npm Package Compare versions

Comparing version 2.0.3 to 2.0.4

8

CHANGELOG.md

@@ -6,2 +6,10 @@ # Change Log

## [2.0.4](https://github.com/istanbuljs/istanbuljs/compare/istanbul-lib-coverage@2.0.3...istanbul-lib-coverage@2.0.4) (2019-03-12)
**Note:** Version bump only for package istanbul-lib-coverage
## [2.0.3](https://github.com/istanbuljs/istanbuljs/compare/istanbul-lib-coverage@2.0.2...istanbul-lib-coverage@2.0.3) (2019-01-26)

@@ -8,0 +16,0 @@

14

index.js

@@ -15,5 +15,5 @@ /*

*/
var CoverageSummary = require('./lib/file').CoverageSummary,
FileCoverage = require('./lib/file').FileCoverage,
CoverageMap = require('./lib/coverage-map').CoverageMap;
const CoverageSummary = require('./lib/file').CoverageSummary;
const FileCoverage = require('./lib/file').FileCoverage;
const CoverageMap = require('./lib/coverage-map').CoverageMap;

@@ -27,3 +27,3 @@ module.exports = {

*/
createCoverageSummary: function(obj) {
createCoverageSummary(obj) {
if (obj && obj instanceof CoverageSummary) {

@@ -40,3 +40,3 @@ return obj;

*/
createCoverageMap: function(obj) {
createCoverageMap(obj) {
if (obj && obj instanceof CoverageMap) {

@@ -53,3 +53,3 @@ return obj;

*/
createFileCoverage: function(obj) {
createFileCoverage(obj) {
if (obj && obj instanceof FileCoverage) {

@@ -67,3 +67,3 @@ return obj;

*/
FileCoverage: FileCoverage
FileCoverage
};

@@ -7,9 +7,9 @@ /*

var FileCoverage = require('./file').FileCoverage,
CoverageSummary = require('./file').CoverageSummary;
const FileCoverage = require('./file').FileCoverage;
const CoverageSummary = require('./file').CoverageSummary;
function loadMap(source) {
var data = Object.create(null);
Object.keys(source).forEach(function(k) {
var cov = source[k];
const data = Object.create(null);
Object.keys(source).forEach(k => {
const cov = source[k];
if (cov instanceof FileCoverage) {

@@ -45,4 +45,3 @@ data[k] = cov;

CoverageMap.prototype.merge = function(obj) {
var that = this,
other;
let other;
if (obj instanceof CoverageMap) {

@@ -53,8 +52,8 @@ other = obj;

}
Object.keys(other.data).forEach(function(k) {
var fc = other.data[k];
if (that.data[k]) {
that.data[k].merge(fc);
Object.keys(other.data).forEach(k => {
const fc = other.data[k];
if (this.data[k]) {
this.data[k].merge(fc);
} else {
that.data[k] = fc;
this.data[k] = fc;
}

@@ -70,6 +69,5 @@ });

CoverageMap.prototype.filter = function(callback) {
var that = this;
Object.keys(that.data).forEach(function(k) {
Object.keys(this.data).forEach(k => {
if (!callback(k)) {
delete that.data[k];
delete this.data[k];
}

@@ -98,3 +96,3 @@ });

CoverageMap.prototype.fileCoverageFor = function(file) {
var fc = this.data[file];
const fc = this.data[file];
if (!fc) {

@@ -112,4 +110,4 @@ throw new Error('No file coverage available for: ' + file);

CoverageMap.prototype.addFileCoverage = function(fc) {
var cov = new FileCoverage(fc),
path = cov.path;
const cov = new FileCoverage(fc);
const path = cov.path;
if (this.data[path]) {

@@ -126,6 +124,5 @@ this.data[path].merge(cov);

CoverageMap.prototype.getCoverageSummary = function() {
var that = this,
ret = new CoverageSummary();
this.files().forEach(function(key) {
ret.merge(that.fileCoverageFor(key).toSummary());
const ret = new CoverageSummary();
this.files().forEach(key => {
ret.merge(this.fileCoverageFor(key).toSummary());
});

@@ -136,3 +133,3 @@ return ret;

module.exports = {
CoverageMap: CoverageMap
CoverageMap
};

@@ -8,3 +8,3 @@ /*

function percent(covered, total) {
var tmp;
let tmp;
if (total > 0) {

@@ -19,3 +19,3 @@ tmp = (1000 * 100 * covered) / total + 5;

function blankSummary() {
var empty = function() {
const empty = function() {
return {

@@ -38,3 +38,3 @@ total: 0,

function assertValidSummary(obj) {
var valid =
const valid =
obj && obj.lines && obj.statements && obj.functions && obj.branches;

@@ -68,6 +68,6 @@ if (!valid) {

['lines', 'statements', 'functions', 'branches'].forEach(function(p) {
['lines', 'statements', 'functions', 'branches'].forEach(p => {
Object.defineProperty(CoverageSummary.prototype, p, {
enumerable: true,
get: function() {
get() {
return this.data[p];

@@ -83,9 +83,8 @@ }

CoverageSummary.prototype.merge = function(obj) {
var that = this,
keys = ['lines', 'statements', 'branches', 'functions'];
keys.forEach(function(key) {
that[key].total += obj[key].total;
that[key].covered += obj[key].covered;
that[key].skipped += obj[key].skipped;
that[key].pct = percent(that[key].covered, that[key].total);
const keys = ['lines', 'statements', 'branches', 'functions'];
keys.forEach(key => {
this[key].total += obj[key].total;
this[key].covered += obj[key].covered;
this[key].skipped += obj[key].skipped;
this[key].pct = percent(this[key].covered, this[key].total);
});

@@ -124,3 +123,3 @@ return this;

function assertValidObject(obj) {
var valid =
const valid =
obj &&

@@ -181,13 +180,13 @@ obj.path &&

FileCoverage.prototype.getLineCoverage = function() {
var statementMap = this.data.statementMap,
statements = this.data.s,
lineMap = Object.create(null);
const statementMap = this.data.statementMap;
const statements = this.data.s;
const lineMap = Object.create(null);
Object.keys(statements).forEach(function(st) {
Object.keys(statements).forEach(st => {
if (!statementMap[st]) {
return;
}
var line = statementMap[st].start.line,
count = statements[st],
prevVal = lineMap[line];
const line = statementMap[st].start.line;
const count = statements[st];
const prevVal = lineMap[line];
if (prevVal === undefined || prevVal < count) {

@@ -205,6 +204,6 @@ lineMap[line] = count;

FileCoverage.prototype.getUncoveredLines = function() {
var lc = this.getLineCoverage(),
ret = [];
Object.keys(lc).forEach(function(l) {
var hits = lc[l];
const lc = this.getLineCoverage();
const ret = [];
Object.keys(lc).forEach(l => {
const hits = lc[l];
if (hits === 0) {

@@ -222,21 +221,19 @@ ret.push(l);

FileCoverage.prototype.getBranchCoverageByLine = function() {
var branchMap = this.branchMap,
branches = this.b,
ret = {};
Object.keys(branchMap).forEach(function(k) {
var line = branchMap[k].line || branchMap[k].loc.start.line,
branchData = branches[k];
const branchMap = this.branchMap;
const branches = this.b;
const ret = {};
Object.keys(branchMap).forEach(k => {
const line = branchMap[k].line || branchMap[k].loc.start.line;
const branchData = branches[k];
ret[line] = ret[line] || [];
ret[line].push.apply(ret[line], branchData);
ret[line].push(...branchData);
});
Object.keys(ret).forEach(function(k) {
var dataArray = ret[k],
covered = dataArray.filter(function(item) {
return item > 0;
}),
coverage = (covered.length / dataArray.length) * 100;
Object.keys(ret).forEach(k => {
const dataArray = ret[k];
const covered = dataArray.filter(item => item > 0);
const coverage = (covered.length / dataArray.length) * 100;
ret[k] = {
covered: covered.length,
total: dataArray.length,
coverage: coverage
coverage
};

@@ -248,8 +245,6 @@ });

// expose coverage data attributes
['path', 'statementMap', 'fnMap', 'branchMap', 's', 'f', 'b'].forEach(function(
p
) {
['path', 'statementMap', 'fnMap', 'branchMap', 's', 'f', 'b'].forEach(p => {
Object.defineProperty(FileCoverage.prototype, p, {
enumerable: true,
get: function() {
get() {
return this.data[p];

@@ -271,15 +266,14 @@ }

FileCoverage.prototype.merge = function(other) {
var that = this;
Object.keys(other.s).forEach(function(k) {
that.data.s[k] += other.s[k];
Object.keys(other.s).forEach(k => {
this.data.s[k] += other.s[k];
});
Object.keys(other.f).forEach(function(k) {
that.data.f[k] += other.f[k];
Object.keys(other.f).forEach(k => {
this.data.f[k] += other.f[k];
});
Object.keys(other.b).forEach(function(k) {
var i,
retArray = that.data.b[k],
secondArray = other.b[k];
Object.keys(other.b).forEach(k => {
let i;
const retArray = this.data.b[k];
const secondArray = other.b[k];
if (!retArray) {
that.data.b[k] = secondArray;
this.data.b[k] = secondArray;
return;

@@ -294,4 +288,4 @@ }

FileCoverage.prototype.computeSimpleTotals = function(property) {
var stats = this[property],
ret = { total: 0, covered: 0, skipped: 0 };
let stats = this[property];
const ret = { total: 0, covered: 0, skipped: 0 };

@@ -301,4 +295,4 @@ if (typeof stats === 'function') {

}
Object.keys(stats).forEach(function(key) {
var covered = !!stats[key];
Object.keys(stats).forEach(key => {
const covered = !!stats[key];
ret.total += 1;

@@ -314,9 +308,9 @@ if (covered) {

FileCoverage.prototype.computeBranchTotals = function() {
var stats = this.b,
ret = { total: 0, covered: 0, skipped: 0 };
const stats = this.b;
const ret = { total: 0, covered: 0, skipped: 0 };
Object.keys(stats).forEach(function(key) {
var branches = stats[key],
covered;
branches.forEach(function(branchHits) {
Object.keys(stats).forEach(key => {
const branches = stats[key];
let covered;
branches.forEach(branchHits => {
covered = branchHits > 0;

@@ -337,16 +331,14 @@ if (covered) {

FileCoverage.prototype.resetHits = function() {
var statements = this.s,
functions = this.f,
branches = this.b;
Object.keys(statements).forEach(function(s) {
const statements = this.s;
const functions = this.f;
const branches = this.b;
Object.keys(statements).forEach(s => {
statements[s] = 0;
});
Object.keys(functions).forEach(function(f) {
Object.keys(functions).forEach(f => {
functions[f] = 0;
});
Object.keys(branches).forEach(function(b) {
var hits = branches[b];
branches[b] = hits.map(function() {
return 0;
});
Object.keys(branches).forEach(b => {
const hits = branches[b];
branches[b] = hits.map(() => 0);
});

@@ -360,3 +352,3 @@ };

FileCoverage.prototype.toSummary = function() {
var ret = {};
const ret = {};
ret.lines = this.computeSimpleTotals('getLineCoverage');

@@ -370,4 +362,4 @@ ret.functions = this.computeSimpleTotals('f', 'fnMap');

module.exports = {
CoverageSummary: CoverageSummary,
FileCoverage: FileCoverage
CoverageSummary,
FileCoverage
};
{
"name": "istanbul-lib-coverage",
"version": "2.0.3",
"version": "2.0.4",
"description": "Data library for istanbul coverage objects",

@@ -37,7 +37,7 @@ "author": "Krishnan Anantheswaran <kananthmail-github@yahoo.com>",

},
"homepage": "https://github.com/istanbuljs/istanbuljs",
"homepage": "https://istanbul.js.org/",
"engines": {
"node": ">=6"
},
"gitHead": "7875defdc3c3640787ac5d83700246de119e8b83"
"gitHead": "c81b051d83217947dfd97d8d06532bd5013e98c3"
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc