move node test suite into its own grunt command

This commit is contained in:
d98762625 2019-01-04 12:14:02 +00:00
parent f22e9ceec6
commit 9d674ce5a7
9 changed files with 116 additions and 73 deletions

View file

@ -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.", "A task which runs all the UI tests in the tests directory. The prod task must already have been run.",
["connect:prod", "exec:browserTests"]); ["connect:prod", "exec:browserTests"]);
// grunt.registerTask("testnode", grunt.registerTask("test-node",
// "Run all the node tests in the tests directory", "Run all the node tests in the tests directory",
// ["clean", "exec:generateConfig", "exec:generateNodeIndex", "exec:generateConfig", "exec:nodeTests"]); ["clean", "exec:generateConfig", "exec:generateNodeIndex", "exec:generateConfig", "exec:nodeTests"]);
grunt.registerTask("docs", grunt.registerTask("docs",
"Compiles documentation in the /docs directory.", "Compiles documentation in the /docs directory.",
@ -481,9 +481,9 @@ module.exports = function (grunt) {
browserTests: { browserTests: {
command: "./node_modules/.bin/nightwatch --env prod,inline" command: "./node_modules/.bin/nightwatch --env prod,inline"
}, },
// nodeTests: { nodeTests: {
// command: "node --experimental-modules --no-warnings --no-deprecation tests/node/index.mjs" command: "node --experimental-modules --no-warnings --no-deprecation tests/node/index.mjs"
// } }
}, },
}); });
}; };

View file

@ -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

View file

@ -84,9 +84,6 @@ export function logTestReport(testStatus, results) {
results.filter(r => r.status !== "passing").forEach(handleTestResult); results.filter(r => r.status !== "passing").forEach(handleTestResult);
} }
console.log(`Tests took ${(testStatus.finish - testStatus.start) / 1000} seconds`);
process.exit(testStatus.allTestsPassing ? 0 : 1); process.exit(testStatus.allTestsPassing ? 0 : 1);
} }

View file

@ -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;

View file

@ -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);

View file

@ -18,7 +18,7 @@ import SyncDish from "../../../src/node/SyncDish";
import fs from "fs"; import fs from "fs";
import { toBase32, Dish, SHA3 } from "../../../src/node/index"; import { toBase32, Dish, SHA3 } from "../../../src/node/index";
import TestRegister from "../../TestRegister"; import TestRegister from "../../lib/TestRegister";
TestRegister.addApiTests([ TestRegister.addApiTests([
it("should have some operations", () => { it("should have some operations", () => {

View file

@ -34,7 +34,7 @@ import {
toHex, toHex,
} from "../../../src/node/index"; } from "../../../src/node/index";
import chef from "../../../src/node/index"; import chef from "../../../src/node/index";
import TestRegister from "../../TestRegister"; import TestRegister from "../../lib/TestRegister";
TestRegister.addApiTests([ TestRegister.addApiTests([

View file

@ -98,8 +98,7 @@ const testStatus = {
allTestsPassing: true, allTestsPassing: true,
counts: { counts: {
total: 0, total: 0,
}, }
start: new Date(),
}; };
setLongTestFailure(); setLongTestFailure();