test_runner: print formatted errors on summary · nodejs/node@0c3ae25
@@ -30,6 +30,31 @@ class SpecReporter extends Transform {
3030colors.refresh();
3131}
323233+ #formatFailedTestResults() {
34+if (this.#failedTests.length === 0) {
35+return '';
36+}
37+38+const results = [
39+`\n${reporterColorMap['test:fail']}${reporterUnicodeSymbolMap['test:fail']}failing tests:${colors.white}\n`,
40+];
41+42+for (let i = 0; i < this.#failedTests.length; i++) {
43+const test = this.#failedTests[i];
44+const formattedErr = formatTestReport('test:fail', test);
45+46+if (test.file) {
47+const relPath = relative(this.#cwd, test.file);
48+const location = `test at ${relPath}:${test.line}:${test.column}`;
49+ArrayPrototypePush(results, location);
50+}
51+52+ArrayPrototypePush(results, formattedErr);
53+}
54+55+this.#failedTests = []; // Clean up the failed tests
56+return ArrayPrototypeJoin(results, '\n'); ;
57+}
3358 #handleTestReportEvent(type, data) {
3459const subtest = ArrayPrototypeShift(this.#stack); // This is the matching `test:start` event
3560if (subtest) {
@@ -74,31 +99,18 @@ class SpecReporter extends Transform {
7499case 'test:coverage':
75100return getCoverageReport(indent(data.nesting), data.summary,
76101reporterUnicodeSymbolMap['test:coverage'], colors.blue, true);
102+case 'test:summary':
103+// We report only the root test summary
104+if (data.file === undefined) {
105+return this.#formatFailedTestResults();
106+}
77107}
78108}
79109_transform({ type, data }, encoding, callback) {
80110callback(null, this.#handleEvent({ __proto__: null, type, data }));
81111}
82112_flush(callback) {
83-if (this.#failedTests.length === 0) {
84-callback(null, '');
85-return;
86-}
87-const results = [`\n${reporterColorMap['test:fail']}${reporterUnicodeSymbolMap['test:fail']}failing tests:${colors.white}\n`];
88-for (let i = 0; i < this.#failedTests.length; i++) {
89-const test = this.#failedTests[i];
90-const formattedErr = formatTestReport('test:fail', test);
91-92-if (test.file) {
93-const relPath = relative(this.#cwd, test.file);
94-const location = `test at ${relPath}:${test.line}:${test.column}`;
95-96-ArrayPrototypePush(results, location);
97-}
98-99-ArrayPrototypePush(results, formattedErr);
100-}
101-callback(null, ArrayPrototypeJoin(results, '\n'));
113+callback(null, this.#formatFailedTestResults());
102114}
103115}
104116