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 zcmex=Bm<7<_#hv=|r|I2c$Ng&3F_7#J8C z7#SECr5ISjYz77|Mrk-Zh*1NohKYfpJ(Gb2swRp70z9C62+h2J5vrPzfnfm?T(#u_ zW&|6g@&7|k#f*}Y0xNy}ykfn?l>DSrz2y8{{ffi_eM3D1eFhu*ih{)C?9>v4q}24x zJX@vryZ0+8WTx0Eg`4^s_!c;)W@LI)6{QAO`Gq7`WhYyvDB0U7*i=|mnkaMm6T-LDnRtPXT0NVp4u-iLH{7zMX=NK1d+Q#SO#+I|Sq?JB3j&8UmvsFd71*Aut*OqaiTz zLIBa)NzF^KRVr7qw`2JKmcb$*BfliSI3vG6!C23L!NSSYmj%=SV_<-=RY6TD27xQG zJvaLqHnF^H;GFU1hg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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();