diff --git a/Gruntfile.js b/Gruntfile.js index 382cdde8..3161b646 100755 --- a/Gruntfile.js +++ b/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" + } }, }); }; diff --git a/test/tests/assertionHandler.mjs b/test/tests/assertionHandler.mjs deleted file mode 100644 index bf3da89c..00000000 --- a/test/tests/assertionHandler.mjs +++ /dev/null @@ -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; diff --git a/test/tests/nodeApi/sampleData/pic.jpg b/test/tests/nodeApi/sampleData/pic.jpg deleted file mode 100644 index 05c21327..00000000 Binary files a/test/tests/nodeApi/sampleData/pic.jpg and /dev/null differ diff --git a/tests/lib/utils.mjs b/tests/lib/utils.mjs index 10e60c10..241a72fc 100644 --- a/tests/lib/utils.mjs +++ b/tests/lib/utils.mjs @@ -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); } diff --git a/tests/node/assertionHandler.mjs b/tests/node/assertionHandler.mjs index e69de29b..0096db42 100644 --- a/tests/node/assertionHandler.mjs +++ b/tests/node/assertionHandler.mjs @@ -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; diff --git a/tests/node/index.mjs b/tests/node/index.mjs index e69de29b..112525cc 100644 --- a/tests/node/index.mjs +++ b/tests/node/index.mjs @@ -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); + diff --git a/test/tests/nodeApi/nodeApi.mjs b/tests/node/tests/nodeApi.mjs similarity index 99% rename from test/tests/nodeApi/nodeApi.mjs rename to tests/node/tests/nodeApi.mjs index 7069d2e3..7604ae13 100644 --- a/test/tests/nodeApi/nodeApi.mjs +++ b/tests/node/tests/nodeApi.mjs @@ -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", () => { diff --git a/test/tests/nodeApi/ops.mjs b/tests/node/tests/ops.mjs similarity index 99% rename from test/tests/nodeApi/ops.mjs rename to tests/node/tests/ops.mjs index c57a8d8a..8d05f8c3 100644 --- a/test/tests/nodeApi/ops.mjs +++ b/tests/node/tests/ops.mjs @@ -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([ diff --git a/tests/operations/index.mjs b/tests/operations/index.mjs index 065ac9fb..196d0dad 100644 --- a/tests/operations/index.mjs +++ b/tests/operations/index.mjs @@ -98,8 +98,7 @@ const testStatus = { allTestsPassing: true, counts: { total: 0, - }, - start: new Date(), + } }; setLongTestFailure();