mirror of
https://github.com/gchq/CyberChef
synced 2024-11-15 00:57:08 +00:00
move node test suite into its own grunt command
This commit is contained in:
parent
f22e9ceec6
commit
9d674ce5a7
9 changed files with 116 additions and 73 deletions
12
Gruntfile.js
12
Gruntfile.js
|
@ -38,9 +38,9 @@ module.exports = function (grunt) {
|
|||
"A task which runs all the UI tests in the tests directory. The prod task must already have been run.",
|
||||
["connect:prod", "exec:browserTests"]);
|
||||
|
||||
// grunt.registerTask("testnode",
|
||||
// "Run all the node tests in the tests directory",
|
||||
// ["clean", "exec:generateConfig", "exec:generateNodeIndex", "exec:generateConfig", "exec:nodeTests"]);
|
||||
grunt.registerTask("test-node",
|
||||
"Run all the node tests in the tests directory",
|
||||
["clean", "exec:generateConfig", "exec:generateNodeIndex", "exec:generateConfig", "exec:nodeTests"]);
|
||||
|
||||
grunt.registerTask("docs",
|
||||
"Compiles documentation in the /docs directory.",
|
||||
|
@ -481,9 +481,9 @@ module.exports = function (grunt) {
|
|||
browserTests: {
|
||||
command: "./node_modules/.bin/nightwatch --env prod,inline"
|
||||
},
|
||||
// nodeTests: {
|
||||
// command: "node --experimental-modules --no-warnings --no-deprecation tests/node/index.mjs"
|
||||
// }
|
||||
nodeTests: {
|
||||
command: "node --experimental-modules --no-warnings --no-deprecation tests/node/index.mjs"
|
||||
}
|
||||
},
|
||||
});
|
||||
};
|
||||
|
|
|
@ -1,60 +0,0 @@
|
|||
/**
|
||||
* assertionHandler.mjs
|
||||
*
|
||||
* Pair native node assertions with a description for
|
||||
* the benefit of the TestRegister.
|
||||
*
|
||||
* @author d98762625 [d98762625@gmail.com]
|
||||
* @copyright Crown Copyright 2018
|
||||
* @license Apache-2.0
|
||||
*/
|
||||
|
||||
/* eslint no-console: 0 */
|
||||
|
||||
|
||||
/**
|
||||
* Print useful stack on error
|
||||
*/
|
||||
const wrapRun = (run) => () => {
|
||||
try {
|
||||
run();
|
||||
} catch (e) {
|
||||
console.dir(e);
|
||||
throw e;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* it - wrapper for assertions to provide a helpful description
|
||||
* to the TestRegister
|
||||
* @namespace ApiTests
|
||||
* @param {String} description - The description of the test
|
||||
* @param {Function} assertion - The test
|
||||
*
|
||||
* @example
|
||||
* // One assertion
|
||||
* it("should run one assertion", () => assert.equal(1,1))
|
||||
*
|
||||
* @example
|
||||
* // multiple assertions
|
||||
* it("should handle multiple assertions", () => {
|
||||
* assert.equal(1,1)
|
||||
* assert.notEqual(3,4)
|
||||
* })
|
||||
*
|
||||
* @example
|
||||
* // async assertions
|
||||
* it("should handle async", async () => {
|
||||
* let r = await asyncFunc()
|
||||
* assert(r)
|
||||
* })
|
||||
*/
|
||||
export function it(name, run) {
|
||||
return {
|
||||
name: `Node API: ${name}`,
|
||||
run: wrapRun(run),
|
||||
};
|
||||
}
|
||||
|
||||
export default it;
|
Binary file not shown.
Before Width: | Height: | Size: 4.6 KiB |
|
@ -84,9 +84,6 @@ export function logTestReport(testStatus, results) {
|
|||
results.filter(r => r.status !== "passing").forEach(handleTestResult);
|
||||
}
|
||||
|
||||
|
||||
console.log(`Tests took ${(testStatus.finish - testStatus.start) / 1000} seconds`);
|
||||
|
||||
process.exit(testStatus.allTestsPassing ? 0 : 1);
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,60 @@
|
|||
/**
|
||||
* assertionHandler.mjs
|
||||
*
|
||||
* Pair native node assertions with a description for
|
||||
* the benefit of the TestRegister.
|
||||
*
|
||||
* @author d98762625 [d98762625@gmail.com]
|
||||
* @copyright Crown Copyright 2019
|
||||
* @license Apache-2.0
|
||||
*/
|
||||
|
||||
/* eslint no-console: 0 */
|
||||
|
||||
|
||||
/**
|
||||
* Print useful stack on error
|
||||
*/
|
||||
const wrapRun = (run) => () => {
|
||||
try {
|
||||
run();
|
||||
} catch (e) {
|
||||
console.dir(e);
|
||||
throw e;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* it - wrapper for assertions to provide a helpful description
|
||||
* to the TestRegister
|
||||
* @namespace ApiTests
|
||||
* @param {String} description - The description of the test
|
||||
* @param {Function} assertion - The test
|
||||
*
|
||||
* @example
|
||||
* // One assertion
|
||||
* it("should run one assertion", () => assert.equal(1,1))
|
||||
*
|
||||
* @example
|
||||
* // multiple assertions
|
||||
* it("should handle multiple assertions", () => {
|
||||
* assert.equal(1,1)
|
||||
* assert.notEqual(3,4)
|
||||
* })
|
||||
*
|
||||
* @example
|
||||
* // async assertions
|
||||
* it("should handle async", async () => {
|
||||
* let r = await asyncFunc()
|
||||
* assert(r)
|
||||
* })
|
||||
*/
|
||||
export function it(name, run) {
|
||||
return {
|
||||
name: `Node API: ${name}`,
|
||||
run: wrapRun(run),
|
||||
};
|
||||
}
|
||||
|
||||
export default it;
|
|
@ -0,0 +1,47 @@
|
|||
/* eslint no-console: 0 */
|
||||
|
||||
/**
|
||||
* Node API Test Runner
|
||||
*
|
||||
* @author d98762625 [d98762625@gmail.com]
|
||||
* @author tlwr [toby@toby.codes]
|
||||
* @author n1474335 [n1474335@gmail.com]
|
||||
* @copyright Crown Copyright 2018
|
||||
* @license Apache-2.0
|
||||
*/
|
||||
import "babel-polyfill";
|
||||
|
||||
import {
|
||||
setLongTestFailure,
|
||||
logTestReport,
|
||||
} from "../lib/utils";
|
||||
|
||||
// Define global environment functions
|
||||
global.ENVIRONMENT_IS_WORKER = function() {
|
||||
return typeof importScripts === "function";
|
||||
};
|
||||
global.ENVIRONMENT_IS_NODE = function() {
|
||||
return typeof process === "object" && typeof require === "function";
|
||||
};
|
||||
global.ENVIRONMENT_IS_WEB = function() {
|
||||
return typeof window === "object";
|
||||
};
|
||||
|
||||
import TestRegister from "../lib/TestRegister";
|
||||
import "./tests/nodeApi";
|
||||
import "./tests/ops";
|
||||
|
||||
const testStatus = {
|
||||
allTestsPassing: true,
|
||||
counts: {
|
||||
total: 0,
|
||||
}
|
||||
};
|
||||
|
||||
setLongTestFailure();
|
||||
|
||||
const logOpsTestReport = logTestReport.bind(null, testStatus);
|
||||
|
||||
TestRegister.runApiTests()
|
||||
.then(logOpsTestReport);
|
||||
|
|
@ -18,7 +18,7 @@ import SyncDish from "../../../src/node/SyncDish";
|
|||
import fs from "fs";
|
||||
|
||||
import { toBase32, Dish, SHA3 } from "../../../src/node/index";
|
||||
import TestRegister from "../../TestRegister";
|
||||
import TestRegister from "../../lib/TestRegister";
|
||||
|
||||
TestRegister.addApiTests([
|
||||
it("should have some operations", () => {
|
|
@ -34,7 +34,7 @@ import {
|
|||
toHex,
|
||||
} from "../../../src/node/index";
|
||||
import chef from "../../../src/node/index";
|
||||
import TestRegister from "../../TestRegister";
|
||||
import TestRegister from "../../lib/TestRegister";
|
||||
|
||||
TestRegister.addApiTests([
|
||||
|
|
@ -98,8 +98,7 @@ const testStatus = {
|
|||
allTestsPassing: true,
|
||||
counts: {
|
||||
total: 0,
|
||||
},
|
||||
start: new Date(),
|
||||
}
|
||||
};
|
||||
|
||||
setLongTestFailure();
|
||||
|
|
Loading…
Reference in a new issue