mirror of
https://github.com/gchq/CyberChef.git
synced 2025-04-21 15:26:16 -04:00
Tweaks and restructuring of test runner.
This commit is contained in:
parent
6e5ea5d75f
commit
d7e396c04f
12 changed files with 99 additions and 149 deletions
|
@ -1,20 +1,20 @@
|
|||
/* eslint-env node */
|
||||
|
||||
/**
|
||||
* NodeRunner.js
|
||||
*
|
||||
* The purpose of this file is to execute via PhantomJS the file
|
||||
* PhantomRunner.js, because PhantomJS is managed by node.
|
||||
*
|
||||
* @author tlwr [toby@toby.codes
|
||||
*
|
||||
* @author tlwr [toby@toby.codes]
|
||||
* @copyright Crown Copyright 2017
|
||||
* @license Apache-2.0
|
||||
*
|
||||
*/
|
||||
var path = require("path");
|
||||
var phantomjs = require("phantomjs-prebuilt");
|
||||
|
||||
var phantomEntryPoint = path.join(__dirname, "PhantomRunner.js");
|
||||
var program = phantomjs.exec(phantomEntryPoint);
|
||||
var path = require("path"),
|
||||
phantomjs = require("phantomjs-prebuilt"),
|
||||
phantomEntryPoint = path.join(__dirname, "PhantomRunner.js"),
|
||||
program = phantomjs.exec(phantomEntryPoint);
|
||||
|
||||
program.stdout.pipe(process.stdout);
|
||||
program.stderr.pipe(process.stderr);
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -4,22 +4,23 @@
|
|||
* This is so individual files can register their tests in one place, and
|
||||
* ensure that they will get run by the frontend.
|
||||
*
|
||||
* @author tlwr [toby@toby.codes
|
||||
*
|
||||
* @author tlwr [toby@toby.codes]
|
||||
* @copyright Crown Copyright 2017
|
||||
* @license Apache-2.0
|
||||
*
|
||||
*/
|
||||
|
||||
(function() {
|
||||
/**
|
||||
* Add a list of tests to the register.
|
||||
* Object to store and run the list of tests.
|
||||
*
|
||||
* @class
|
||||
* @constructor
|
||||
*/
|
||||
function TestRegister() {
|
||||
this.tests = [];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Add a list of tests to the register.
|
||||
*
|
||||
|
@ -29,18 +30,9 @@
|
|||
this.tests = this.tests.concat(tests);
|
||||
};
|
||||
|
||||
/**
|
||||
* Returns the list of tests.
|
||||
*
|
||||
* @returns {Object[]} tests
|
||||
*/
|
||||
TestRegister.prototype.getTests = function() {
|
||||
return this.tests;
|
||||
};
|
||||
|
||||
/**
|
||||
* Runs all the tests in the register.
|
||||
*
|
||||
*/
|
||||
TestRegister.prototype.runTests = function() {
|
||||
return Promise.all(
|
||||
|
@ -52,7 +44,7 @@
|
|||
test.recipeConfig,
|
||||
{},
|
||||
0,
|
||||
0
|
||||
false
|
||||
))
|
||||
.then(function(result) {
|
||||
var ret = {
|
||||
|
@ -91,6 +83,7 @@
|
|||
);
|
||||
};
|
||||
|
||||
|
||||
// Singleton TestRegister, keeping things simple and obvious.
|
||||
window.TestRegister = new TestRegister();
|
||||
})();
|
||||
|
|
|
@ -3,36 +3,36 @@
|
|||
*
|
||||
* This is for actually running the tests in the test register.
|
||||
*
|
||||
* @author tlwr [toby@toby.codes
|
||||
*
|
||||
* @author tlwr [toby@toby.codes]
|
||||
* @copyright Crown Copyright 2017
|
||||
* @license Apache-2.0
|
||||
*
|
||||
*/
|
||||
(function() {
|
||||
document.addEventListener("DOMContentLoaded", function() {
|
||||
TestRegister.runTests()
|
||||
.then(function(results) {
|
||||
results.forEach(function(testResult) {
|
||||
if (typeof window.callPhantom === "function") {
|
||||
window.callPhantom(
|
||||
"testResult",
|
||||
testResult
|
||||
);
|
||||
} else {
|
||||
var output = [
|
||||
"----------",
|
||||
testResult.test.name,
|
||||
testResult.status,
|
||||
testResult.output,
|
||||
].join("<br>");
|
||||
document.body.innerHTML += "<div>" + output + "</div>";
|
||||
}
|
||||
});
|
||||
|
||||
document.addEventListener("DOMContentLoaded", function() {
|
||||
TestRegister.runTests()
|
||||
.then(function(results) {
|
||||
results.forEach(function(testResult) {
|
||||
|
||||
if (typeof window.callPhantom === "function") {
|
||||
window.callPhantom("exit");
|
||||
// If we're running this in PhantomJS
|
||||
window.callPhantom(
|
||||
"testResult",
|
||||
testResult
|
||||
);
|
||||
} else {
|
||||
// If we're just viewing this in a normal browser
|
||||
var output = [
|
||||
"----------",
|
||||
testResult.test.name,
|
||||
testResult.status,
|
||||
testResult.output,
|
||||
].join("<br>");
|
||||
document.querySelector("main").innerHTML += output;
|
||||
}
|
||||
});
|
||||
|
||||
if (typeof window.callPhantom === "function") {
|
||||
window.callPhantom("exit");
|
||||
}
|
||||
});
|
||||
})();
|
||||
});
|
||||
|
|
33
test/test.html
Executable file
33
test/test.html
Executable file
|
@ -0,0 +1,33 @@
|
|||
<!--
|
||||
CyberChef test suite
|
||||
|
||||
@author tlwr [toby@toby.codes]
|
||||
|
||||
@copyright Crown Copyright 2017
|
||||
@license Apache-2.0
|
||||
|
||||
Copyright 2017 Crown Copyright
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
-->
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>CyberChef test suite</title>
|
||||
</head>
|
||||
<body>
|
||||
<main style="white-space: pre"></main>
|
||||
<script type="application/javascript" src="tests.js"></script>
|
||||
</body>
|
||||
</html>
|
|
@ -1,11 +1,10 @@
|
|||
/**
|
||||
* Base58 tests.
|
||||
*
|
||||
* @author tlwr [toby@toby.codes
|
||||
* @author tlwr [toby@toby.codes]
|
||||
*
|
||||
* @copyright Crown Copyright 2017
|
||||
* @license Apache-2.0
|
||||
*
|
||||
*/
|
||||
TestRegister.addTests([
|
||||
{
|
||||
|
|
|
@ -1,52 +1,12 @@
|
|||
/**
|
||||
* Core tests.
|
||||
* Flow Control tests.
|
||||
*
|
||||
* @author tlwr [toby@toby.codes]
|
||||
*
|
||||
* @copyright Crown Copyright 2017
|
||||
* @license Apache-2.0
|
||||
*
|
||||
*/
|
||||
TestRegister.addTests([
|
||||
//{
|
||||
// name: "Example error",
|
||||
// input: "1\n2\na\n4",
|
||||
// expectedOutput: "1\n2\n3\n4",
|
||||
// recipeConfig: [
|
||||
// {
|
||||
// op: "Fork",
|
||||
// args: ["\n", "\n", false],
|
||||
// },
|
||||
// {
|
||||
// op: "To Base",
|
||||
// args: [16],
|
||||
// },
|
||||
// ],
|
||||
//},
|
||||
//{
|
||||
// name: "Example non-error when error was expected",
|
||||
// input: "1",
|
||||
// expectedError: true,
|
||||
// recipeConfig: [
|
||||
// {
|
||||
// op: "To Base",
|
||||
// args: [16],
|
||||
// },
|
||||
// ],
|
||||
//},
|
||||
//{
|
||||
// name: "Example fail",
|
||||
// input: "1\n2\na\n4",
|
||||
// expectedOutput: "1\n2\n3\n4",
|
||||
// recipeConfig: [
|
||||
// {
|
||||
// op: "Fork",
|
||||
// args: ["\n", "\n", true],
|
||||
// },
|
||||
// {
|
||||
// op: "To Base",
|
||||
// args: [16],
|
||||
// },
|
||||
// ],
|
||||
//},
|
||||
{
|
||||
name: "Fork: nothing",
|
||||
input: "",
|
|
@ -1,11 +1,10 @@
|
|||
/**
|
||||
* Base58 tests.
|
||||
*
|
||||
* @author tlwr [toby@toby.codes
|
||||
* @author tlwr [toby@toby.codes]
|
||||
*
|
||||
* @copyright Crown Copyright 2017
|
||||
* @license Apache-2.0
|
||||
*
|
||||
*/
|
||||
TestRegister.addTests([
|
||||
{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue