Browse Source

Merge branch 'node-lib-tests' into node-lib

d98762625 6 years ago
parent
commit
6ca78ce8cb
68 changed files with 263 additions and 182 deletions
  1. 6 6
      Gruntfile.js
  2. 32 32
      package-lock.json
  3. BIN
      test/tests/nodeApi/sampleData/pic.jpg
  4. 1 0
      tests/lib/TestRegister.mjs
  5. 99 0
      tests/lib/utils.mjs
  6. 1 1
      tests/node/assertionHandler.mjs
  7. 47 0
      tests/node/index.mjs
  8. 1 1
      tests/node/tests/nodeApi.mjs
  9. 1 1
      tests/node/tests/ops.mjs
  10. 17 83
      tests/operations/index.mjs
  11. 1 1
      tests/operations/tests/BCD.mjs
  12. 1 1
      tests/operations/tests/BSON.mjs
  13. 1 1
      tests/operations/tests/Base58.mjs
  14. 1 1
      tests/operations/tests/Base62.mjs
  15. 1 1
      tests/operations/tests/Base64.mjs
  16. 1 1
      tests/operations/tests/BitwiseOp.mjs
  17. 1 1
      tests/operations/tests/ByteRepr.mjs
  18. 1 1
      tests/operations/tests/CSV.mjs
  19. 1 1
      tests/operations/tests/CartesianProduct.mjs
  20. 1 1
      tests/operations/tests/CharEnc.mjs
  21. 1 1
      tests/operations/tests/Checksum.mjs
  22. 1 1
      tests/operations/tests/Ciphers.mjs
  23. 1 1
      tests/operations/tests/Code.mjs
  24. 1 1
      tests/operations/tests/Comment.mjs
  25. 1 1
      tests/operations/tests/Compress.mjs
  26. 1 1
      tests/operations/tests/ConditionalJump.mjs
  27. 1 1
      tests/operations/tests/Crypt.mjs
  28. 1 1
      tests/operations/tests/DateTime.mjs
  29. 1 1
      tests/operations/tests/ExtractEmailAddresses.mjs
  30. 1 1
      tests/operations/tests/Fork.mjs
  31. 1 1
      tests/operations/tests/FromDecimal.mjs
  32. 1 1
      tests/operations/tests/FromGeohash.mjs
  33. 1 1
      tests/operations/tests/Hash.mjs
  34. 1 1
      tests/operations/tests/HaversineDistance.mjs
  35. 1 1
      tests/operations/tests/Hexdump.mjs
  36. 1 1
      tests/operations/tests/Image.mjs
  37. 1 1
      tests/operations/tests/JSONBeautify.mjs
  38. 1 1
      tests/operations/tests/JSONMinify.mjs
  39. 1 1
      tests/operations/tests/JWTDecode.mjs
  40. 1 1
      tests/operations/tests/JWTSign.mjs
  41. 1 1
      tests/operations/tests/JWTVerify.mjs
  42. 1 1
      tests/operations/tests/Jump.mjs
  43. 1 1
      tests/operations/tests/MS.mjs
  44. 1 1
      tests/operations/tests/Magic.mjs
  45. 1 1
      tests/operations/tests/Media.mjs
  46. 1 1
      tests/operations/tests/MorseCode.mjs
  47. 1 1
      tests/operations/tests/NetBIOS.mjs
  48. 1 1
      tests/operations/tests/OTP.mjs
  49. 1 1
      tests/operations/tests/PGP.mjs
  50. 1 1
      tests/operations/tests/PHP.mjs
  51. 1 1
      tests/operations/tests/ParseIPRange.mjs
  52. 1 1
      tests/operations/tests/ParseQRCode.mjs
  53. 1 1
      tests/operations/tests/ParseTLV.mjs
  54. 1 1
      tests/operations/tests/PowerSet.mjs
  55. 1 1
      tests/operations/tests/Regex.mjs
  56. 1 1
      tests/operations/tests/Register.mjs
  57. 1 1
      tests/operations/tests/RemoveDiacritics.mjs
  58. 1 1
      tests/operations/tests/Rotate.mjs
  59. 1 1
      tests/operations/tests/SeqUtils.mjs
  60. 1 1
      tests/operations/tests/SetDifference.mjs
  61. 1 1
      tests/operations/tests/SetIntersection.mjs
  62. 1 1
      tests/operations/tests/SetUnion.mjs
  63. 1 1
      tests/operations/tests/SplitColourChannels.mjs
  64. 1 1
      tests/operations/tests/StrUtils.mjs
  65. 1 1
      tests/operations/tests/SymmetricDifference.mjs
  66. 1 1
      tests/operations/tests/TextEncodingBruteForce.mjs
  67. 1 1
      tests/operations/tests/ToGeohash.mjs
  68. 1 1
      tests/operations/tests/TranslateDateTimeFormat.mjs

+ 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.",
         ["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"
+            }
         },
     });
 };

+ 32 - 32
package-lock.json

@@ -1774,7 +1774,7 @@
         },
         "string_decoder": {
           "version": "1.1.1",
-          "resolved": "http://registry.npmjs.org/string_decoder/-/string_decoder-1.1.1.tgz",
+          "resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-1.1.1.tgz",
           "integrity": "sha512-n/ShnvDi6FHbbVfviro+WojiFzv+s8MPMHBczVePfUpDJLwoLT0ht1l4YwBCbi8pJAveEEdnkHyPyTP/mzRfwg==",
           "dev": true,
           "requires": {
@@ -2972,7 +2972,7 @@
         },
         "string-width": {
           "version": "1.0.2",
-          "resolved": "http://registry.npmjs.org/string-width/-/string-width-1.0.2.tgz",
+          "resolved": "https://registry.npmjs.org/string-width/-/string-width-1.0.2.tgz",
           "integrity": "sha1-EYvfW4zcUaKn5w0hHgfisLmxB9M=",
           "dev": true,
           "requires": {
@@ -3498,7 +3498,7 @@
         },
         "regexpu-core": {
           "version": "1.0.0",
-          "resolved": "http://registry.npmjs.org/regexpu-core/-/regexpu-core-1.0.0.tgz",
+          "resolved": "https://registry.npmjs.org/regexpu-core/-/regexpu-core-1.0.0.tgz",
           "integrity": "sha1-hqdj9Y7k18L2sQLkdkBQ3n7ZDGs=",
           "dev": true,
           "requires": {
@@ -3515,7 +3515,7 @@
         },
         "regjsparser": {
           "version": "0.1.5",
-          "resolved": "http://registry.npmjs.org/regjsparser/-/regjsparser-0.1.5.tgz",
+          "resolved": "https://registry.npmjs.org/regjsparser/-/regjsparser-0.1.5.tgz",
           "integrity": "sha1-fuj4Tcb6eS0/0K4ijSS9lJ6tIFw=",
           "dev": true,
           "requires": {
@@ -5930,7 +5930,7 @@
         },
         "string-width": {
           "version": "1.0.2",
-          "resolved": "http://registry.npmjs.org/string-width/-/string-width-1.0.2.tgz",
+          "resolved": "https://registry.npmjs.org/string-width/-/string-width-1.0.2.tgz",
           "integrity": "sha1-EYvfW4zcUaKn5w0hHgfisLmxB9M=",
           "dev": true,
           "requires": {
@@ -6106,7 +6106,7 @@
       "dependencies": {
         "pify": {
           "version": "2.3.0",
-          "resolved": "http://registry.npmjs.org/pify/-/pify-2.3.0.tgz",
+          "resolved": "https://registry.npmjs.org/pify/-/pify-2.3.0.tgz",
           "integrity": "sha1-7RQaasBDqEnqWISY59yosVMw6Qw=",
           "dev": true
         }
@@ -6679,7 +6679,7 @@
         },
         "string_decoder": {
           "version": "1.1.1",
-          "resolved": "http://registry.npmjs.org/string_decoder/-/string_decoder-1.1.1.tgz",
+          "resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-1.1.1.tgz",
           "integrity": "sha512-n/ShnvDi6FHbbVfviro+WojiFzv+s8MPMHBczVePfUpDJLwoLT0ht1l4YwBCbi8pJAveEEdnkHyPyTP/mzRfwg==",
           "dev": true,
           "requires": {
@@ -8451,7 +8451,7 @@
     },
     "media-typer": {
       "version": "0.3.0",
-      "resolved": "http://registry.npmjs.org/media-typer/-/media-typer-0.3.0.tgz",
+      "resolved": "https://registry.npmjs.org/media-typer/-/media-typer-0.3.0.tgz",
       "integrity": "sha1-hxDXrwqmJvj/+hzgAWhUUmMlV0g=",
       "dev": true
     },
@@ -8499,7 +8499,7 @@
         },
         "string_decoder": {
           "version": "1.1.1",
-          "resolved": "http://registry.npmjs.org/string_decoder/-/string_decoder-1.1.1.tgz",
+          "resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-1.1.1.tgz",
           "integrity": "sha512-n/ShnvDi6FHbbVfviro+WojiFzv+s8MPMHBczVePfUpDJLwoLT0ht1l4YwBCbi8pJAveEEdnkHyPyTP/mzRfwg==",
           "dev": true,
           "requires": {
@@ -9016,7 +9016,7 @@
       "dependencies": {
         "semver": {
           "version": "5.3.0",
-          "resolved": "http://registry.npmjs.org/semver/-/semver-5.3.0.tgz",
+          "resolved": "https://registry.npmjs.org/semver/-/semver-5.3.0.tgz",
           "integrity": "sha1-myzl094C0XxgEq0yaqa00M9U+U8=",
           "dev": true
         }
@@ -9479,13 +9479,13 @@
     },
     "os-homedir": {
       "version": "1.0.2",
-      "resolved": "http://registry.npmjs.org/os-homedir/-/os-homedir-1.0.2.tgz",
+      "resolved": "https://registry.npmjs.org/os-homedir/-/os-homedir-1.0.2.tgz",
       "integrity": "sha1-/7xJiDNuDoM94MFox+8VISGqf7M=",
       "dev": true
     },
     "os-locale": {
       "version": "1.4.0",
-      "resolved": "http://registry.npmjs.org/os-locale/-/os-locale-1.4.0.tgz",
+      "resolved": "https://registry.npmjs.org/os-locale/-/os-locale-1.4.0.tgz",
       "integrity": "sha1-IPnxeuKe00XoveWDsT0gCYA8FNk=",
       "dev": true,
       "requires": {
@@ -9494,7 +9494,7 @@
     },
     "os-tmpdir": {
       "version": "1.0.2",
-      "resolved": "http://registry.npmjs.org/os-tmpdir/-/os-tmpdir-1.0.2.tgz",
+      "resolved": "https://registry.npmjs.org/os-tmpdir/-/os-tmpdir-1.0.2.tgz",
       "integrity": "sha1-u+Z0BseaqFxc/sdm/lc0VV36EnQ=",
       "dev": true
     },
@@ -9709,7 +9709,7 @@
     },
     "parse-asn1": {
       "version": "5.1.1",
-      "resolved": "http://registry.npmjs.org/parse-asn1/-/parse-asn1-5.1.1.tgz",
+      "resolved": "https://registry.npmjs.org/parse-asn1/-/parse-asn1-5.1.1.tgz",
       "integrity": "sha512-KPx7flKXg775zZpnp9SxJlz00gTd4BmJ2yJufSc44gMCRrRQ7NSzAcSJQfifuOLgW6bEi+ftrALtsgALeB2Adw==",
       "dev": true,
       "requires": {
@@ -9777,7 +9777,7 @@
     },
     "path-browserify": {
       "version": "0.0.0",
-      "resolved": "http://registry.npmjs.org/path-browserify/-/path-browserify-0.0.0.tgz",
+      "resolved": "https://registry.npmjs.org/path-browserify/-/path-browserify-0.0.0.tgz",
       "integrity": "sha1-oLhwcpquIUAFt9UDLsLLuw+0RRo=",
       "dev": true
     },
@@ -10740,7 +10740,7 @@
         },
         "string_decoder": {
           "version": "1.1.1",
-          "resolved": "http://registry.npmjs.org/string_decoder/-/string_decoder-1.1.1.tgz",
+          "resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-1.1.1.tgz",
           "integrity": "sha512-n/ShnvDi6FHbbVfviro+WojiFzv+s8MPMHBczVePfUpDJLwoLT0ht1l4YwBCbi8pJAveEEdnkHyPyTP/mzRfwg==",
           "dev": true,
           "requires": {
@@ -11022,7 +11022,7 @@
     },
     "require-uncached": {
       "version": "1.0.3",
-      "resolved": "http://registry.npmjs.org/require-uncached/-/require-uncached-1.0.3.tgz",
+      "resolved": "https://registry.npmjs.org/require-uncached/-/require-uncached-1.0.3.tgz",
       "integrity": "sha1-Tg1W1slmL9MeQwEcS5WqSZVUIdM=",
       "dev": true,
       "requires": {
@@ -11189,7 +11189,7 @@
     },
     "safe-regex": {
       "version": "1.1.0",
-      "resolved": "http://registry.npmjs.org/safe-regex/-/safe-regex-1.1.0.tgz",
+      "resolved": "https://registry.npmjs.org/safe-regex/-/safe-regex-1.1.0.tgz",
       "integrity": "sha1-QKNmnzsHfR6UPURinhV91IAjvy4=",
       "dev": true,
       "requires": {
@@ -11372,7 +11372,7 @@
       "dependencies": {
         "source-map": {
           "version": "0.4.4",
-          "resolved": "http://registry.npmjs.org/source-map/-/source-map-0.4.4.tgz",
+          "resolved": "https://registry.npmjs.org/source-map/-/source-map-0.4.4.tgz",
           "integrity": "sha1-66T12pwNyZneaAMti092FzZSA2s=",
           "dev": true,
           "requires": {
@@ -11521,7 +11521,7 @@
     },
     "sha.js": {
       "version": "2.4.11",
-      "resolved": "http://registry.npmjs.org/sha.js/-/sha.js-2.4.11.tgz",
+      "resolved": "https://registry.npmjs.org/sha.js/-/sha.js-2.4.11.tgz",
       "integrity": "sha512-QMEp5B7cftE7APOjk5Y6xgrbWu+WkLVQwk8JNjZ8nKRciZaByEW6MubieAiToS7+dwvrjGhH8jRXz3MVd0AYqQ==",
       "dev": true,
       "requires": {
@@ -12117,7 +12117,7 @@
         },
         "string_decoder": {
           "version": "1.1.1",
-          "resolved": "http://registry.npmjs.org/string_decoder/-/string_decoder-1.1.1.tgz",
+          "resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-1.1.1.tgz",
           "integrity": "sha512-n/ShnvDi6FHbbVfviro+WojiFzv+s8MPMHBczVePfUpDJLwoLT0ht1l4YwBCbi8pJAveEEdnkHyPyTP/mzRfwg==",
           "dev": true,
           "requires": {
@@ -12134,7 +12134,7 @@
     },
     "stream-browserify": {
       "version": "2.0.1",
-      "resolved": "http://registry.npmjs.org/stream-browserify/-/stream-browserify-2.0.1.tgz",
+      "resolved": "https://registry.npmjs.org/stream-browserify/-/stream-browserify-2.0.1.tgz",
       "integrity": "sha1-ZiZu5fm9uZQKTkUUyvtDu3Hlyds=",
       "dev": true,
       "requires": {
@@ -12165,7 +12165,7 @@
         },
         "string_decoder": {
           "version": "1.1.1",
-          "resolved": "http://registry.npmjs.org/string_decoder/-/string_decoder-1.1.1.tgz",
+          "resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-1.1.1.tgz",
           "integrity": "sha512-n/ShnvDi6FHbbVfviro+WojiFzv+s8MPMHBczVePfUpDJLwoLT0ht1l4YwBCbi8pJAveEEdnkHyPyTP/mzRfwg==",
           "dev": true,
           "requires": {
@@ -12220,7 +12220,7 @@
         },
         "string_decoder": {
           "version": "1.1.1",
-          "resolved": "http://registry.npmjs.org/string_decoder/-/string_decoder-1.1.1.tgz",
+          "resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-1.1.1.tgz",
           "integrity": "sha512-n/ShnvDi6FHbbVfviro+WojiFzv+s8MPMHBczVePfUpDJLwoLT0ht1l4YwBCbi8pJAveEEdnkHyPyTP/mzRfwg==",
           "dev": true,
           "requires": {
@@ -12293,7 +12293,7 @@
     },
     "strip-eof": {
       "version": "1.0.0",
-      "resolved": "http://registry.npmjs.org/strip-eof/-/strip-eof-1.0.0.tgz",
+      "resolved": "https://registry.npmjs.org/strip-eof/-/strip-eof-1.0.0.tgz",
       "integrity": "sha1-u0P/VZim6wXYm1n80SnJgzE2Br8=",
       "dev": true
     },
@@ -12394,7 +12394,7 @@
     },
     "tar": {
       "version": "2.2.1",
-      "resolved": "http://registry.npmjs.org/tar/-/tar-2.2.1.tgz",
+      "resolved": "https://registry.npmjs.org/tar/-/tar-2.2.1.tgz",
       "integrity": "sha1-jk0qJWwOIYXGsYrWlK7JaLg8sdE=",
       "dev": true,
       "requires": {
@@ -12552,7 +12552,7 @@
     },
     "through": {
       "version": "2.3.8",
-      "resolved": "http://registry.npmjs.org/through/-/through-2.3.8.tgz",
+      "resolved": "https://registry.npmjs.org/through/-/through-2.3.8.tgz",
       "integrity": "sha1-DdTJ/6q8NXlgsbckEV1+Doai4fU=",
       "dev": true
     },
@@ -12808,7 +12808,7 @@
     },
     "tty-browserify": {
       "version": "0.0.0",
-      "resolved": "http://registry.npmjs.org/tty-browserify/-/tty-browserify-0.0.0.tgz",
+      "resolved": "https://registry.npmjs.org/tty-browserify/-/tty-browserify-0.0.0.tgz",
       "integrity": "sha1-oVe6QC2iTpv5V/mqadUk7tQpAaY=",
       "dev": true
     },
@@ -13417,7 +13417,7 @@
     },
     "vm-browserify": {
       "version": "0.0.4",
-      "resolved": "http://registry.npmjs.org/vm-browserify/-/vm-browserify-0.0.4.tgz",
+      "resolved": "https://registry.npmjs.org/vm-browserify/-/vm-browserify-0.0.4.tgz",
       "integrity": "sha1-XX6kW7755Kb/ZflUOOCofDV9WnM=",
       "dev": true,
       "requires": {
@@ -14084,7 +14084,7 @@
     },
     "wrap-ansi": {
       "version": "2.1.0",
-      "resolved": "http://registry.npmjs.org/wrap-ansi/-/wrap-ansi-2.1.0.tgz",
+      "resolved": "https://registry.npmjs.org/wrap-ansi/-/wrap-ansi-2.1.0.tgz",
       "integrity": "sha1-2Pw9KE3QV5T+hJc8rs3Rz4JP3YU=",
       "dev": true,
       "requires": {
@@ -14103,7 +14103,7 @@
         },
         "string-width": {
           "version": "1.0.2",
-          "resolved": "http://registry.npmjs.org/string-width/-/string-width-1.0.2.tgz",
+          "resolved": "https://registry.npmjs.org/string-width/-/string-width-1.0.2.tgz",
           "integrity": "sha1-EYvfW4zcUaKn5w0hHgfisLmxB9M=",
           "dev": true,
           "requires": {
@@ -14259,7 +14259,7 @@
         },
         "string-width": {
           "version": "1.0.2",
-          "resolved": "http://registry.npmjs.org/string-width/-/string-width-1.0.2.tgz",
+          "resolved": "https://registry.npmjs.org/string-width/-/string-width-1.0.2.tgz",
           "integrity": "sha1-EYvfW4zcUaKn5w0hHgfisLmxB9M=",
           "dev": true,
           "requires": {

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


+ 1 - 0
tests/operations/TestRegister.mjs → tests/lib/TestRegister.mjs

@@ -48,6 +48,7 @@ class TestRegister {
      * Runs all the tests in the register.
      */
     runTests () {
+        console.log("run tests");
         return Promise.all(
             this.tests.map(function(test, i) {
                 const chef = new Chef();

+ 99 - 0
tests/lib/utils.mjs

@@ -0,0 +1,99 @@
+/**
+ * Utils for test suite
+ *
+ * @author d98762625@gmail.com
+ * @author tlwr [toby@toby.codes]
+ * @author n1474335 [n1474335@gmail.com]
+ * @copyright Crown Copyright 2018
+ * @license Apache-2.0
+ */
+
+// 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";
+};
+
+/**
+ * Helper function to convert a status to an icon.
+ *
+ * @param {string} status
+ * @returns {string}
+ */
+const statusToIcon = function statusToIcon(status) {
+    const icons = {
+        erroring: "🔥",
+        failing: "❌",
+        passing: "✔️️",
+    };
+    return icons[status] || "?";
+};
+
+
+/**
+ * Displays a given test result in the console.
+ * Counts test statuses.
+ *
+ * @param {Object} testStatusCounts
+ * @param {Object} testResult
+ */
+function handleTestResult(testStatus, testResult) {
+    testStatus.allTestsPassing = testStatus.allTestsPassing && testResult.status === "passing";
+    const newCount = (testStatus.counts[testResult.status] || 0) + 1;
+    testStatus.counts[testResult.status] = newCount;
+    testStatus.counts.total += 1;
+    console.log([
+        statusToIcon(testResult.status),
+        testResult.test.name
+    ].join(" "));
+
+    if (testResult.output) {
+        console.log(
+            testResult.output
+                .trim()
+                .replace(/^/, "\t")
+                .replace(/\n/g, "\n\t")
+        );
+    }
+}
+
+/**
+ * Log each test result, count tests and failures. Log test suite run duration.
+ * 
+ * @param {Object} testStatus - object describing test run data
+ * @param {Object[]} results - results from TestRegister
+ */
+export function logTestReport(testStatus, results) {
+    results.forEach(r => handleTestResult(testStatus, r));
+    console.log("\n");
+
+    for (const testStatusCount in testStatus.counts) {
+        const count = testStatus.counts[testStatusCount];
+        if (count > 0) {
+            console.log(testStatusCount.toUpperCase(), count);
+        }
+    }
+
+    if (!testStatus.allTestsPassing) {
+        console.log("\nFailing tests:\n");
+        results.filter(r => r.status !== "passing").forEach(handleTestResult);
+    }
+
+    process.exit(testStatus.allTestsPassing ? 0 : 1);
+}
+
+/**
+ * Fail if the process takes longer than 60 seconds.
+ */
+export function setLongTestFailure() {
+    setTimeout(function() {
+        console.log("Tests took longer than 60 seconds to run, returning.");
+        process.exit(1);
+    }, 60 * 1000);
+}
+

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

@@ -5,7 +5,7 @@
  * the benefit of the TestRegister.
  *
  * @author d98762625 [d98762625@gmail.com]
- * @copyright Crown Copyright 2018
+ * @copyright Crown Copyright 2019
  * @license Apache-2.0
  */
 

+ 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 { toBase32, Dish, SHA3 } from "../../../src/node/index";
-import TestRegister from "../../TestRegister";
+import TestRegister from "../../lib/TestRegister";
 
 TestRegister.addApiTests([
     it("should have some operations", () => {

+ 1 - 1
test/tests/nodeApi/ops.mjs → 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([
 

+ 17 - 83
tests/operations/index.mjs

@@ -12,6 +12,11 @@
  */
 import "babel-polyfill";
 
+import {
+    setLongTestFailure,
+    logTestReport,
+} from "../lib/utils";
+
 // Define global environment functions
 global.ENVIRONMENT_IS_WORKER = function() {
     return typeof importScripts === "function";
@@ -23,7 +28,7 @@ global.ENVIRONMENT_IS_WEB = function() {
     return typeof window === "object";
 };
 
-import TestRegister from "./TestRegister";
+import TestRegister from "../lib/TestRegister";
 import "./tests/BCD";
 import "./tests/BSON";
 import "./tests/Base58";
@@ -86,91 +91,20 @@ import "./tests/Media";
 // Cannot test operations that use the File type yet
 //import "./tests/SplitColourChannels";
 
+// import "./tests/nodeApi/nodeApi";
+// import "./tests/nodeApi/ops";
 
-let allTestsPassing = true;
-const testStatusCounts = {
-    total: 0,
-};
-
-
-/**
- * Helper function to convert a status to an icon.
- *
- * @param {string} status
- * @returns {string}
- */
-function statusToIcon(status) {
-    const icons = {
-        erroring: "🔥",
-        failing: "❌",
-        passing: "✔️️",
-    };
-    return icons[status] || "?";
-}
-
-
-/**
- * Displays a given test result in the console.
- *
- * @param {Object} testResult
- */
-function handleTestResult(testResult) {
-    allTestsPassing = allTestsPassing && testResult.status === "passing";
-    const newCount = (testStatusCounts[testResult.status] || 0) + 1;
-    testStatusCounts[testResult.status] = newCount;
-    testStatusCounts.total += 1;
-
-    console.log([
-        statusToIcon(testResult.status),
-        testResult.test.name
-    ].join(" "));
-
-    if (testResult.output) {
-        console.log(
-            testResult.output
-                .trim()
-                .replace(/^/, "\t")
-                .replace(/\n/g, "\n\t")
-        );
+const testStatus = {
+    allTestsPassing: true,
+    counts: {
+        total: 0,
     }
-}
-
-
-/**
- * Fail if the process takes longer than 60 seconds.
- */
-setTimeout(function() {
-    console.log("Tests took longer than 60 seconds to run, returning.");
-    process.exit(1);
-}, 60 * 1000);
-
-const start = new Date();
-
-Promise.all([
-    TestRegister.runTests(),
-    TestRegister.runApiTests()
-])
-    .then(function(resultsPair) {
-        const finish = new Date();
-        const results = resultsPair[0].concat(resultsPair[1]);
-        results.forEach(handleTestResult);
-
-        console.log("\n");
-
-        for (const testStatus in testStatusCounts) {
-            const count = testStatusCounts[testStatus];
-            if (count > 0) {
-                console.log(testStatus.toUpperCase(), count);
-            }
-        }
+};
 
-        if (!allTestsPassing) {
-            console.log("\nFailing tests:\n");
-            results.filter(r => r.status !== "passing").forEach(handleTestResult);
-        }
+setLongTestFailure();
 
-        console.log(`Tests took ${(finish - start) / 1000} seconds`);
+const logOpsTestReport = logTestReport.bind(null, testStatus);
 
-        process.exit(allTestsPassing ? 0 : 1);
-    });
+TestRegister.runTests()
+    .then(logOpsTestReport);
 

+ 1 - 1
tests/operations/tests/BCD.mjs

@@ -5,7 +5,7 @@
  * @copyright Crown Copyright 2017
  * @license Apache-2.0
  */
-import TestRegister from "../TestRegister";
+import TestRegister from "../../lib/TestRegister";
 
 TestRegister.addTests([
     {

+ 1 - 1
tests/operations/tests/BSON.mjs

@@ -6,7 +6,7 @@
  * @copyright Crown Copyright 2018
  * @license Apache-2.0
  */
-import TestRegister from "../TestRegister";
+import TestRegister from "../../lib/TestRegister";
 
 TestRegister.addTests([
     {

+ 1 - 1
tests/operations/tests/Base58.mjs

@@ -6,7 +6,7 @@
  * @copyright Crown Copyright 2017
  * @license Apache-2.0
  */
-import TestRegister from "../TestRegister";
+import TestRegister from "../../lib/TestRegister";
 
 TestRegister.addTests([
     {

+ 1 - 1
tests/operations/tests/Base62.mjs

@@ -7,7 +7,7 @@
  * @license Apache-2.0
  */
 
-import TestRegister from "../TestRegister";
+import TestRegister from "../../lib/TestRegister";
 
 TestRegister.addTests([
     {

+ 1 - 1
tests/operations/tests/Base64.mjs

@@ -6,7 +6,7 @@
  * @copyright Crown Copyright 2018
  * @license Apache-2.0
  */
-import TestRegister from "../TestRegister";
+import TestRegister from "../../lib/TestRegister";
 
 const ALL_BYTES = [
     "\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f",

+ 1 - 1
tests/operations/tests/BitwiseOp.mjs

@@ -5,7 +5,7 @@
  * @copyright Crown Copyright 2017
  * @license Apache-2.0
  */
-import TestRegister from "../TestRegister";
+import TestRegister from "../../lib/TestRegister";
 
 TestRegister.addTests([
     {

+ 1 - 1
tests/operations/tests/ByteRepr.mjs

@@ -5,7 +5,7 @@
  * @copyright Crown Copyright 2017
  * @license Apache-2.0
  */
-import TestRegister from "../TestRegister";
+import TestRegister from "../../lib/TestRegister";
 
 const ALL_BYTES = [
     "\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f",

+ 1 - 1
tests/operations/tests/CSV.mjs

@@ -6,7 +6,7 @@
  * @copyright Crown Copyright 2018
  * @license Apache-2.0
  */
-import TestRegister from "../TestRegister";
+import TestRegister from "../../lib/TestRegister";
 
 const EXAMPLE_CSV = `A,B,C,D,E,F\r
 1,2,3,4,5,6\r

+ 1 - 1
tests/operations/tests/CartesianProduct.mjs

@@ -6,7 +6,7 @@
  * @copyright Crown Copyright 2018
  * @license Apache-2.0
  */
-import TestRegister from "../TestRegister";
+import TestRegister from "../../lib/TestRegister";
 
 TestRegister.addTests([
     {

+ 1 - 1
tests/operations/tests/CharEnc.mjs

@@ -5,7 +5,7 @@
  * @copyright Crown Copyright 2017
  * @license Apache-2.0
  */
-import TestRegister from "../TestRegister";
+import TestRegister from "../../lib/TestRegister";
 
 TestRegister.addTests([
     {

+ 1 - 1
tests/operations/tests/Checksum.mjs

@@ -5,7 +5,7 @@
  * @copyright Crown Copyright 2018
  * @license Apache-2.0
  */
-import TestRegister from "../TestRegister";
+import TestRegister from "../../lib/TestRegister";
 
 const BASIC_STRING = "The ships hung in the sky in much the same way that bricks don't.";
 const UTF8_STR = "ნუ პანიკას";

+ 1 - 1
tests/operations/tests/Ciphers.mjs

@@ -7,7 +7,7 @@
  * @copyright Crown Copyright 2018
  * @license Apache-2.0
  */
-import TestRegister from "../TestRegister";
+import TestRegister from "../../lib/TestRegister";
 
 
 TestRegister.addTests([

+ 1 - 1
tests/operations/tests/Code.mjs

@@ -7,7 +7,7 @@
  * @copyright Crown Copyright 2017
  * @license Apache-2.0
  */
-import TestRegister from "../TestRegister";
+import TestRegister from "../../lib/TestRegister";
 
 const JSON_TEST_DATA = {
     "store": {

+ 1 - 1
tests/operations/tests/Comment.mjs

@@ -6,7 +6,7 @@
  * @copyright Crown Copyright 2018
  * @license Apache-2.0
  */
-import TestRegister from "../TestRegister";
+import TestRegister from "../../lib/TestRegister";
 
 const ALL_BYTES = [
     "\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f",

+ 1 - 1
tests/operations/tests/Compress.mjs

@@ -5,7 +5,7 @@
  * @copyright Crown Copyright 2017
  * @license Apache-2.0
  */
-import TestRegister from "../TestRegister";
+import TestRegister from "../../lib/TestRegister";
 
 TestRegister.addTests([
     {

+ 1 - 1
tests/operations/tests/ConditionalJump.mjs

@@ -6,7 +6,7 @@
  * @copyright Crown Copyright 2018
  * @license Apache-2.0
  */
-import TestRegister from "../TestRegister";
+import TestRegister from "../../lib/TestRegister";
 
 TestRegister.addTests([
     {

+ 1 - 1
tests/operations/tests/Crypt.mjs

@@ -6,7 +6,7 @@
  * @copyright Crown Copyright 2018
  * @license Apache-2.0
  */
-import TestRegister from "../TestRegister";
+import TestRegister from "../../lib/TestRegister";
 
 TestRegister.addTests([
     /**

+ 1 - 1
tests/operations/tests/DateTime.mjs

@@ -6,7 +6,7 @@
  * @copyright Crown Copyright 2017
  * @license Apache-2.0
  */
-import TestRegister from "../TestRegister";
+import TestRegister from "../../lib/TestRegister";
 
 TestRegister.addTests([
     {

+ 1 - 1
tests/operations/tests/ExtractEmailAddresses.mjs

@@ -5,7 +5,7 @@
  * @copyright Crown Copyright 2017
  * @license Apache-2.0
  */
-import TestRegister from "../TestRegister";
+import TestRegister from "../../lib/TestRegister";
 
 TestRegister.addTests([
     {

+ 1 - 1
tests/operations/tests/Fork.mjs

@@ -6,7 +6,7 @@
  * @copyright Crown Copyright 2018
  * @license Apache-2.0
  */
-import TestRegister from "../TestRegister";
+import TestRegister from "../../lib/TestRegister";
 
 TestRegister.addTests([
     {

+ 1 - 1
tests/operations/tests/FromDecimal.mjs

@@ -5,7 +5,7 @@
  * @copyright Crown Copyright 2018
  * @licence Apache-2.0
  */
-import TestRegister from "../TestRegister";
+import TestRegister from "../../lib/TestRegister";
 
 TestRegister.addTests([
     {

+ 1 - 1
tests/operations/tests/FromGeohash.mjs

@@ -5,7 +5,7 @@
  * @copyright Crown Copyright 2018
  * @license Apache-2.0
  */
-import TestRegister from "../TestRegister";
+import TestRegister from "../../lib/TestRegister";
 
 TestRegister.addTests([
     {

+ 1 - 1
tests/operations/tests/Hash.mjs

@@ -5,7 +5,7 @@
  * @copyright Crown Copyright 2017
  * @license Apache-2.0
  */
-import TestRegister from "../TestRegister";
+import TestRegister from "../../lib/TestRegister";
 
 TestRegister.addTests([
     {

+ 1 - 1
tests/operations/tests/HaversineDistance.mjs

@@ -5,7 +5,7 @@
  * @copyright Crown Copyright 2018
  * @license Apache-2.0
  */
-import TestRegister from "../TestRegister";
+import TestRegister from "../../lib/TestRegister";
 
 TestRegister.addTests([
     {

+ 1 - 1
tests/operations/tests/Hexdump.mjs

@@ -6,7 +6,7 @@
  * @copyright Crown Copyright 2018
  * @license Apache-2.0
  */
-import TestRegister from "../TestRegister";
+import TestRegister from "../../lib/TestRegister";
 
 const ALL_BYTES = [
     "\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f",

+ 1 - 1
tests/operations/tests/Image.mjs

@@ -7,7 +7,7 @@
  * @copyright Crown Copyright 2017
  * @license Apache-2.0
  */
-import TestRegister from "../TestRegister";
+import TestRegister from "../../lib/TestRegister";
 
 TestRegister.addTests([
     {

+ 1 - 1
tests/operations/tests/JSONBeautify.mjs

@@ -6,7 +6,7 @@
  * @copyright Crown Copyright 2018
  * @license Apache-2.0
  */
-import TestRegister from "../TestRegister";
+import TestRegister from "../../lib/TestRegister";
 
 TestRegister.addTests([
     {

+ 1 - 1
tests/operations/tests/JSONMinify.mjs

@@ -6,7 +6,7 @@
  * @copyright Crown Copyright 2018
  * @license Apache-2.0
  */
-import TestRegister from "../TestRegister";
+import TestRegister from "../../lib/TestRegister";
 
 TestRegister.addTests([
     {

+ 1 - 1
tests/operations/tests/JWTDecode.mjs

@@ -6,7 +6,7 @@
  * @copyright Crown Copyright 2018
  * @license Apache-2.0
  */
-import TestRegister from "../TestRegister";
+import TestRegister from "../../lib/TestRegister";
 
 const outputObject = JSON.stringify({
     String: "SomeString",

+ 1 - 1
tests/operations/tests/JWTSign.mjs

@@ -6,7 +6,7 @@
  * @copyright Crown Copyright 2018
  * @license Apache-2.0
  */
-import TestRegister from "../TestRegister";
+import TestRegister from "../../lib/TestRegister";
 
 const inputObject = JSON.stringify({
     String: "SomeString",

+ 1 - 1
tests/operations/tests/JWTVerify.mjs

@@ -6,7 +6,7 @@
  * @copyright Crown Copyright 2018
  * @license Apache-2.0
  */
-import TestRegister from "../TestRegister";
+import TestRegister from "../../lib/TestRegister";
 
 const outputObject = JSON.stringify({
     String: "SomeString",

+ 1 - 1
tests/operations/tests/Jump.mjs

@@ -6,7 +6,7 @@
  * @copyright Crown Copyright 2018
  * @license Apache-2.0
  */
-import TestRegister from "../TestRegister";
+import TestRegister from "../../lib/TestRegister";
 
 TestRegister.addTests([
     {

+ 1 - 1
tests/operations/tests/MS.mjs

@@ -5,7 +5,7 @@
  * @copyright Crown Copyright 2017
  * @license Apache-2.0
  */
-import TestRegister from "../TestRegister";
+import TestRegister from "../../lib/TestRegister";
 
 TestRegister.addTests([
     {

+ 1 - 1
tests/operations/tests/Magic.mjs

@@ -6,7 +6,7 @@
  * @copyright Crown Copyright 2018
  * @license Apache-2.0
  */
-import TestRegister from "../TestRegister";
+import TestRegister from "../../lib/TestRegister";
 
 
 TestRegister.addTests([

+ 1 - 1
tests/operations/tests/Media.mjs

@@ -4,7 +4,7 @@
  * @copyright Crown Copyright 2018
  * @license Apache-2.0
  */
-import TestRegister from "../TestRegister";
+import TestRegister from "../../lib/TestRegister";
 
 TestRegister.addTests([
     {

+ 1 - 1
tests/operations/tests/MorseCode.mjs

@@ -6,7 +6,7 @@
  * @copyright Crown Copyright 2017
  * @license Apache-2.0
  */
-import TestRegister from "../TestRegister";
+import TestRegister from "../../lib/TestRegister";
 
 TestRegister.addTests([
     {

+ 1 - 1
tests/operations/tests/NetBIOS.mjs

@@ -6,7 +6,7 @@
  * @copyright Crown Copyright 2017
  * @license Apache-2.0
  */
-import TestRegister from "../TestRegister";
+import TestRegister from "../../lib/TestRegister";
 
 TestRegister.addTests([
     {

+ 1 - 1
tests/operations/tests/OTP.mjs

@@ -6,7 +6,7 @@
  * @copyright Crown Copyright 2017
  * @license Apache-2.0
  */
-import TestRegister from "../TestRegister";
+import TestRegister from "../../lib/TestRegister";
 
 TestRegister.addTests([
     {

+ 1 - 1
tests/operations/tests/PGP.mjs

@@ -5,7 +5,7 @@
  * @copyright Crown Copyright 2018
  * @license Apache-2.0
  */
-import TestRegister from "../TestRegister";
+import TestRegister from "../../lib/TestRegister";
 
 const ASCII_TEXT = "A common mistake that people make when trying to design something completely foolproof is to underestimate the ingenuity of complete fools.";
 

+ 1 - 1
tests/operations/tests/PHP.mjs

@@ -7,7 +7,7 @@
  * @license Apache-2.0
  */
 
-import TestRegister from "../TestRegister";
+import TestRegister from "../../lib/TestRegister";
 
 TestRegister.addTests([
     {

+ 1 - 1
tests/operations/tests/ParseIPRange.mjs

@@ -5,7 +5,7 @@
  * @copyright Crown Copyright 2017
  * @license Apache-2.0
  */
-import TestRegister from "../TestRegister";
+import TestRegister from "../../lib/TestRegister";
 
 TestRegister.addTests([
     {

+ 1 - 1
tests/operations/tests/ParseQRCode.mjs

@@ -5,7 +5,7 @@
  * @copyright Crown Copyright 2018
  * @license Apache-2.0
  */
-import TestRegister from "../TestRegister";
+import TestRegister from "../../lib/TestRegister";
 
 TestRegister.addTests([
     {

+ 1 - 1
tests/operations/tests/ParseTLV.mjs

@@ -6,7 +6,7 @@
  * @license Apache-2.0
  */
 
-import TestRegister from "../TestRegister";
+import TestRegister from "../../lib/TestRegister";
 
 TestRegister.addTests([
     {

+ 1 - 1
tests/operations/tests/PowerSet.mjs

@@ -6,7 +6,7 @@
  * @copyright Crown Copyright 2018
  * @license Apache-2.0
  */
-import TestRegister from "../TestRegister";
+import TestRegister from "../../lib/TestRegister";
 
 TestRegister.addTests([
     {

+ 1 - 1
tests/operations/tests/Regex.mjs

@@ -5,7 +5,7 @@
  * @copyright Crown Copyright 2017
  * @license Apache-2.0
  */
-import TestRegister from "../TestRegister";
+import TestRegister from "../../lib/TestRegister";
 
 TestRegister.addTests([
     {

+ 1 - 1
tests/operations/tests/Register.mjs

@@ -6,7 +6,7 @@
  * @copyright Crown Copyright 2018
  * @license Apache-2.0
  */
-import TestRegister from "../TestRegister";
+import TestRegister from "../../lib/TestRegister";
 
 TestRegister.addTests([
     {

+ 1 - 1
tests/operations/tests/RemoveDiacritics.mjs

@@ -5,7 +5,7 @@
  * @copyright Crown Copyright 2017
  * @license Apache-2.0
  */
-import TestRegister from "../TestRegister";
+import TestRegister from "../../lib/TestRegister";
 
 TestRegister.addTests([
     {

+ 1 - 1
tests/operations/tests/Rotate.mjs

@@ -6,7 +6,7 @@
  * @copyright Crown Copyright 2018
  * @license Apache-2.0
  */
-import TestRegister from "../TestRegister";
+import TestRegister from "../../lib/TestRegister";
 
 
 TestRegister.addTests([

+ 1 - 1
tests/operations/tests/SeqUtils.mjs

@@ -5,7 +5,7 @@
  * @copyright Copyright 2017
  * @license Apache-2.0
  */
-import TestRegister from "../TestRegister";
+import TestRegister from "../../lib/TestRegister";
 
 TestRegister.addTests([
     {

+ 1 - 1
tests/operations/tests/SetDifference.mjs

@@ -6,7 +6,7 @@
  * @copyright Crown Copyright 2018
  * @license Apache-2.0
  */
-import TestRegister from "../TestRegister";
+import TestRegister from "../../lib/TestRegister";
 
 TestRegister.addTests([
     {

+ 1 - 1
tests/operations/tests/SetIntersection.mjs

@@ -6,7 +6,7 @@
  * @copyright Crown Copyright 2018
  * @license Apache-2.0
  */
-import TestRegister from "../TestRegister";
+import TestRegister from "../../lib/TestRegister";
 
 TestRegister.addTests([
     {

+ 1 - 1
tests/operations/tests/SetUnion.mjs

@@ -6,7 +6,7 @@
  * @copyright Crown Copyright 2018
  * @license Apache-2.0
  */
-import TestRegister from "../TestRegister";
+import TestRegister from "../../lib/TestRegister";
 
 TestRegister.addTests([
     {

File diff suppressed because it is too large
+ 1 - 1
tests/operations/tests/SplitColourChannels.mjs


+ 1 - 1
tests/operations/tests/StrUtils.mjs

@@ -5,7 +5,7 @@
  * @copyright Crown Copyright 2017
  * @license Apache-2.0
  */
-import TestRegister from "../TestRegister";
+import TestRegister from "../../lib/TestRegister";
 
 TestRegister.addTests([
     {

+ 1 - 1
tests/operations/tests/SymmetricDifference.mjs

@@ -6,7 +6,7 @@
  * @copyright Crown Copyright 2018
  * @license Apache-2.0
  */
-import TestRegister from "../TestRegister";
+import TestRegister from "../../lib/TestRegister";
 
 TestRegister.addTests([
     {

+ 1 - 1
tests/operations/tests/TextEncodingBruteForce.mjs

@@ -6,7 +6,7 @@
  * @copyright Crown Copyright 2018
  * @license Apache-2.0
  */
-import TestRegister from "../TestRegister";
+import TestRegister from "../../lib/TestRegister";
 
 TestRegister.addTests([
     {

+ 1 - 1
tests/operations/tests/ToGeohash.mjs

@@ -5,7 +5,7 @@
  * @copyright Crown Copyright 2018
  * @license Apache-2.0
  */
-import TestRegister from "../TestRegister";
+import TestRegister from "../../lib/TestRegister";
 
 TestRegister.addTests([
     {

+ 1 - 1
tests/operations/tests/TranslateDateTimeFormat.mjs

@@ -6,7 +6,7 @@
  * @copyright Crown Copyright 2018
  * @license Apache-2.0
  */
-import TestRegister from "../TestRegister";
+import TestRegister from "../../lib/TestRegister";
 
 TestRegister.addTests([
     {

Some files were not shown because too many files changed in this diff