nstdlib-nightly
Version:
Node.js standard library converted to runtime-agnostic ES modules.
38 lines (33 loc) • 1.14 kB
JavaScript
// Source: https://github.com/nodejs/node/blob/65eff1eb/lib/internal/test_runner/reporter/dot.js
import * as colors from "nstdlib/lib/internal/util/colors";
import { formatTestReport } from "nstdlib/lib/internal/test_runner/reporter/utils";
export default (async function* dot(source) {
let count = 0;
let columns = getLineLength();
const failedTests = [];
for await (const { type, data } of source) {
if (type === "test:pass") {
yield `${colors.green}.${colors.clear}`;
}
if (type === "test:fail") {
yield `${colors.red}X${colors.clear}`;
Array.prototype.push.call(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;
}
}
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);
}
}
});
function getLineLength() {
return Math.max(process.stdout.columns ?? 20, 20);
}