mirror of
https://github.com/gchq/CyberChef
synced 2024-12-25 03:53:19 +00: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
.gitignore
vendored
1
.gitignore
vendored
|
@ -1,6 +1,7 @@
|
|||
node_modules
|
||||
npm-debug.log
|
||||
build/dev
|
||||
build/test
|
||||
docs/*
|
||||
!docs/*.conf.json
|
||||
!docs/*.ico
|
||||
|
|
49
Gruntfile.js
49
Gruntfile.js
|
@ -11,7 +11,7 @@ module.exports = function(grunt) {
|
|||
|
||||
grunt.registerTask("test",
|
||||
"A task which runs all the tests in test/tests.",
|
||||
["clean:test", "concat:jsTest", "copy:htmlTest", "chmod:build", "exec:tests"]);
|
||||
["clean:test", "concat:jsTest", "copy:htmlTest", "chmod:build", "execute:test"]);
|
||||
|
||||
grunt.registerTask("prod",
|
||||
"Creates a production-ready build. Use the --msg flag to add a compile message.",
|
||||
|
@ -35,6 +35,7 @@ module.exports = function(grunt) {
|
|||
["eslint", "exec:stats", "exec:displayStats"]);
|
||||
|
||||
grunt.registerTask("doc", "docs");
|
||||
grunt.registerTask("tests", "test");
|
||||
grunt.registerTask("lint", "eslint");
|
||||
|
||||
|
||||
|
@ -50,6 +51,7 @@ module.exports = function(grunt) {
|
|||
grunt.loadNpmTasks("grunt-inline-alt");
|
||||
grunt.loadNpmTasks("grunt-chmod");
|
||||
grunt.loadNpmTasks("grunt-exec");
|
||||
grunt.loadNpmTasks("grunt-execute");
|
||||
grunt.loadNpmTasks("grunt-contrib-watch");
|
||||
|
||||
|
||||
|
@ -161,22 +163,16 @@ module.exports = function(grunt) {
|
|||
|
||||
];
|
||||
|
||||
var jsAppFiles = [].concat(
|
||||
jsIncludes,
|
||||
[
|
||||
// Start the main app!
|
||||
"src/js/views/html/main.js",
|
||||
]
|
||||
);
|
||||
var jsAppFiles = jsIncludes.concat([
|
||||
// Start the main app!
|
||||
"src/js/views/html/main.js",
|
||||
]);
|
||||
|
||||
var jsTestFiles = [].concat(
|
||||
jsIncludes,
|
||||
[
|
||||
"test/TestRegister.js",
|
||||
"test/tests/**/*.js",
|
||||
"test/TestRunner.js",
|
||||
]
|
||||
);
|
||||
var jsTestFiles = jsIncludes.concat([
|
||||
"test/TestRegister.js",
|
||||
"test/tests/**/*.js",
|
||||
"test/TestRunner.js",
|
||||
]);
|
||||
|
||||
var banner = '/**\n\
|
||||
* CyberChef - The Cyber Swiss Army Knife\n\
|
||||
|
@ -218,11 +214,7 @@ module.exports = function(grunt) {
|
|||
config: ["src/js/config/**/*.js"],
|
||||
views: ["src/js/views/**/*.js"],
|
||||
operations: ["src/js/operations/**/*.js"],
|
||||
tests: [
|
||||
"test/**/*.js",
|
||||
"!test/PhantomRunner.js",
|
||||
"!test/NodeRunner.js",
|
||||
],
|
||||
tests: ["test/**/*.js"],
|
||||
},
|
||||
jsdoc: {
|
||||
options: {
|
||||
|
@ -241,8 +233,8 @@ module.exports = function(grunt) {
|
|||
},
|
||||
clean: {
|
||||
dev: ["build/dev/*"],
|
||||
test: ["build/test/*"],
|
||||
prod: ["build/prod/*"],
|
||||
test: ["build/test/*"],
|
||||
docs: ["docs/*", "!docs/*.conf.json", "!docs/*.ico"],
|
||||
},
|
||||
concat: {
|
||||
|
@ -291,12 +283,7 @@ module.exports = function(grunt) {
|
|||
dest: "build/dev/index.html"
|
||||
},
|
||||
htmlTest: {
|
||||
options: {
|
||||
process: function(content, srcpath) {
|
||||
return grunt.template.process(content, templateOptions);
|
||||
}
|
||||
},
|
||||
src: "src/html/test.html",
|
||||
src: "test/test.html",
|
||||
dest: "build/test/index.html"
|
||||
},
|
||||
htmlProd: {
|
||||
|
@ -451,9 +438,6 @@ module.exports = function(grunt) {
|
|||
}
|
||||
},
|
||||
exec: {
|
||||
tests: {
|
||||
command: "node test/NodeRunner.js",
|
||||
},
|
||||
repoSize: {
|
||||
command: [
|
||||
"git ls-files | wc -l | xargs printf '\n%b\ttracked files\n'",
|
||||
|
@ -506,6 +490,9 @@ module.exports = function(grunt) {
|
|||
].join(";")
|
||||
}
|
||||
},
|
||||
execute: {
|
||||
test: "test/NodeRunner.js"
|
||||
},
|
||||
watch: {
|
||||
css: {
|
||||
files: "src/css/**/*.css",
|
||||
|
|
|
@ -37,6 +37,7 @@
|
|||
"grunt-contrib-watch": "~1.0.0",
|
||||
"grunt-eslint": "^19.0.0",
|
||||
"grunt-exec": "~1.0.1",
|
||||
"grunt-execute": "^0.2.2",
|
||||
"grunt-inline-alt": "~0.3.10",
|
||||
"grunt-jsdoc": "^2.1.0",
|
||||
"ink-docstrap": "^1.1.4",
|
||||
|
|
8
src/js/lib/vuejs/vue.min.js
vendored
8
src/js/lib/vuejs/vue.min.js
vendored
File diff suppressed because one or more lines are too long
|
@ -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");
|
||||
}
|
||||
});
|
||||
})();
|
||||
});
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
<!-- htmlmin:ignore --><!--
|
||||
CyberChef - The Cyber Swiss Army Knife
|
||||
<!--
|
||||
CyberChef test suite
|
||||
|
||||
@author tlwr [toby@toby.codes]
|
||||
|
||||
|
@ -20,12 +20,11 @@
|
|||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
-->
|
||||
<!-- htmlmin:ignore -->
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>CyberChef</title>
|
||||
<title>CyberChef test suite</title>
|
||||
</head>
|
||||
<body>
|
||||
<main style="white-space: pre"></main>
|
|
@ -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…
Reference in a new issue