-
-
Notifications
You must be signed in to change notification settings - Fork 35.4k
Expand file tree
/
Copy pathdot.js
More file actions
51 lines (48 loc) · 1.47 KB
/
dot.js
File metadata and controls
51 lines (48 loc) · 1.47 KB
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
'use strict';
const {
ArrayPrototypePush,
MathMax,
} = primordials;
const colors = require('internal/util/colors');
const { formatTestReport } = require('internal/test_runner/reporter/utils');
module.exports = async function* dot(source) {
let count = 0;
let columns = getLineLength();
const failedTests = [];
const coverageErrors = [];
for await (const { type, data } of source) {
if (type === 'test:pass') {
yield `${colors.green}.${colors.reset}`;
}
if (type === 'test:fail') {
yield `${colors.red}X${colors.reset}`;
ArrayPrototypePush(failedTests, data);
}
if (type === 'test:diagnostic' && data.level === 'error') {
// Collect coverage errors (coverage threshold failures)
ArrayPrototypePush(coverageErrors, data.message);
}
if ((type === 'test:fail' || type === 'test:pass') && ++count === columns) {
yield '\n';
// Getting again in case the terminal was resized.
columns = getLineLength();
count = 0;
}
}
yield '\n';
if (failedTests.length > 0) {
yield `\n${colors.red}Failed tests:${colors.white}\n\n`;
for (const test of failedTests) {
yield formatTestReport('test:fail', test);
}
}
if (coverageErrors.length > 0) {
yield `\n${colors.red}Coverage errors:${colors.white}\n\n`;
for (const error of coverageErrors) {
yield `${colors.red}${error}${colors.white}\n`;
}
}
};
function getLineLength() {
return MathMax(process.stdout.columns ?? 20, 20);
}