-
-
Notifications
You must be signed in to change notification settings - Fork 35.4k
Expand file tree
/
Copy pathdot.js
More file actions
60 lines (57 loc) · 1.74 KB
/
dot.js
File metadata and controls
60 lines (57 loc) · 1.74 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
52
53
54
55
56
57
58
59
60
'use strict';
const {
ArrayPrototypePush,
MathMax,
} = primordials;
const colors = require('internal/util/colors');
const { getCoverageReport } = require('internal/test_runner/utils');
const {
formatTestReport,
reporterColorMap,
reporterUnicodeSymbolMap,
} = require('internal/test_runner/reporter/utils');
module.exports = async function* dot(source) {
let count = 0;
let columns = getLineLength();
const failedTests = [];
const diagnostics = [];
let coverage;
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:fail' || type === 'test:pass') && ++count === columns) {
yield '\n';
// Getting again in case the terminal was resized.
columns = getLineLength();
count = 0;
}
if (type === 'test:diagnostic') {
ArrayPrototypePush(diagnostics, data);
}
if (type === 'test:coverage') {
coverage = data;
}
}
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);
}
}
for (const diagnostic of diagnostics) {
const color = reporterColorMap[diagnostic.level] || reporterColorMap['test:diagnostic'];
yield `${color}${reporterUnicodeSymbolMap['test:diagnostic']}${diagnostic.message}${colors.white}\n`;
}
if (coverage) {
yield getCoverageReport('', coverage.summary, reporterUnicodeSymbolMap['test:coverage'], colors.blue, true);
}
};
function getLineLength() {
return MathMax(process.stdout.columns ?? 20, 20);
}