Skip to content

Commit

Permalink
Convert test runner to headless
Browse files Browse the repository at this point in the history
  • Loading branch information
tlwr committed Feb 24, 2017
1 parent 04df7a5 commit 3a90244
Show file tree
Hide file tree
Showing 14 changed files with 1,466 additions and 318 deletions.
64 changes: 20 additions & 44 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ module.exports = function(grunt) {
["clean:dev", "concat:css", "concat:js", "copy:htmlDev", "copy:staticDev", "chmod:build", "watch"]);

grunt.registerTask("test",
"A persistent task which creates a test build whenever source files are modified.",
["clean:dev", "concat:cssTest", "concat:jsTest", "copy:htmlTest", "copy:staticTest", "chmod:build", "watch"]);
"A task which runs all the tests in test/tests.",
["clean:test", "concat:jsTest", "copy:htmlTest", "chmod:build", "exec:tests"]);

grunt.registerTask("prod",
"Creates a production-ready build. Use the --msg flag to add a compile message.",
["eslint", "exec:stats", "clean", "jsdoc", "concat", "copy:htmlDev", "copy:htmlProd", "copy:htmlInline",
"copy:staticDev", "copy:staticProd", "cssmin", "uglify:prod", "inline", "htmlmin", "chmod"]);
"copy:staticDev", "copy:staticProd", "cssmin", "uglify:prod", "inline", "htmlmin", "chmod", "test"]);

grunt.registerTask("docs",
"Compiles documentation in the /docs directory.",
Expand Down Expand Up @@ -138,6 +138,7 @@ module.exports = function(grunt) {
"src/js/lib/vkbeautify.js",
"src/js/lib/Sortable.js",
"src/js/lib/bootstrap-colorpicker.js",
"src/js/lib/es6-promise.auto.js",
"src/js/lib/xpath.js",

// Custom libraries
Expand Down Expand Up @@ -171,11 +172,9 @@ module.exports = function(grunt) {
var jsTestFiles = [].concat(
jsIncludes,
[
"src/js/lib/vuejs/vue.min.js",
"src/js/test/*.js",
"src/js/test/tests/**/*",
// Start the test runner app!
"src/js/test/views/html/main.js",
"test/TestRegister.js",
"test/tests/**/*.js",
"test/TestRunner.js",
]
);

Expand Down Expand Up @@ -219,7 +218,11 @@ module.exports = function(grunt) {
config: ["src/js/config/**/*.js"],
views: ["src/js/views/**/*.js"],
operations: ["src/js/operations/**/*.js"],
tests: ["src/js/test/**/*.js"],
tests: [
"test/**/*.js",
"!test/PhantomRunner.js",
"!test/NodeRunner.js",
],
},
jsdoc: {
options: {
Expand All @@ -238,6 +241,7 @@ module.exports = function(grunt) {
},
clean: {
dev: ["build/dev/*"],
test: ["build/test/*"],
prod: ["build/prod/*"],
docs: ["docs/*", "!docs/*.conf.json", "!docs/*.ico"],
},
Expand All @@ -261,22 +265,6 @@ module.exports = function(grunt) {
],
dest: "build/dev/styles.css"
},
cssTest: {
options: {
banner: banner.replace(/\/\*\*/g, "/*!"),
process: function(content, srcpath) {
// Change special comments from /** to /*! to comply with cssmin
content = content.replace(/^\/\*\* /g, "/*! ");
return grunt.template.process(content);
}
},
src: [
"src/css/lib/**/*.css",
"src/css/structure/**/*.css",
"src/css/themes/classic.css"
],
dest: "build/test/styles.css"
},
js: {
options: {
banner: '"use strict";\n'
Expand All @@ -289,7 +277,7 @@ module.exports = function(grunt) {
banner: '"use strict";\n'
},
src: jsTestFiles,
dest: "build/test/scripts.js"
dest: "build/test/tests.js"
}
},
copy: {
Expand Down Expand Up @@ -348,21 +336,6 @@ module.exports = function(grunt) {
}
]
},
staticTest: {
files: [
{
expand: true,
cwd: "src/static/",
src: [
"**/*",
"**/.*",
"!stats.txt",
"!ga.html"
],
dest: "build/test/"
}
]
},
staticProd: {
files: [
{
Expand Down Expand Up @@ -478,6 +451,9 @@ 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'",
Expand Down Expand Up @@ -537,15 +513,15 @@ module.exports = function(grunt) {
},
js: {
files: "src/js/**/*.js",
tasks: ["concat:js", "concat:jsTest", "chmod:build"]
tasks: ["concat:js", "chmod:build"]
},
html: {
files: "src/html/**/*.html",
tasks: ["copy:htmlDev", "copy:htmlTest", "chmod:build"]
tasks: ["copy:htmlDev", "chmod:build"]
},
static: {
files: ["src/static/**/*", "src/static/**/.*"],
tasks: ["copy:staticDev", "copy:staticTest", "chmod:build"]
tasks: ["copy:staticDev", "chmod:build"]
},
grunt: {
files: "Gruntfile.js",
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
"grunt-exec": "~1.0.1",
"grunt-inline-alt": "~0.3.10",
"grunt-jsdoc": "^2.1.0",
"ink-docstrap": "^1.1.4"
"ink-docstrap": "^1.1.4",
"phantomjs-prebuilt": "^2.1.14"
}
}
68 changes: 3 additions & 65 deletions src/html/test.html
Original file line number Diff line number Diff line change
Expand Up @@ -25,72 +25,10 @@
<html>
<head>
<meta charset="UTF-8">
<title>CyberChef Test Runner</title>
<link rel="icon" type="image/png" href="images/favicon.ico?__inline" />
<link href="styles.css" rel="stylesheet" />
<title>CyberChef</title>
</head>
<body>
<template id="test-status-icon-template">
<span>{{ getIcon() }}</span>
</template>

<template id="test-stats-template">
<div class="text-center row">
<div class="col-md-2"
v-for="status in ['Waiting', 'Loading', 'Erroring', 'Failing']">
<test-status-icon :status="status.toLowerCase()"></test-status-icon>
<br>
{{ status }}
<br>
{{ countTestsWithStatus(status.toLowerCase()) }}
</div>
<div class="col-md-2">
<test-status-icon status="passing"></test-status-icon>
<br>
Passing
<br>
{{ countTestsWithStatus("passing") }}
/
{{ tests.length }}
</div>
<div class="col-md-2">
<test-status-icon status="passing"></test-status-icon>
<br>
% Passing
<br>
{{ ((100.0 * countTestsWithStatus("passing")) / tests.length).toFixed(1) }}%
</div>
</div>
</template>

<template id="tests-template">
<table class="table table-striped">
<tbody>
<tr v-for="test in tests">
<td class="col-md-1 col-sm-4">
<test-status-icon :status="test.status"></test-status-icon>
</td>
<td class="col-md-4 col-sm-8">
{{ test.name }}
</td>
<td class="col-md-7 col-sm-12">
<pre v-if="test.output"><code>{{ test.output }}</code></pre>
</td>
</tr>
</tbody>
</table>
</template>

<div class="container">
<main>
<h1>CyberChef Test Runner</h1>
<hr>
<test-stats :tests="tests"></test-stats>
<hr>
<tests :tests="tests"></tests>
</main>
</div>

<script type="application/javascript" src="scripts.js"></script>
<main style="white-space: pre"></main>
<script type="application/javascript" src="tests.js"></script>
</body>
</html>
6 changes: 3 additions & 3 deletions src/js/.eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,8 @@
"SeasonalWaiter": false,
"WindowWaiter": false,

/* test */
"Vue": false,
"TestRegister": false
/* tests */
"TestRegister": false,
"TestRunner": false
}
}
Loading

0 comments on commit 3a90244

Please sign in to comment.