aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorkumavis <aaron@kumavis.me>2017-03-31 05:43:56 +0800
committerkumavis <aaron@kumavis.me>2017-03-31 05:43:56 +0800
commite95ae43c8f0e40742540844984861a06f26999c6 (patch)
treee1e319658160975c53264a38bcc5ef4e50c02b9a /test
parent738201e8e5d829282363dda4bc0480dec7245f4a (diff)
downloadtangerine-wallet-browser-e95ae43c8f0e40742540844984861a06f26999c6.tar
tangerine-wallet-browser-e95ae43c8f0e40742540844984861a06f26999c6.tar.gz
tangerine-wallet-browser-e95ae43c8f0e40742540844984861a06f26999c6.tar.bz2
tangerine-wallet-browser-e95ae43c8f0e40742540844984861a06f26999c6.tar.lz
tangerine-wallet-browser-e95ae43c8f0e40742540844984861a06f26999c6.tar.xz
tangerine-wallet-browser-e95ae43c8f0e40742540844984861a06f26999c6.tar.zst
tangerine-wallet-browser-e95ae43c8f0e40742540844984861a06f26999c6.zip
tests - unit - fail on unhandled promise rejection
Diffstat (limited to 'test')
-rw-r--r--test/helper.js49
1 files changed, 45 insertions, 4 deletions
diff --git a/test/helper.js b/test/helper.js
index a01ea1e53..dd22d80b4 100644
--- a/test/helper.js
+++ b/test/helper.js
@@ -1,11 +1,52 @@
+// disallow promises from swallowing errors
+enableFailureOnUnhandledPromiseRejection()
+
+// logging util
var log = require('loglevel')
log.setDefaultLevel(5)
+global.log = log
+//
+// polyfills
+//
+
+// dom
require('jsdom-global')()
+
+// localStorage
window.localStorage = {}
-if (!('crypto' in window)) { window.crypto = {} }
-window.crypto.getRandomValues = require('polyfill-crypto.getrandomvalues')
+// crypto.getRandomValues
+if (!window.crypto) window.crypto = {}
+if (!window.crypto.getRandomValues) window.crypto.getRandomValues = require('polyfill-crypto.getrandomvalues')
-window.log = log
-global.log = log
+
+
+function enableFailureOnUnhandledPromiseRejection() {
+ // overwrite node's promise with the stricter Bluebird promise
+ global.Promise = require('bluebird')
+
+ // rethrow unhandledRejections
+ if (typeof process !== 'undefined') {
+ process.on('unhandledRejection', function (reason) {
+ throw reason;
+ });
+ } else if (typeof window !== 'undefined') {
+ // 2016-02-01: No browsers support this natively, however bluebird, when.js,
+ // and probably other libraries do.
+ if (typeof window.addEventListener === 'function') {
+ window.addEventListener('unhandledrejection', function (evt) {
+ throw evt.detail.reason;
+ });
+ } else {
+ var oldOHR = window.onunhandledrejection;
+ window.onunhandledrejection = function (evt) {
+ if (typeof oldOHR === 'function') oldOHR.apply(this, arguments);
+ throw evt.detail.reason;
+ };
+ }
+ } else if (typeof console !== 'undefined' &&
+ typeof (console.error || console.log) === 'function') {
+ (console.error || console.log)('Unhandled rejections will be ignored!');
+ }
+} \ No newline at end of file