2017-12-28 19:17:38 +01:00
|
|
|
/* eslint no-console: 0 */
|
|
|
|
|
2017-02-25 00:50:17 +01:00
|
|
|
/**
|
2018-05-17 17:11:34 +02:00
|
|
|
* Test Runner
|
2017-02-25 00:50:17 +01:00
|
|
|
*
|
2017-03-21 23:41:44 +01:00
|
|
|
* For running the tests in the test register.
|
2017-02-25 00:50:17 +01:00
|
|
|
*
|
2017-02-28 18:08:36 +01:00
|
|
|
* @author tlwr [toby@toby.codes]
|
2017-03-21 23:41:44 +01:00
|
|
|
* @author n1474335 [n1474335@gmail.com]
|
2017-02-25 00:50:17 +01:00
|
|
|
* @copyright Crown Copyright 2017
|
|
|
|
* @license Apache-2.0
|
|
|
|
*/
|
2017-03-25 14:32:35 +01:00
|
|
|
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";
|
2018-05-17 17:34:00 +02:00
|
|
|
import "./tests/operations/Base58";
|
2018-03-27 00:14:23 +02:00
|
|
|
import "./tests/operations/Base64";
|
2018-05-17 17:34:00 +02:00
|
|
|
import "./tests/operations/BCD";
|
2018-05-23 19:59:57 +02:00
|
|
|
import "./tests/operations/BitwiseOp";
|
2018-05-21 19:37:32 +02:00
|
|
|
import "./tests/operations/BSON";
|
2018-05-17 17:34:00 +02:00
|
|
|
import "./tests/operations/ByteRepr";
|
2018-04-09 12:13:23 +02:00
|
|
|
import "./tests/operations/CartesianProduct";
|
2018-05-17 17:34:00 +02:00
|
|
|
import "./tests/operations/CharEnc";
|
2018-05-14 19:33:16 +02:00
|
|
|
import "./tests/operations/Ciphers";
|
2018-05-17 17:11:34 +02:00
|
|
|
import "./tests/operations/Checksum";
|
2018-05-27 23:07:09 +02:00
|
|
|
import "./tests/operations/Code";
|
2018-05-21 20:23:05 +02:00
|
|
|
import "./tests/operations/Compress";
|
2018-05-23 19:31:26 +02:00
|
|
|
import "./tests/operations/Crypt";
|
2018-05-21 19:37:32 +02:00
|
|
|
import "./tests/operations/DateTime";
|
2018-05-21 11:58:35 +02:00
|
|
|
import "./tests/operations/Fork";
|
|
|
|
import "./tests/operations/Jump";
|
|
|
|
import "./tests/operations/ConditionalJump";
|
|
|
|
import "./tests/operations/Register";
|
|
|
|
import "./tests/operations/Comment";
|
2018-05-17 17:11:34 +02:00
|
|
|
import "./tests/operations/Hash";
|
2018-08-03 19:20:38 +02:00
|
|
|
import "./tests/operations/HaversineDistance";
|
2018-05-17 17:34:00 +02:00
|
|
|
import "./tests/operations/Hexdump";
|
2018-05-28 00:27:11 +02:00
|
|
|
import "./tests/operations/Image";
|
2018-05-17 17:34:00 +02:00
|
|
|
import "./tests/operations/MorseCode";
|
|
|
|
import "./tests/operations/MS";
|
2018-05-29 18:00:24 +02:00
|
|
|
import "./tests/operations/PGP";
|
2018-05-21 14:35:11 +02:00
|
|
|
import "./tests/operations/PHP";
|
2018-05-17 17:34:00 +02:00
|
|
|
import "./tests/operations/NetBIOS";
|
2018-05-21 14:35:11 +02:00
|
|
|
import "./tests/operations/OTP";
|
2018-04-09 12:13:23 +02:00
|
|
|
import "./tests/operations/PowerSet";
|
2018-05-28 01:39:03 +02:00
|
|
|
import "./tests/operations/Regex";
|
2018-05-14 19:33:16 +02:00
|
|
|
import "./tests/operations/Rotate";
|
2018-05-27 23:07:09 +02:00
|
|
|
import "./tests/operations/StrUtils";
|
2018-05-17 17:34:00 +02:00
|
|
|
import "./tests/operations/SeqUtils";
|
2018-05-14 19:33:16 +02:00
|
|
|
import "./tests/operations/SetDifference";
|
|
|
|
import "./tests/operations/SetIntersection";
|
|
|
|
import "./tests/operations/SetUnion";
|
|
|
|
import "./tests/operations/SymmetricDifference";
|
2018-08-09 20:17:24 +02:00
|
|
|
import "./tests/operations/Magic";
|
2017-03-23 18:52:20 +01:00
|
|
|
|
2018-05-03 11:20:13 +02:00
|
|
|
import "./tests/nodeApi/nodeApi";
|
2018-06-15 12:33:13 +02:00
|
|
|
import "./tests/nodeApi/ops";
|
2018-05-03 11:20:13 +02:00
|
|
|
|
2017-05-03 01:40:39 +02:00
|
|
|
let allTestsPassing = true;
|
|
|
|
const testStatusCounts = {
|
|
|
|
total: 0,
|
|
|
|
};
|
2017-02-28 18:08:36 +01:00
|
|
|
|
2017-03-21 23:41:44 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 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 = {
|
2017-03-21 23:41:44 +01:00
|
|
|
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;
|
2017-03-21 23:41:44 +01:00
|
|
|
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
|
|
|
|
2018-05-03 11:20:13 +02:00
|
|
|
Promise.all([
|
|
|
|
TestRegister.runTests(),
|
|
|
|
TestRegister.runApiTests()
|
|
|
|
])
|
|
|
|
.then(function(resultsPair) {
|
|
|
|
const results = resultsPair[0].concat(resultsPair[1]);
|
2017-03-21 23:41:44 +01:00
|
|
|
results.forEach(handleTestResult);
|
|
|
|
|
|
|
|
console.log("\n");
|
|
|
|
|
2017-05-03 00:06:28 +02:00
|
|
|
for (const testStatus in testStatusCounts) {
|
|
|
|
const count = testStatusCounts[testStatus];
|
2017-03-21 23:41:44 +01:00
|
|
|
if (count > 0) {
|
|
|
|
console.log(testStatus.toUpperCase(), count);
|
2017-02-25 00:50:17 +01:00
|
|
|
}
|
2017-03-21 23:41:44 +01:00
|
|
|
}
|
2017-02-28 18:08:36 +01:00
|
|
|
|
2017-03-21 23:41:44 +01:00
|
|
|
if (!allTestsPassing) {
|
|
|
|
console.log("\nNot all tests are passing");
|
2017-02-28 18:08:36 +01:00
|
|
|
}
|
2017-03-21 23:41:44 +01:00
|
|
|
|
|
|
|
process.exit(allTestsPassing ? 0 : 1);
|
2017-02-25 00:50:17 +01:00
|
|
|
});
|
2018-05-03 11:20:13 +02:00
|
|
|
|