Skip to content

Commit

Permalink
test: print test summary at the end (#13421)
Browse files Browse the repository at this point in the history
  • Loading branch information
OrKoN authored Dec 18, 2024
1 parent d1c5ca3 commit 152f426
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 14 deletions.
21 changes: 15 additions & 6 deletions tools/mocha-runner/src/mocha-runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import {
filterByParameters,
filterByPlatform,
getExpectationUpdates,
getSuggestionsForAction,
printSuggestions,
readJSON,
writeJSON,
Expand Down Expand Up @@ -295,23 +296,31 @@ async function main() {
fail = true;
console.error(err);
} finally {
const added = getSuggestionsForAction(recommendations, 'add');
const removed = getSuggestionsForAction(recommendations, 'remove');
const updated = getSuggestionsForAction(recommendations, 'update');
if (!!provideSuggestions) {
printSuggestions(
recommendations,
'add',
added,
'Add the following to TestExpectations.json to ignore the error:',
true,
);
printSuggestions(
recommendations,
'remove',
removed,
'Remove the following from the TestExpectations.json to ignore the error:',
);
printSuggestions(
recommendations,
'update',
updated,
'Update the following expectations in the TestExpectations.json to ignore the error:',
true,
);
}
const unexpected = added.length + removed.length + updated.length;
console.log(
fail && Boolean(unexpected)
? `Run failed: ${unexpected} unexpected result(s).`
: `Run succeeded.`,
);
process.exit(fail ? 1 : 0);
}
}
Expand Down
22 changes: 14 additions & 8 deletions tools/mocha-runner/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,27 +72,33 @@ export function prettyPrintJSON(json: unknown): void {
console.log(JSON.stringify(json, null, 2));
}

export function printSuggestions(
export function getSuggestionsForAction(
recommendations: RecommendedExpectation[],
action: RecommendedExpectation['action'],
message: string,
): void {
const toPrint = recommendations.filter(item => {
): RecommendedExpectation[] {
return recommendations.filter(item => {
return item.action === action;
});
if (toPrint.length) {
}

export function printSuggestions(
recommendations: RecommendedExpectation[],
message: string,
printBasedOn = false,
): void {
if (recommendations.length) {
console.log(message);
prettyPrintJSON(
toPrint.map(item => {
recommendations.map(item => {
return item.expectation;
}),
);
if (action !== 'remove') {
if (printBasedOn) {
console.log(
'The recommendations are based on the following applied expectations:',
);
prettyPrintJSON(
toPrint.map(item => {
recommendations.map(item => {
return item.basedOn;
}),
);
Expand Down

0 comments on commit 152f426

Please sign in to comment.