mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-12-23 09:52:26 +01:00
1d73d90a1a
Unhandled rejections are now caught using built-in Node.js APIs instead of with `bluebird`. `bluebird` was added as a production dependency but was only used for this purpose. The code responsible for catching unhandled rejection in the browser was removed, as this test helper is never run in the browser. Additionally, unhandled rejections are tracked over the course of all tests, and result in a non-zero exit code if they remain at the end. This was done because it is possible for errors to trigger the `uncaughtRejection` event but then still be handled later on. This is uncommon, and doesn't seem to happen in our test suite. But if it does in the future, it'll be logged but won't result in a non-zero exit code.
61 lines
1.4 KiB
JavaScript
61 lines
1.4 KiB
JavaScript
import Ganache from 'ganache-core'
|
|
import nock from 'nock'
|
|
import Enzyme from 'enzyme'
|
|
import Adapter from 'enzyme-adapter-react-16'
|
|
import log from 'loglevel'
|
|
|
|
nock.disableNetConnect()
|
|
nock.enableNetConnect('localhost')
|
|
|
|
// catch rejections that are still unhandled when tests exit
|
|
const unhandledRejections = new Map()
|
|
process.on('unhandledRejection', (reason, promise) => {
|
|
console.log('Unhandled rejection:', reason)
|
|
unhandledRejections.set(promise, reason)
|
|
})
|
|
process.on('rejectionHandled', (promise) => {
|
|
console.log(`handled: ${unhandledRejections.get(promise)}`)
|
|
unhandledRejections.delete(promise)
|
|
})
|
|
|
|
process.on('exit', () => {
|
|
if (unhandledRejections.size > 0) {
|
|
console.error(`Found ${unhandledRejections.size} unhandled rejections:`)
|
|
for (const reason of unhandledRejections.values()) {
|
|
console.error('Unhandled rejection: ', reason)
|
|
}
|
|
process.exit(1)
|
|
}
|
|
})
|
|
|
|
Enzyme.configure({ adapter: new Adapter() })
|
|
|
|
// ganache server
|
|
const server = Ganache.server()
|
|
server.listen(8545, () => {})
|
|
|
|
log.setDefaultLevel(5)
|
|
global.log = log
|
|
|
|
//
|
|
// polyfills
|
|
//
|
|
|
|
// fetch
|
|
global.fetch = require('isomorphic-fetch')
|
|
require('abortcontroller-polyfill/dist/polyfill-patch-fetch')
|
|
|
|
// dom
|
|
require('jsdom-global')()
|
|
|
|
// localStorage
|
|
window.localStorage = {}
|
|
|
|
// crypto.getRandomValues
|
|
if (!window.crypto) {
|
|
window.crypto = {}
|
|
}
|
|
if (!window.crypto.getRandomValues) {
|
|
window.crypto.getRandomValues = require('polyfill-crypto.getrandomvalues')
|
|
}
|