1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-12-23 01:39:44 +01:00

tests - unit - fail on unhandled promise rejection

This commit is contained in:
kumavis 2017-03-30 14:43:56 -07:00
parent 738201e8e5
commit e95ae43c8f
2 changed files with 46 additions and 4 deletions

View File

@ -40,6 +40,7 @@
"async": "^1.5.2",
"async-q": "^0.3.1",
"bip39": "^2.2.0",
"bluebird": "^3.5.0",
"browser-passworder": "^2.0.3",
"browserify-derequire": "^0.9.4",
"clone": "^1.0.2",

View File

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