Tweaks and restructuring of test runner.

This commit is contained in:
n1474335 2017-02-28 17:08:36 +00:00
parent 6e5ea5d75f
commit d7e396c04f
12 changed files with 99 additions and 149 deletions

View file

@ -1,21 +1,29 @@
/* eslint-env node */
/* globals phantom */
/**
* PhantomRunner.js
*
* This file navigates to build/test/index.html and logs the test results.
*
* @author tlwr [toby@toby.codes
*
* @author tlwr [toby@toby.codes]
* @copyright Crown Copyright 2017
* @license Apache-2.0
*
*/
var page = require("webpage").create();
var allTestsPassing = true;
var testStatusCounts = {
total: 0,
};
var page = require("webpage").create(),
allTestsPassing = true,
testStatusCounts = {
total: 0,
};
/**
* Helper function to convert a status to an icon.
*
* @param {string} status
* @returns {string}
*/
function statusToIcon(status) {
var icons = {
erroring: "🔥",
@ -25,6 +33,10 @@ function statusToIcon(status) {
return icons[status] || "?";
}
/**
* Callback function to handle test results.
*/
page.onCallback = function(messageType) {
if (messageType === "testResult") {
var testResult = arguments[1];
@ -59,22 +71,29 @@ page.onCallback = function(messageType) {
}
if (!allTestsPassing) {
console.log("\n")
console.log("Not all tests are passing");
console.log("\nNot all tests are passing");
}
phantom.exit(allTestsPassing ? 0 : 1);
}
};
page.open("file:///home/toby/Code/CyberChef/build/test/index.html", function(status) {
/**
* Open the test webpage in PhantomJS.
*/
page.open("build/test/index.html", function(status) {
if (status !== "success") {
console.log("STATUS", status);
console.log("STATUS: ", status);
phantom.exit(1);
}
});
/**
* Fail if the process takes longer than 10 seconds.
*/
setTimeout(function() {
// Timeout
console.log("Tests took longer than 10 seconds to run, returning.");
phantom.exit(1);
}, 10 * 1000);