2018-05-25 08:18:11 +02:00
|
|
|
const Ganache = require('ganache-core')
|
2018-07-30 15:27:25 +02:00
|
|
|
const nock = require('nock')
|
2018-01-30 22:26:37 +01:00
|
|
|
import Enzyme from 'enzyme'
|
|
|
|
import Adapter from 'enzyme-adapter-react-15'
|
|
|
|
|
2018-07-30 15:27:25 +02:00
|
|
|
nock.disableNetConnect()
|
|
|
|
nock.enableNetConnect('localhost')
|
|
|
|
|
2018-01-30 22:26:37 +01:00
|
|
|
Enzyme.configure({ adapter: new Adapter() })
|
2017-03-30 23:43:56 +02:00
|
|
|
// disallow promises from swallowing errors
|
|
|
|
enableFailureOnUnhandledPromiseRejection()
|
|
|
|
|
2018-05-25 08:18:11 +02:00
|
|
|
// ganache server
|
|
|
|
const server = Ganache.server()
|
|
|
|
server.listen(8545, () => {
|
|
|
|
console.log('Ganache Testrpc is running on "http://localhost:8545"')
|
|
|
|
})
|
|
|
|
|
2017-03-30 23:43:56 +02:00
|
|
|
// logging util
|
2019-12-03 15:52:01 +01:00
|
|
|
const log = require('loglevel')
|
2017-02-21 08:42:40 +01:00
|
|
|
log.setDefaultLevel(5)
|
2017-03-30 23:43:56 +02:00
|
|
|
global.log = log
|
2017-02-21 08:42:40 +01:00
|
|
|
|
2017-03-30 23:43:56 +02:00
|
|
|
//
|
|
|
|
// polyfills
|
|
|
|
//
|
|
|
|
|
2018-05-25 07:10:17 +02:00
|
|
|
// fetch
|
|
|
|
global.fetch = require('isomorphic-fetch')
|
2019-06-18 14:17:14 +02:00
|
|
|
require('abortcontroller-polyfill/dist/polyfill-patch-fetch')
|
2018-05-25 07:10:17 +02:00
|
|
|
|
2017-03-30 23:43:56 +02:00
|
|
|
// dom
|
Made configuration migrateable
Abstract all configuration data into a singleton called `configManager`, who is responsible for reading and writing to the persisted storage (localStorage, in our case).
Uses my new module [pojo-migrator](https://www.npmjs.com/package/pojo-migrator), and wraps it with the `ConfigManager` class, which we can hang any state setting or getting methods we need.
By keeping all the persisted state in one place, we can stabilize its outward-facing API, making the interactions increasingly atomic, which will allow us to add features that require restructuring the persisted data in the long term without having to rewrite UI or even `background.js` code.
All the restructuring and data-type management is kept in one neat little place.
This should make it very easy to add new configuration options like user-configured providers, per-domain vaults, and more!
I know this doesn't seem like a big user-facing feature, but we have a big laundry list of features that I think this will really help streamline.
2016-03-31 04:15:49 +02:00
|
|
|
require('jsdom-global')()
|
2017-03-30 23:43:56 +02:00
|
|
|
|
|
|
|
// localStorage
|
Made configuration migrateable
Abstract all configuration data into a singleton called `configManager`, who is responsible for reading and writing to the persisted storage (localStorage, in our case).
Uses my new module [pojo-migrator](https://www.npmjs.com/package/pojo-migrator), and wraps it with the `ConfigManager` class, which we can hang any state setting or getting methods we need.
By keeping all the persisted state in one place, we can stabilize its outward-facing API, making the interactions increasingly atomic, which will allow us to add features that require restructuring the persisted data in the long term without having to rewrite UI or even `background.js` code.
All the restructuring and data-type management is kept in one neat little place.
This should make it very easy to add new configuration options like user-configured providers, per-domain vaults, and more!
I know this doesn't seem like a big user-facing feature, but we have a big laundry list of features that I think this will really help streamline.
2016-03-31 04:15:49 +02:00
|
|
|
window.localStorage = {}
|
2016-04-18 20:31:06 +02:00
|
|
|
|
2017-03-30 23:43:56 +02:00
|
|
|
// crypto.getRandomValues
|
2019-11-20 01:03:20 +01:00
|
|
|
if (!window.crypto) {
|
|
|
|
window.crypto = {}
|
|
|
|
}
|
|
|
|
if (!window.crypto.getRandomValues) {
|
|
|
|
window.crypto.getRandomValues = require('polyfill-crypto.getrandomvalues')
|
|
|
|
}
|
2017-02-21 08:42:40 +01:00
|
|
|
|
2017-05-04 23:35:10 +02:00
|
|
|
function enableFailureOnUnhandledPromiseRejection () {
|
2017-03-30 23:43:56 +02:00
|
|
|
// overwrite node's promise with the stricter Bluebird promise
|
|
|
|
global.Promise = require('bluebird')
|
|
|
|
|
2017-03-30 23:49:39 +02:00
|
|
|
// modified from https://github.com/mochajs/mocha/issues/1926#issuecomment-180842722
|
2017-05-04 23:35:10 +02:00
|
|
|
|
2017-03-30 23:43:56 +02:00
|
|
|
// rethrow unhandledRejections
|
|
|
|
if (typeof process !== 'undefined') {
|
|
|
|
process.on('unhandledRejection', function (reason) {
|
2017-03-30 23:49:39 +02:00
|
|
|
throw reason
|
|
|
|
})
|
2017-03-30 23:43:56 +02:00
|
|
|
} 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 23:49:39 +02:00
|
|
|
throw evt.detail.reason
|
|
|
|
})
|
2017-03-30 23:43:56 +02:00
|
|
|
} else {
|
2019-12-03 15:52:01 +01:00
|
|
|
const oldOHR = window.onunhandledrejection
|
2017-03-30 23:43:56 +02:00
|
|
|
window.onunhandledrejection = function (evt) {
|
2019-11-20 01:03:20 +01:00
|
|
|
if (typeof oldOHR === 'function') {
|
|
|
|
oldOHR.apply(this, arguments)
|
|
|
|
}
|
2017-03-30 23:49:39 +02:00
|
|
|
throw evt.detail.reason
|
|
|
|
}
|
2017-03-30 23:43:56 +02:00
|
|
|
}
|
|
|
|
} else if (typeof console !== 'undefined' &&
|
|
|
|
typeof (console.error || console.log) === 'function') {
|
2017-03-30 23:49:39 +02:00
|
|
|
(console.error || console.log)('Unhandled rejections will be ignored!')
|
2017-03-30 23:43:56 +02:00
|
|
|
}
|
2017-05-04 23:35:10 +02:00
|
|
|
}
|