aboutsummaryrefslogtreecommitdiff
path: root/node_modules/istanbul-lib-coverage/lib/coverage-summary.js
diff options
context:
space:
mode:
authorJoel Kronqvist <work.joelkronqvist@pm.me>2022-03-11 20:46:06 +0200
committerJoel Kronqvist <work.joelkronqvist@pm.me>2022-03-11 20:46:06 +0200
commit080c5819d87b933816d724a83f3bf4f1686770a7 (patch)
tree4a2ccc68b27edf7d4cbc586c932cc7542b655e19 /node_modules/istanbul-lib-coverage/lib/coverage-summary.js
parent5ac7049a9d30733165cc212dee308163c2a14644 (diff)
parentd003b82235a9329f912522a2f70aa950dfce4998 (diff)
downloadLYLLRuoka-080c5819d87b933816d724a83f3bf4f1686770a7.tar.gz
LYLLRuoka-080c5819d87b933816d724a83f3bf4f1686770a7.zip
Merge branch 'master' of https://github.com/JoelHMikael/FoodJS
Updating remote changes
Diffstat (limited to 'node_modules/istanbul-lib-coverage/lib/coverage-summary.js')
-rw-r--r--node_modules/istanbul-lib-coverage/lib/coverage-summary.js112
1 files changed, 112 insertions, 0 deletions
diff --git a/node_modules/istanbul-lib-coverage/lib/coverage-summary.js b/node_modules/istanbul-lib-coverage/lib/coverage-summary.js
new file mode 100644
index 0000000..9b769c6
--- /dev/null
+++ b/node_modules/istanbul-lib-coverage/lib/coverage-summary.js
@@ -0,0 +1,112 @@
+/*
+ Copyright 2012-2015, Yahoo Inc.
+ Copyrights licensed under the New BSD License. See the accompanying LICENSE file for terms.
+ */
+'use strict';
+
+const percent = require('./percent');
+const dataProperties = require('./data-properties');
+
+function blankSummary() {
+ const empty = () => ({
+ total: 0,
+ covered: 0,
+ skipped: 0,
+ pct: 'Unknown'
+ });
+
+ return {
+ lines: empty(),
+ statements: empty(),
+ functions: empty(),
+ branches: empty(),
+ branchesTrue: empty()
+ };
+}
+
+// asserts that a data object "looks like" a summary coverage object
+function assertValidSummary(obj) {
+ const valid =
+ obj && obj.lines && obj.statements && obj.functions && obj.branches;
+ if (!valid) {
+ throw new Error(
+ 'Invalid summary coverage object, missing keys, found:' +
+ Object.keys(obj).join(',')
+ );
+ }
+}
+
+/**
+ * CoverageSummary provides a summary of code coverage . It exposes 4 properties,
+ * `lines`, `statements`, `branches`, and `functions`. Each of these properties
+ * is an object that has 4 keys `total`, `covered`, `skipped` and `pct`.
+ * `pct` is a percentage number (0-100).
+ */
+class CoverageSummary {
+ /**
+ * @constructor
+ * @param {Object|CoverageSummary} [obj=undefined] an optional data object or
+ * another coverage summary to initialize this object with.
+ */
+ constructor(obj) {
+ if (!obj) {
+ this.data = blankSummary();
+ } else if (obj instanceof CoverageSummary) {
+ this.data = obj.data;
+ } else {
+ this.data = obj;
+ }
+ assertValidSummary(this.data);
+ }
+
+ /**
+ * merges a second summary coverage object into this one
+ * @param {CoverageSummary} obj - another coverage summary object
+ */
+ merge(obj) {
+ const keys = [
+ 'lines',
+ 'statements',
+ 'branches',
+ 'functions',
+ 'branchesTrue'
+ ];
+ keys.forEach(key => {
+ if (obj[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);
+ }
+ });
+
+ return this;
+ }
+
+ /**
+ * returns a POJO that is JSON serializable. May be used to get the raw
+ * summary object.
+ */
+ toJSON() {
+ return this.data;
+ }
+
+ /**
+ * return true if summary has no lines of code
+ */
+ isEmpty() {
+ return this.lines.total === 0;
+ }
+}
+
+dataProperties(CoverageSummary, [
+ 'lines',
+ 'statements',
+ 'functions',
+ 'branches',
+ 'branchesTrue'
+]);
+
+module.exports = {
+ CoverageSummary
+};