CyberChef/test/index.js

99 lines
2.2 KiB
JavaScript
Raw Normal View History

2017-02-24 23:50:17 +00:00
/**
* TestRunner.js
*
* For running the tests in the test register.
2017-02-24 23:50:17 +00:00
*
* @author tlwr [toby@toby.codes]
* @author n1474335 [n1474335@gmail.com]
2017-02-24 23:50:17 +00:00
* @copyright Crown Copyright 2017
* @license Apache-2.0
*/
import "babel-polyfill";
import TestRegister from "./TestRegister.js";
import "./tests/operations/Base58.js";
2017-04-05 21:00:06 +00:00
import "./tests/operations/ByteRepr.js";
2017-05-02 15:21:04 +00:00
import "./tests/operations/Code.js";
import "./tests/operations/Compress.js";
import "./tests/operations/FlowControl.js";
import "./tests/operations/MorseCode.js";
import "./tests/operations/StrUtils.js";
2017-04-28 15:51:57 +00:00
let allTestsPassing = true,
testStatusCounts = {
total: 0,
};
/**
* Helper function to convert a status to an icon.
*
* @param {string} status
* @returns {string}
*/
function statusToIcon(status) {
2017-05-02 22:06:28 +00:00
const icons = {
erroring: "🔥",
failing: "❌",
passing: "✔️️",
};
return icons[status] || "?";
}
/**
* Displays a given test result in the console.
*
* @param {Object} testResult
*/
function handleTestResult(testResult) {
allTestsPassing = allTestsPassing && testResult.status === "passing";
2017-05-02 22:06:28 +00:00
const newCount = (testStatusCounts[testResult.status] || 0) + 1;
testStatusCounts[testResult.status] = newCount;
testStatusCounts.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")
);
}
}
2017-03-29 23:15:40 +00:00
/**
* Fail if the process takes longer than 10 seconds.
*/
setTimeout(function() {
console.log("Tests took longer than 10 seconds to run, returning.");
process.exit(1);
}, 1 * 1000);
TestRegister.runTests()
.then(function(results) {
results.forEach(handleTestResult);
console.log("\n");
2017-05-02 22:06:28 +00:00
for (const testStatus in testStatusCounts) {
const count = testStatusCounts[testStatus];
if (count > 0) {
console.log(testStatus.toUpperCase(), count);
2017-02-24 23:50:17 +00:00
}
}
if (!allTestsPassing) {
console.log("\nNot all tests are passing");
}
process.exit(allTestsPassing ? 0 : 1);
2017-02-24 23:50:17 +00:00
});