Skip to content

Commit 152f426

Browse files
authored
test: print test summary at the end (#13421)
1 parent d1c5ca3 commit 152f426

File tree

2 files changed

+29
-14
lines changed

2 files changed

+29
-14
lines changed

tools/mocha-runner/src/mocha-runner.ts

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import {
2929
filterByParameters,
3030
filterByPlatform,
3131
getExpectationUpdates,
32+
getSuggestionsForAction,
3233
printSuggestions,
3334
readJSON,
3435
writeJSON,
@@ -295,23 +296,31 @@ async function main() {
295296
fail = true;
296297
console.error(err);
297298
} finally {
299+
const added = getSuggestionsForAction(recommendations, 'add');
300+
const removed = getSuggestionsForAction(recommendations, 'remove');
301+
const updated = getSuggestionsForAction(recommendations, 'update');
298302
if (!!provideSuggestions) {
299303
printSuggestions(
300-
recommendations,
301-
'add',
304+
added,
302305
'Add the following to TestExpectations.json to ignore the error:',
306+
true,
303307
);
304308
printSuggestions(
305-
recommendations,
306-
'remove',
309+
removed,
307310
'Remove the following from the TestExpectations.json to ignore the error:',
308311
);
309312
printSuggestions(
310-
recommendations,
311-
'update',
313+
updated,
312314
'Update the following expectations in the TestExpectations.json to ignore the error:',
315+
true,
313316
);
314317
}
318+
const unexpected = added.length + removed.length + updated.length;
319+
console.log(
320+
fail && Boolean(unexpected)
321+
? `Run failed: ${unexpected} unexpected result(s).`
322+
: `Run succeeded.`,
323+
);
315324
process.exit(fail ? 1 : 0);
316325
}
317326
}

tools/mocha-runner/src/utils.ts

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -72,27 +72,33 @@ export function prettyPrintJSON(json: unknown): void {
7272
console.log(JSON.stringify(json, null, 2));
7373
}
7474

75-
export function printSuggestions(
75+
export function getSuggestionsForAction(
7676
recommendations: RecommendedExpectation[],
7777
action: RecommendedExpectation['action'],
78-
message: string,
79-
): void {
80-
const toPrint = recommendations.filter(item => {
78+
): RecommendedExpectation[] {
79+
return recommendations.filter(item => {
8180
return item.action === action;
8281
});
83-
if (toPrint.length) {
82+
}
83+
84+
export function printSuggestions(
85+
recommendations: RecommendedExpectation[],
86+
message: string,
87+
printBasedOn = false,
88+
): void {
89+
if (recommendations.length) {
8490
console.log(message);
8591
prettyPrintJSON(
86-
toPrint.map(item => {
92+
recommendations.map(item => {
8793
return item.expectation;
8894
}),
8995
);
90-
if (action !== 'remove') {
96+
if (printBasedOn) {
9197
console.log(
9298
'The recommendations are based on the following applied expectations:',
9399
);
94100
prettyPrintJSON(
95-
toPrint.map(item => {
101+
recommendations.map(item => {
96102
return item.basedOn;
97103
}),
98104
);

0 commit comments

Comments
 (0)