2017-02-25 00:50:17 +01:00
|
|
|
/**
|
|
|
|
* TestRunner.js
|
|
|
|
*
|
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";
|
|
|
|
|
2017-03-23 18:52:20 +01:00
|
|
|
import TestRegister from "./TestRegister.js";
|
|
|
|
import "./tests/operations/Base58.js";
|
2017-07-19 17:29:37 +02:00
|
|
|
import "./tests/operations/BCD.js";
|
2017-09-05 16:26:09 +02:00
|
|
|
import "./tests/operations/BitwiseOp.js";
|
2017-04-05 23:00:06 +02:00
|
|
|
import "./tests/operations/ByteRepr.js";
|
2017-05-08 00:07:56 +02:00
|
|
|
import "./tests/operations/CharEnc.js";
|
2017-06-21 23:28:17 +02:00
|
|
|
import "./tests/operations/Cipher.js";
|
2017-05-02 17:21:04 +02:00
|
|
|
import "./tests/operations/Code.js";
|
2017-03-23 18:52:20 +01:00
|
|
|
import "./tests/operations/Compress.js";
|
2017-06-12 14:28:41 +02:00
|
|
|
import "./tests/operations/DateTime.js";
|
2017-03-23 18:52:20 +01:00
|
|
|
import "./tests/operations/FlowControl.js";
|
2017-09-14 16:54:56 +02:00
|
|
|
import "./tests/operations/Hash.js";
|
2017-04-29 21:44:39 +02:00
|
|
|
import "./tests/operations/Image.js";
|
2017-03-23 18:52:20 +01:00
|
|
|
import "./tests/operations/MorseCode.js";
|
2017-08-28 23:55:54 +02:00
|
|
|
import "./tests/operations/MS.js";
|
2017-11-24 17:32:11 +01:00
|
|
|
import "./tests/operations/PHP.js";
|
2017-03-23 18:52:20 +01:00
|
|
|
import "./tests/operations/StrUtils.js";
|
2017-05-30 08:53:18 +02:00
|
|
|
import "./tests/operations/SeqUtils.js";
|
2017-08-27 15:44:26 +02:00
|
|
|
|
2017-03-23 18:52:20 +01: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
|
|
|
|
|
|
|
|
2017-03-21 23:41:44 +01:00
|
|
|
TestRegister.runTests()
|
2017-02-28 18:08:36 +01:00
|
|
|
.then(function(results) {
|
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
|
|
|
});
|