mirror of
https://github.com/gchq/CyberChef
synced 2025-01-12 12:38:48 +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
|
node_modules
|
||||||
npm-debug.log
|
npm-debug.log
|
||||||
build/dev
|
build/dev
|
||||||
|
build/test
|
||||||
docs/*
|
docs/*
|
||||||
!docs/*.conf.json
|
!docs/*.conf.json
|
||||||
!docs/*.ico
|
!docs/*.ico
|
||||||
|
|
39
Gruntfile.js
39
Gruntfile.js
|
@ -11,7 +11,7 @@ module.exports = function(grunt) {
|
||||||
|
|
||||||
grunt.registerTask("test",
|
grunt.registerTask("test",
|
||||||
"A task which runs all the tests in test/tests.",
|
"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",
|
grunt.registerTask("prod",
|
||||||
"Creates a production-ready build. Use the --msg flag to add a compile message.",
|
"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"]);
|
["eslint", "exec:stats", "exec:displayStats"]);
|
||||||
|
|
||||||
grunt.registerTask("doc", "docs");
|
grunt.registerTask("doc", "docs");
|
||||||
|
grunt.registerTask("tests", "test");
|
||||||
grunt.registerTask("lint", "eslint");
|
grunt.registerTask("lint", "eslint");
|
||||||
|
|
||||||
|
|
||||||
|
@ -50,6 +51,7 @@ module.exports = function(grunt) {
|
||||||
grunt.loadNpmTasks("grunt-inline-alt");
|
grunt.loadNpmTasks("grunt-inline-alt");
|
||||||
grunt.loadNpmTasks("grunt-chmod");
|
grunt.loadNpmTasks("grunt-chmod");
|
||||||
grunt.loadNpmTasks("grunt-exec");
|
grunt.loadNpmTasks("grunt-exec");
|
||||||
|
grunt.loadNpmTasks("grunt-execute");
|
||||||
grunt.loadNpmTasks("grunt-contrib-watch");
|
grunt.loadNpmTasks("grunt-contrib-watch");
|
||||||
|
|
||||||
|
|
||||||
|
@ -161,22 +163,16 @@ module.exports = function(grunt) {
|
||||||
|
|
||||||
];
|
];
|
||||||
|
|
||||||
var jsAppFiles = [].concat(
|
var jsAppFiles = jsIncludes.concat([
|
||||||
jsIncludes,
|
|
||||||
[
|
|
||||||
// Start the main app!
|
// Start the main app!
|
||||||
"src/js/views/html/main.js",
|
"src/js/views/html/main.js",
|
||||||
]
|
]);
|
||||||
);
|
|
||||||
|
|
||||||
var jsTestFiles = [].concat(
|
var jsTestFiles = jsIncludes.concat([
|
||||||
jsIncludes,
|
|
||||||
[
|
|
||||||
"test/TestRegister.js",
|
"test/TestRegister.js",
|
||||||
"test/tests/**/*.js",
|
"test/tests/**/*.js",
|
||||||
"test/TestRunner.js",
|
"test/TestRunner.js",
|
||||||
]
|
]);
|
||||||
);
|
|
||||||
|
|
||||||
var banner = '/**\n\
|
var banner = '/**\n\
|
||||||
* CyberChef - The Cyber Swiss Army Knife\n\
|
* CyberChef - The Cyber Swiss Army Knife\n\
|
||||||
|
@ -218,11 +214,7 @@ module.exports = function(grunt) {
|
||||||
config: ["src/js/config/**/*.js"],
|
config: ["src/js/config/**/*.js"],
|
||||||
views: ["src/js/views/**/*.js"],
|
views: ["src/js/views/**/*.js"],
|
||||||
operations: ["src/js/operations/**/*.js"],
|
operations: ["src/js/operations/**/*.js"],
|
||||||
tests: [
|
tests: ["test/**/*.js"],
|
||||||
"test/**/*.js",
|
|
||||||
"!test/PhantomRunner.js",
|
|
||||||
"!test/NodeRunner.js",
|
|
||||||
],
|
|
||||||
},
|
},
|
||||||
jsdoc: {
|
jsdoc: {
|
||||||
options: {
|
options: {
|
||||||
|
@ -241,8 +233,8 @@ module.exports = function(grunt) {
|
||||||
},
|
},
|
||||||
clean: {
|
clean: {
|
||||||
dev: ["build/dev/*"],
|
dev: ["build/dev/*"],
|
||||||
test: ["build/test/*"],
|
|
||||||
prod: ["build/prod/*"],
|
prod: ["build/prod/*"],
|
||||||
|
test: ["build/test/*"],
|
||||||
docs: ["docs/*", "!docs/*.conf.json", "!docs/*.ico"],
|
docs: ["docs/*", "!docs/*.conf.json", "!docs/*.ico"],
|
||||||
},
|
},
|
||||||
concat: {
|
concat: {
|
||||||
|
@ -291,12 +283,7 @@ module.exports = function(grunt) {
|
||||||
dest: "build/dev/index.html"
|
dest: "build/dev/index.html"
|
||||||
},
|
},
|
||||||
htmlTest: {
|
htmlTest: {
|
||||||
options: {
|
src: "test/test.html",
|
||||||
process: function(content, srcpath) {
|
|
||||||
return grunt.template.process(content, templateOptions);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
src: "src/html/test.html",
|
|
||||||
dest: "build/test/index.html"
|
dest: "build/test/index.html"
|
||||||
},
|
},
|
||||||
htmlProd: {
|
htmlProd: {
|
||||||
|
@ -451,9 +438,6 @@ module.exports = function(grunt) {
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
exec: {
|
exec: {
|
||||||
tests: {
|
|
||||||
command: "node test/NodeRunner.js",
|
|
||||||
},
|
|
||||||
repoSize: {
|
repoSize: {
|
||||||
command: [
|
command: [
|
||||||
"git ls-files | wc -l | xargs printf '\n%b\ttracked files\n'",
|
"git ls-files | wc -l | xargs printf '\n%b\ttracked files\n'",
|
||||||
|
@ -506,6 +490,9 @@ module.exports = function(grunt) {
|
||||||
].join(";")
|
].join(";")
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
execute: {
|
||||||
|
test: "test/NodeRunner.js"
|
||||||
|
},
|
||||||
watch: {
|
watch: {
|
||||||
css: {
|
css: {
|
||||||
files: "src/css/**/*.css",
|
files: "src/css/**/*.css",
|
||||||
|
|
|
@ -37,6 +37,7 @@
|
||||||
"grunt-contrib-watch": "~1.0.0",
|
"grunt-contrib-watch": "~1.0.0",
|
||||||
"grunt-eslint": "^19.0.0",
|
"grunt-eslint": "^19.0.0",
|
||||||
"grunt-exec": "~1.0.1",
|
"grunt-exec": "~1.0.1",
|
||||||
|
"grunt-execute": "^0.2.2",
|
||||||
"grunt-inline-alt": "~0.3.10",
|
"grunt-inline-alt": "~0.3.10",
|
||||||
"grunt-jsdoc": "^2.1.0",
|
"grunt-jsdoc": "^2.1.0",
|
||||||
"ink-docstrap": "^1.1.4",
|
"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
|
* NodeRunner.js
|
||||||
*
|
*
|
||||||
* The purpose of this file is to execute via PhantomJS the file
|
* The purpose of this file is to execute via PhantomJS the file
|
||||||
* PhantomRunner.js, because PhantomJS is managed by node.
|
* PhantomRunner.js, because PhantomJS is managed by node.
|
||||||
*
|
*
|
||||||
* @author tlwr [toby@toby.codes
|
* @author tlwr [toby@toby.codes]
|
||||||
*
|
|
||||||
* @copyright Crown Copyright 2017
|
* @copyright Crown Copyright 2017
|
||||||
* @license Apache-2.0
|
* @license Apache-2.0
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
var path = require("path");
|
|
||||||
var phantomjs = require("phantomjs-prebuilt");
|
|
||||||
|
|
||||||
var phantomEntryPoint = path.join(__dirname, "PhantomRunner.js");
|
var path = require("path"),
|
||||||
var program = phantomjs.exec(phantomEntryPoint);
|
phantomjs = require("phantomjs-prebuilt"),
|
||||||
|
phantomEntryPoint = path.join(__dirname, "PhantomRunner.js"),
|
||||||
|
program = phantomjs.exec(phantomEntryPoint);
|
||||||
|
|
||||||
program.stdout.pipe(process.stdout);
|
program.stdout.pipe(process.stdout);
|
||||||
program.stderr.pipe(process.stderr);
|
program.stderr.pipe(process.stderr);
|
||||||
|
|
|
@ -1,21 +1,29 @@
|
||||||
|
/* eslint-env node */
|
||||||
|
/* globals phantom */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* PhantomRunner.js
|
* PhantomRunner.js
|
||||||
*
|
*
|
||||||
* This file navigates to build/test/index.html and logs the test results.
|
* 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
|
* @copyright Crown Copyright 2017
|
||||||
* @license Apache-2.0
|
* @license Apache-2.0
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
var page = require("webpage").create();
|
|
||||||
|
|
||||||
var allTestsPassing = true;
|
var page = require("webpage").create(),
|
||||||
var testStatusCounts = {
|
allTestsPassing = true,
|
||||||
|
testStatusCounts = {
|
||||||
total: 0,
|
total: 0,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Helper function to convert a status to an icon.
|
||||||
|
*
|
||||||
|
* @param {string} status
|
||||||
|
* @returns {string}
|
||||||
|
*/
|
||||||
function statusToIcon(status) {
|
function statusToIcon(status) {
|
||||||
var icons = {
|
var icons = {
|
||||||
erroring: "🔥",
|
erroring: "🔥",
|
||||||
|
@ -25,6 +33,10 @@ function statusToIcon(status) {
|
||||||
return icons[status] || "?";
|
return icons[status] || "?";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Callback function to handle test results.
|
||||||
|
*/
|
||||||
page.onCallback = function(messageType) {
|
page.onCallback = function(messageType) {
|
||||||
if (messageType === "testResult") {
|
if (messageType === "testResult") {
|
||||||
var testResult = arguments[1];
|
var testResult = arguments[1];
|
||||||
|
@ -59,22 +71,29 @@ page.onCallback = function(messageType) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!allTestsPassing) {
|
if (!allTestsPassing) {
|
||||||
console.log("\n")
|
console.log("\nNot all tests are passing");
|
||||||
console.log("Not all tests are passing");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
phantom.exit(allTestsPassing ? 0 : 1);
|
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") {
|
if (status !== "success") {
|
||||||
console.log("STATUS", status);
|
console.log("STATUS: ", status);
|
||||||
phantom.exit(1);
|
phantom.exit(1);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Fail if the process takes longer than 10 seconds.
|
||||||
|
*/
|
||||||
setTimeout(function() {
|
setTimeout(function() {
|
||||||
// Timeout
|
console.log("Tests took longer than 10 seconds to run, returning.");
|
||||||
phantom.exit(1);
|
phantom.exit(1);
|
||||||
}, 10 * 1000);
|
}, 10 * 1000);
|
||||||
|
|
|
@ -4,22 +4,23 @@
|
||||||
* This is so individual files can register their tests in one place, and
|
* This is so individual files can register their tests in one place, and
|
||||||
* ensure that they will get run by the frontend.
|
* ensure that they will get run by the frontend.
|
||||||
*
|
*
|
||||||
* @author tlwr [toby@toby.codes
|
* @author tlwr [toby@toby.codes]
|
||||||
*
|
|
||||||
* @copyright Crown Copyright 2017
|
* @copyright Crown Copyright 2017
|
||||||
* @license Apache-2.0
|
* @license Apache-2.0
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
(function() {
|
(function() {
|
||||||
/**
|
/**
|
||||||
* Add a list of tests to the register.
|
* Object to store and run the list of tests.
|
||||||
*
|
*
|
||||||
* @class
|
* @class
|
||||||
|
* @constructor
|
||||||
*/
|
*/
|
||||||
function TestRegister() {
|
function TestRegister() {
|
||||||
this.tests = [];
|
this.tests = [];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add a list of tests to the register.
|
* Add a list of tests to the register.
|
||||||
*
|
*
|
||||||
|
@ -29,18 +30,9 @@
|
||||||
this.tests = this.tests.concat(tests);
|
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.
|
* Runs all the tests in the register.
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
TestRegister.prototype.runTests = function() {
|
TestRegister.prototype.runTests = function() {
|
||||||
return Promise.all(
|
return Promise.all(
|
||||||
|
@ -52,7 +44,7 @@
|
||||||
test.recipeConfig,
|
test.recipeConfig,
|
||||||
{},
|
{},
|
||||||
0,
|
0,
|
||||||
0
|
false
|
||||||
))
|
))
|
||||||
.then(function(result) {
|
.then(function(result) {
|
||||||
var ret = {
|
var ret = {
|
||||||
|
@ -91,6 +83,7 @@
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
// Singleton TestRegister, keeping things simple and obvious.
|
// Singleton TestRegister, keeping things simple and obvious.
|
||||||
window.TestRegister = new TestRegister();
|
window.TestRegister = new TestRegister();
|
||||||
})();
|
})();
|
||||||
|
|
|
@ -3,30 +3,31 @@
|
||||||
*
|
*
|
||||||
* This is for actually running the tests in the test register.
|
* 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
|
* @copyright Crown Copyright 2017
|
||||||
* @license Apache-2.0
|
* @license Apache-2.0
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
(function() {
|
|
||||||
document.addEventListener("DOMContentLoaded", function() {
|
document.addEventListener("DOMContentLoaded", function() {
|
||||||
TestRegister.runTests()
|
TestRegister.runTests()
|
||||||
.then(function(results) {
|
.then(function(results) {
|
||||||
results.forEach(function(testResult) {
|
results.forEach(function(testResult) {
|
||||||
|
|
||||||
if (typeof window.callPhantom === "function") {
|
if (typeof window.callPhantom === "function") {
|
||||||
|
// If we're running this in PhantomJS
|
||||||
window.callPhantom(
|
window.callPhantom(
|
||||||
"testResult",
|
"testResult",
|
||||||
testResult
|
testResult
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
|
// If we're just viewing this in a normal browser
|
||||||
var output = [
|
var output = [
|
||||||
"----------",
|
"----------",
|
||||||
testResult.test.name,
|
testResult.test.name,
|
||||||
testResult.status,
|
testResult.status,
|
||||||
testResult.output,
|
testResult.output,
|
||||||
].join("<br>");
|
].join("<br>");
|
||||||
document.body.innerHTML += "<div>" + output + "</div>";
|
document.querySelector("main").innerHTML += output;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -34,5 +35,4 @@
|
||||||
window.callPhantom("exit");
|
window.callPhantom("exit");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
})();
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
<!-- htmlmin:ignore --><!--
|
<!--
|
||||||
CyberChef - The Cyber Swiss Army Knife
|
CyberChef test suite
|
||||||
|
|
||||||
@author tlwr [toby@toby.codes]
|
@author tlwr [toby@toby.codes]
|
||||||
|
|
||||||
|
@ -20,12 +20,11 @@
|
||||||
See the License for the specific language governing permissions and
|
See the License for the specific language governing permissions and
|
||||||
limitations under the License.
|
limitations under the License.
|
||||||
-->
|
-->
|
||||||
<!-- htmlmin:ignore -->
|
|
||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<html>
|
<html>
|
||||||
<head>
|
<head>
|
||||||
<meta charset="UTF-8">
|
<meta charset="UTF-8">
|
||||||
<title>CyberChef</title>
|
<title>CyberChef test suite</title>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<main style="white-space: pre"></main>
|
<main style="white-space: pre"></main>
|
|
@ -1,11 +1,10 @@
|
||||||
/**
|
/**
|
||||||
* Base58 tests.
|
* Base58 tests.
|
||||||
*
|
*
|
||||||
* @author tlwr [toby@toby.codes
|
* @author tlwr [toby@toby.codes]
|
||||||
*
|
*
|
||||||
* @copyright Crown Copyright 2017
|
* @copyright Crown Copyright 2017
|
||||||
* @license Apache-2.0
|
* @license Apache-2.0
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
TestRegister.addTests([
|
TestRegister.addTests([
|
||||||
{
|
{
|
||||||
|
|
|
@ -1,52 +1,12 @@
|
||||||
/**
|
/**
|
||||||
* Core tests.
|
* Flow Control tests.
|
||||||
|
*
|
||||||
|
* @author tlwr [toby@toby.codes]
|
||||||
*
|
*
|
||||||
* @copyright Crown Copyright 2017
|
* @copyright Crown Copyright 2017
|
||||||
* @license Apache-2.0
|
* @license Apache-2.0
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
TestRegister.addTests([
|
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",
|
name: "Fork: nothing",
|
||||||
input: "",
|
input: "",
|
|
@ -1,11 +1,10 @@
|
||||||
/**
|
/**
|
||||||
* Base58 tests.
|
* Base58 tests.
|
||||||
*
|
*
|
||||||
* @author tlwr [toby@toby.codes
|
* @author tlwr [toby@toby.codes]
|
||||||
*
|
*
|
||||||
* @copyright Crown Copyright 2017
|
* @copyright Crown Copyright 2017
|
||||||
* @license Apache-2.0
|
* @license Apache-2.0
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
TestRegister.addTests([
|
TestRegister.addTests([
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in a new issue