mirror of
https://github.com/gchq/CyberChef
synced 2025-12-14 15:23:20 +00:00
Tidied up test runner. Passing tests are no longer printed to the console.
This commit is contained in:
@@ -15,59 +15,63 @@
|
||||
* @param {string} status
|
||||
* @returns {string}
|
||||
*/
|
||||
const statusToIcon = function statusToIcon(status) {
|
||||
const icons = {
|
||||
function statusToIcon(status) {
|
||||
return {
|
||||
erroring: "🔥",
|
||||
failing: "❌",
|
||||
passing: "✔️️",
|
||||
};
|
||||
return icons[status] || "?";
|
||||
};
|
||||
|
||||
}[status] || "?";
|
||||
}
|
||||
|
||||
/**
|
||||
* Displays a given test result in the console.
|
||||
* Counts test statuses.
|
||||
*
|
||||
* @param {Object} testStatusCounts
|
||||
* @param {Object} testStatus
|
||||
* @param {Object} testResult
|
||||
*/
|
||||
function handleTestResult(testStatus, testResult) {
|
||||
testStatus.allTestsPassing = testStatus.allTestsPassing && testResult.status === "passing";
|
||||
const newCount = (testStatus.counts[testResult.status] || 0) + 1;
|
||||
testStatus.counts[testResult.status] = newCount;
|
||||
testStatus.counts[testResult.status] = (testStatus.counts[testResult.status] || 0) + 1;
|
||||
testStatus.counts.total += 1;
|
||||
console.log([
|
||||
statusToIcon(testResult.status),
|
||||
testResult.test.name
|
||||
].join(" "));
|
||||
|
||||
if (testResult.output) {
|
||||
console.log(
|
||||
testResult.output
|
||||
.trim()
|
||||
.replace(/^/, "\t")
|
||||
.replace(/\n/g, "\n\t")
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Log each test result, count tests and failures. Log test suite run duration.
|
||||
* Log each test result, count tests and failures.
|
||||
*
|
||||
* @param {Object} testStatus - object describing test run data
|
||||
* @param {Object[]} results - results from TestRegister
|
||||
*/
|
||||
export function logTestReport(testStatus, results) {
|
||||
results.forEach(r => handleTestResult(testStatus, r));
|
||||
console.log("\n");
|
||||
console.log("Tests completed.");
|
||||
|
||||
results.forEach(r => handleTestResult(testStatus, r));
|
||||
|
||||
console.log();
|
||||
for (const testStatusCount in testStatus.counts) {
|
||||
const count = testStatus.counts[testStatusCount];
|
||||
if (count > 0) {
|
||||
console.log(testStatusCount.toUpperCase(), count);
|
||||
console.log(testStatusCount.toUpperCase() + "\t" + count);
|
||||
}
|
||||
}
|
||||
console.log();
|
||||
|
||||
// Print error messages for tests that didn't pass
|
||||
results.filter(res => res.status !== "passing").forEach(testResult => {
|
||||
console.log([
|
||||
statusToIcon(testResult.status),
|
||||
testResult.test.name
|
||||
].join(" "));
|
||||
|
||||
if (testResult.output) {
|
||||
console.log(
|
||||
testResult.output
|
||||
.trim()
|
||||
.replace(/^/, "\t")
|
||||
.replace(/\n/g, "\n\t")
|
||||
);
|
||||
}
|
||||
});
|
||||
console.log();
|
||||
|
||||
process.exit(testStatus.allTestsPassing ? 0 : 1);
|
||||
}
|
||||
@@ -81,4 +85,3 @@ export function setLongTestFailure() {
|
||||
process.exit(1);
|
||||
}, 60 * 1000);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user