Преглед на файлове

move node test suite into its own grunt command

d98762625 преди 6 години
родител
ревизия
9d674ce5a7

+ 6 - 6
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.",
         "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",
-    //     "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",
     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: {
-            //     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"
+            }
         },
         },
     });
     });
 };
 };

+ 0 - 60
test/tests/assertionHandler.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;

BIN
test/tests/nodeApi/sampleData/pic.jpg


+ 0 - 3
tests/lib/utils.mjs

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

+ 60 - 0
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;

+ 47 - 0
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);
+

+ 1 - 1
test/tests/nodeApi/nodeApi.mjs → tests/node/tests/nodeApi.mjs

@@ -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", () => {

+ 1 - 1
test/tests/nodeApi/ops.mjs → tests/node/tests/ops.mjs

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

+ 1 - 2
tests/operations/index.mjs

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