Skip to content

Commit 0ac3c48

Browse files
committed
show pass percent
1 parent ba1de1e commit 0ac3c48

File tree

1 file changed

+23
-3
lines changed

1 file changed

+23
-3
lines changed

test/specs/run-spec.js

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,35 @@
11
function runSpecs(title, file, options) {
22
const json = require(file);
3+
let longestName = 0;
4+
let maxSpecs = 0;
35
const specs = json.reduce((obj, spec) => {
46
if (!obj[spec.section]) {
5-
obj[spec.section] = [];
7+
longestName = Math.max(spec.section.length, longestName);
8+
obj[spec.section] = {
9+
specs: [],
10+
pass: 0,
11+
total: 0
12+
};
613
}
7-
obj[spec.section].push(spec);
14+
obj[spec.section].total++;
15+
maxSpecs = Math.max(obj[spec.section].total, maxSpecs);
16+
if (!spec.shouldFail) {
17+
obj[spec.section].pass++;
18+
}
19+
obj[spec.section].specs.push(spec);
820
return obj;
921
}, {});
1022

1123
describe(title, () => {
24+
const maxSpecsLen = ('' + maxSpecs).length;
25+
const spaces = maxSpecsLen * 2 + longestName + 11;
26+
console.log('-'.padEnd(spaces + 4, '-'));
27+
console.log(`| ${title.padStart(Math.ceil((spaces + title.length) / 2)).padEnd(spaces)} |`);
28+
console.log(`| ${' '.padEnd(spaces)} |`);
1229
Object.keys(specs).forEach(section => {
30+
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)}% |`);
1331
describe(section, () => {
14-
specs[section].forEach((spec) => {
32+
specs[section].specs.forEach((spec) => {
1533
if (options) {
1634
spec.options = Object.assign({}, options, (spec.options || {}));
1735
}
@@ -25,6 +43,8 @@ function runSpecs(title, file, options) {
2543
});
2644
});
2745
});
46+
console.log('-'.padEnd(spaces + 4, '-'));
47+
console.log();
2848
});
2949
};
3050

0 commit comments

Comments
 (0)