All files / tests node-test.js

100% Statements 79/79
100% Branches 0/0
100% Functions 9/9
100% Lines 79/79
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 1201x 1x     6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x       3x 3x 3x 3x       2x 2x 2x 2x       3x 3x 3x 3x 3x       1x 1x     1x 1x 1x     1x 1x 1x     1x 1x 1x 1x     1x 1x 1x 1x     1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x   1x   1x 1x     1x 1x   1x   1x     1x 1x 1x 1x 1x 1x   1x 3x 3x   3x 6x       1x 3x     1x   1x 1x  
expect = require('expect.js');
Worker = require('webworker-threads').Worker;
 
function unset() {
  delete require.cache[require.resolve('../src/sha512.js')];
  delete require.cache[require.resolve('./test.js')];
  delete require.cache[require.resolve('./hmac-test.js')];
  sha512 = null;
  sha384 = null;
  sha512_256 = null;
  sha512_224 = null;
  BUFFER = undefined;
  JS_SHA512_NO_WINDOW = undefined;
  JS_SHA512_NO_NODE_JS = undefined;
  JS_SHA512_NO_COMMON_JS = undefined;
  JS_SHA512_NO_ARRAY_BUFFER = undefined;
  JS_SHA512_NO_ARRAY_BUFFER_IS_VIEW = undefined;
  window = undefined;
}
 
function requireToGlobal() {
  sha512 = require('../src/sha512.js').sha512;
  sha384 = require('../src/sha512.js').sha384;
  sha512_256 = require('../src/sha512.js').sha512_256;
  sha512_224 = require('../src/sha512.js').sha512_224;
}
 
function runCommonJsTest() {
  requireToGlobal();
  require('./test.js');
  require('./hmac-test.js');
  unset();
}
 
function runWindowTest() {
  window = global;
  require('../src/sha512.js');
  require('./test.js');
  require('./hmac-test.js');
  unset();
}
 
// Node.js env
BUFFER = true;
runCommonJsTest();
 
// Webpack browser env
JS_SHA512_NO_NODE_JS = true;
window = global;
runCommonJsTest();
 
// browser env
JS_SHA512_NO_NODE_JS = true;
JS_SHA512_NO_COMMON_JS = true;
runWindowTest();
 
// browser env and no array buffer
JS_SHA512_NO_NODE_JS = true;
JS_SHA512_NO_COMMON_JS = true;
JS_SHA512_NO_ARRAY_BUFFER = true;
runWindowTest();
 
// browser env and no isView
JS_SHA512_NO_NODE_JS = true;
JS_SHA512_NO_COMMON_JS = true;
JS_SHA512_NO_ARRAY_BUFFER_IS_VIEW = true;
runWindowTest();
 
// browser AMD
JS_SHA512_NO_NODE_JS = true;
JS_SHA512_NO_COMMON_JS = true;
JS_SHA512_NO_ARRAY_BUFFER_IS_VIEW = false;
window = global;
define = function (func) {
  sha512 = func();
  sha384 = sha512.sha384;
  sha512_256 = sha512.sha512_256;
  sha512_224 = sha512.sha512_224;
  require('./test.js');
  require('./hmac-test.js');
};
define.amd = true;
 
require('../src/sha512.js');
unset();
 
// webworker
WORKER = 'tests/worker.js';
SOURCE = 'src/sha512.js';
 
require('./worker-test.js');
 
delete require.cache[require.resolve('./worker-test.js')];
 
// cover webworker
JS_SHA512_NO_WINDOW = true;
JS_SHA512_NO_NODE_JS = true;
WORKER = './worker.js';
SOURCE = '../src/sha512.js';
window = global;
self = global;
 
Worker = function (file) {
  require(file);
  currentWorker = this;
 
  this.postMessage = function (data) {
    onmessage({data: data});
  };
}
 
postMessage = function (data) {
  currentWorker.onmessage({data: data});
}
 
importScripts = function () {};
 
requireToGlobal();
require('./worker-test.js');