nifty-wallet/test/helper.js

71 lines
2.0 KiB
JavaScript
Raw Normal View History

const Ganache = require('ganache-core')
const nock = require('nock')
import Enzyme from 'enzyme'
import Adapter from 'enzyme-adapter-react-15'
nock.disableNetConnect()
nock.enableNetConnect('localhost')
Enzyme.configure({ adapter: new Adapter() })
// disallow promises from swallowing errors
enableFailureOnUnhandledPromiseRejection()
// ganache server
const server = Ganache.server()
server.listen(8545, () => {
console.log('Ganache Testrpc is running on "http://localhost:8545"')
})
// logging util
2017-02-20 23:42:40 -08:00
var log = require('loglevel')
log.setDefaultLevel(5)
global.log = log
2017-02-20 23:42:40 -08:00
//
// polyfills
//
// fetch
global.fetch = require('isomorphic-fetch')
// dom
require('jsdom-global')()
// localStorage
window.localStorage = {}
2016-04-18 11:31:06 -07:00
// crypto.getRandomValues
if (!window.crypto) window.crypto = {}
if (!window.crypto.getRandomValues) window.crypto.getRandomValues = require('polyfill-crypto.getrandomvalues')
2017-02-20 23:42:40 -08:00
2017-05-04 14:35:10 -07:00
function enableFailureOnUnhandledPromiseRejection () {
// overwrite node's promise with the stricter Bluebird promise
global.Promise = require('bluebird')
2017-03-30 14:49:39 -07:00
// modified from https://github.com/mochajs/mocha/issues/1926#issuecomment-180842722
2017-05-04 14:35:10 -07:00
// rethrow unhandledRejections
if (typeof process !== 'undefined') {
process.on('unhandledRejection', function (reason) {
2017-03-30 14:49:39 -07:00
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) {
2017-03-30 14:49:39 -07:00
throw evt.detail.reason
})
} else {
2017-03-30 14:49:39 -07:00
var oldOHR = window.onunhandledrejection
window.onunhandledrejection = function (evt) {
2017-03-30 14:49:39 -07:00
if (typeof oldOHR === 'function') oldOHR.apply(this, arguments)
throw evt.detail.reason
}
}
} else if (typeof console !== 'undefined' &&
typeof (console.error || console.log) === 'function') {
2017-03-30 14:49:39 -07:00
(console.error || console.log)('Unhandled rejections will be ignored!')
}
2017-05-04 14:35:10 -07:00
}