CyberChef/test/index.mjs

129 lines
3.3 KiB
JavaScript
Raw Normal View History

/* eslint no-console: 0 */
2017-02-25 00:50:17 +01:00
/**
* TestRunner.js
*
* For running the tests in the test register.
2017-02-25 00:50:17 +01:00
*
* @author tlwr [toby@toby.codes]
* @author n1474335 [n1474335@gmail.com]
2017-02-25 00:50:17 +01:00
* @copyright Crown Copyright 2017
* @license Apache-2.0
*/
import "babel-polyfill";
2018-03-27 00:14:23 +02:00
// Define global environment functions
global.ENVIRONMENT_IS_WORKER = function() {
return typeof importScripts === "function";
};
global.ENVIRONMENT_IS_NODE = function() {
return typeof process === "object" && typeof require === "function";
};
global.ENVIRONMENT_IS_WEB = function() {
return typeof window === "object";
};
import TestRegister from "./TestRegister";
// import "./tests/operations/Base58.js";
import "./tests/operations/Base64";
// import "./tests/operations/BCD.js";
// import "./tests/operations/BitwiseOp.js";
// import "./tests/operations/BSON.js";
// import "./tests/operations/ByteRepr.js";
// import "./tests/operations/CharEnc.js";
// import "./tests/operations/Cipher.js";
// import "./tests/operations/Code.js";
// import "./tests/operations/Compress.js";
// import "./tests/operations/DateTime.js";
// import "./tests/operations/FlowControl.js";
// import "./tests/operations/Hash.js";
// import "./tests/operations/Hexdump.js";
// import "./tests/operations/Image.js";
// import "./tests/operations/MorseCode.js";
// import "./tests/operations/MS.js";
// import "./tests/operations/PHP.js";
// import "./tests/operations/NetBIOS.js";
// import "./tests/operations/OTP.js";
// import "./tests/operations/Regex.js";
// import "./tests/operations/StrUtils.js";
// import "./tests/operations/SeqUtils.js";
2017-08-27 15:44:26 +02:00
2017-05-03 01:40:39 +02:00
let allTestsPassing = true;
const testStatusCounts = {
total: 0,
};
/**
* Helper function to convert a status to an icon.
*
* @param {string} status
* @returns {string}
*/
function statusToIcon(status) {
2017-05-03 00:06:28 +02: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-03 00:06:28 +02: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-30 01:15:40 +02: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);
2017-05-19 13:15:48 +02:00
}, 10 * 1000);
2017-03-30 01:15:40 +02:00
TestRegister.runTests()
.then(function(results) {
results.forEach(handleTestResult);
console.log("\n");
2017-05-03 00:06:28 +02:00
for (const testStatus in testStatusCounts) {
const count = testStatusCounts[testStatus];
if (count > 0) {
console.log(testStatus.toUpperCase(), count);
2017-02-25 00:50:17 +01:00
}
}
if (!allTestsPassing) {
console.log("\nNot all tests are passing");
}
process.exit(allTestsPassing ? 0 : 1);
2017-02-25 00:50:17 +01:00
});