Skip to content

Commit

Permalink
show pass percent
Browse files Browse the repository at this point in the history
  • Loading branch information
UziTech committed Apr 9, 2019
1 parent ba1de1e commit 0ac3c48
Showing 1 changed file with 23 additions and 3 deletions.
26 changes: 23 additions & 3 deletions test/specs/run-spec.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,35 @@
function runSpecs(title, file, options) {
const json = require(file);
let longestName = 0;
let maxSpecs = 0;
const specs = json.reduce((obj, spec) => {
if (!obj[spec.section]) {
obj[spec.section] = [];
longestName = Math.max(spec.section.length, longestName);
obj[spec.section] = {
specs: [],
pass: 0,
total: 0
};
}
obj[spec.section].push(spec);
obj[spec.section].total++;
maxSpecs = Math.max(obj[spec.section].total, maxSpecs);
if (!spec.shouldFail) {
obj[spec.section].pass++;
}
obj[spec.section].specs.push(spec);
return obj;
}, {});

describe(title, () => {
const maxSpecsLen = ('' + maxSpecs).length;
const spaces = maxSpecsLen * 2 + longestName + 11;
console.log('-'.padEnd(spaces + 4, '-'));
console.log(`| ${title.padStart(Math.ceil((spaces + title.length) / 2)).padEnd(spaces)} |`);
console.log(`| ${' '.padEnd(spaces)} |`);
Object.keys(specs).forEach(section => {
console.log(`| ${section.padEnd(longestName)} ${('' + specs[section].pass).padStart(maxSpecsLen)} of ${('' + specs[section].total).padStart(maxSpecsLen)} ${(100 * specs[section].pass / specs[section].total).toFixed().padStart(4)}% |`);
describe(section, () => {
specs[section].forEach((spec) => {
specs[section].specs.forEach((spec) => {
if (options) {
spec.options = Object.assign({}, options, (spec.options || {}));
}
Expand All @@ -25,6 +43,8 @@ function runSpecs(title, file, options) {
});
});
});
console.log('-'.padEnd(spaces + 4, '-'));
console.log();
});
};

Expand Down

0 comments on commit 0ac3c48

Please sign in to comment.