From 9d674ce5a70f1b4d435899047d8982af9ffaff00 Mon Sep 17 00:00:00 2001 From: d98762625 Date: Fri, 4 Jan 2019 12:14:02 +0000 Subject: [PATCH] move node test suite into its own grunt command --- Gruntfile.js | 12 ++-- test/tests/assertionHandler.mjs | 60 ------------------ test/tests/nodeApi/sampleData/pic.jpg | Bin 4724 -> 0 bytes tests/lib/utils.mjs | 3 - tests/node/assertionHandler.mjs | 60 ++++++++++++++++++ tests/node/index.mjs | 47 ++++++++++++++ .../nodeApi => tests/node/tests}/nodeApi.mjs | 2 +- .../nodeApi => tests/node/tests}/ops.mjs | 2 +- tests/operations/index.mjs | 3 +- 9 files changed, 116 insertions(+), 73 deletions(-) delete mode 100644 test/tests/assertionHandler.mjs delete mode 100644 test/tests/nodeApi/sampleData/pic.jpg rename {test/tests/nodeApi => tests/node/tests}/nodeApi.mjs (99%) rename {test/tests/nodeApi => tests/node/tests}/ops.mjs (99%) 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 05c213276a58543c5cdbfb60e7831c35b8eaf017..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 4724 zcmeHJX;c$g8hzOei#CgZw6up18bQE>MbIFDMi3ANP*xQr9UwqN2%Q8HQIf$H5!;QW zRWdFtDj;@8Mchy#ilDR#D99obf`Aeh11f|q)fJl2b7ubZnZLuWI#su-zVCbQ-d9!U zgW8~Opy}nl$sHgN0C>V1fF$7XMlL-X03RP<4ggRA7=$)J!3+U!0I?ik<~RUe2!k)& zA7M5hg9IRh4$$*4+u^ekaAjro{27&x_*yX^`6Zf^kNV1$X^=$KD3;AmbRZHFSOjVm zBZ5YVWW*D>)I_2+!HNhRowPM)#?#nT95;Sf0?UC*#?KXZfVuKE5s#Y-VaJj2TYWa; zTp3In&W^B#V1I9bYzbm-WSdmP6BAd=gz$q(IBN$0+G9FKaM5t>V#X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8Sd@~hMGf5= z^E%5?N6YN}rrDJ@a-Lf>5JVB;_QHv3J;QGj_UfYKd%T+ocHW`H8{wFvV*`4ms4mlw z-}G%X@YdDWM^;@ZtU8IR-RtsmfuH*Rx}fxRPO-IiruvTtFZM|Y_tEqWif1S(F%cs7iuY=>}%k^%amv)&(QxN1R5$P zjC;g#PVrDG1l&emLjd&w0+aYVVh!FSQMpGto1!V-<01>x6YvjRetV@w68cB&GW#a4 zm2M`*mZ!2@X=-O3df+)1V9d jyqJUByY+Xa%_%HjU;k_E;Xe14P<^e!t^|jBK<$45ODl-$ 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();