You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
80 lines
2.2 KiB
80 lines
2.2 KiB
4 years ago
|
import nock from 'nock';
|
||
|
import Enzyme from 'enzyme';
|
||
|
import Adapter from 'enzyme-adapter-react-16';
|
||
|
import log from 'loglevel';
|
||
|
import { JSDOM } from 'jsdom';
|
||
4 years ago
|
|
||
4 years ago
|
nock.disableNetConnect();
|
||
|
nock.enableNetConnect('localhost');
|
||
6 years ago
|
|
||
5 years ago
|
// catch rejections that are still unhandled when tests exit
|
||
4 years ago
|
const unhandledRejections = new Map();
|
||
5 years ago
|
process.on('unhandledRejection', (reason, promise) => {
|
||
4 years ago
|
console.log('Unhandled rejection:', reason);
|
||
|
unhandledRejections.set(promise, reason);
|
||
|
});
|
||
5 years ago
|
process.on('rejectionHandled', (promise) => {
|
||
4 years ago
|
console.log(`handled: ${unhandledRejections.get(promise)}`);
|
||
|
unhandledRejections.delete(promise);
|
||
|
});
|
||
5 years ago
|
|
||
|
process.on('exit', () => {
|
||
|
if (unhandledRejections.size > 0) {
|
||
4 years ago
|
console.error(`Found ${unhandledRejections.size} unhandled rejections:`);
|
||
5 years ago
|
for (const reason of unhandledRejections.values()) {
|
||
4 years ago
|
console.error('Unhandled rejection: ', reason);
|
||
5 years ago
|
}
|
||
4 years ago
|
process.exit(1);
|
||
5 years ago
|
}
|
||
4 years ago
|
});
|
||
5 years ago
|
|
||
4 years ago
|
Enzyme.configure({ adapter: new Adapter() });
|
||
8 years ago
|
|
||
4 years ago
|
log.setDefaultLevel(5);
|
||
|
global.log = log;
|
||
8 years ago
|
|
||
8 years ago
|
//
|
||
|
// polyfills
|
||
|
//
|
||
|
|
||
5 years ago
|
// dom
|
||
4 years ago
|
const jsdom = new JSDOM();
|
||
|
global.window = jsdom.window;
|
||
5 years ago
|
|
||
|
// required by `trezor-connect/node_modules/whatwg-fetch`
|
||
4 years ago
|
global.self = window;
|
||
5 years ago
|
// required by `dom-helpers` and various other libraries
|
||
4 years ago
|
global.document = window.document;
|
||
5 years ago
|
// required by `react-tippy`
|
||
4 years ago
|
global.navigator = window.navigator;
|
||
|
global.Element = window.Element;
|
||
5 years ago
|
// required by `react-popper`
|
||
4 years ago
|
global.HTMLElement = window.HTMLElement;
|
||
5 years ago
|
|
||
|
// required by any components anchored on `popover-content`
|
||
4 years ago
|
const popoverContent = window.document.createElement('div');
|
||
|
popoverContent.setAttribute('id', 'popover-content');
|
||
|
window.document.body.appendChild(popoverContent);
|
||
5 years ago
|
|
||
7 years ago
|
// fetch
|
||
4 years ago
|
const fetch = require('node-fetch');
|
||
5 years ago
|
|
||
4 years ago
|
const { Headers, Request, Response } = fetch;
|
||
|
Object.assign(window, { fetch, Headers, Request, Response });
|
||
7 years ago
|
|
||
8 years ago
|
// localStorage
|
||
4 years ago
|
window.localStorage = {
|
||
|
removeItem: () => null,
|
||
4 years ago
|
};
|
||
4 years ago
|
// override @metamask/logo
|
||
4 years ago
|
window.requestAnimationFrame = () => undefined;
|
||
5 years ago
|
|
||
8 years ago
|
// crypto.getRandomValues
|
||
5 years ago
|
if (!window.crypto) {
|
||
4 years ago
|
window.crypto = {};
|
||
5 years ago
|
}
|
||
|
if (!window.crypto.getRandomValues) {
|
||
4 years ago
|
// eslint-disable-next-line node/global-require
|
||
4 years ago
|
window.crypto.getRandomValues = require('polyfill-crypto.getrandomvalues');
|
||
5 years ago
|
}
|