| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687 |
- import '@babel/polyfill';
- import path from 'path';
- import Enzyme from 'enzyme';
- import Adapter from 'enzyme-adapter-react-16';
- Enzyme.configure({ adapter: new Adapter() });
- import { JSDOM } from 'jsdom';
- import { EventEmitter } from 'events';
- import register from 'ignore-styles';
- // eslint-disable-next-line no-undefined
- register(['.scss', '.png', '.wav', '.mp3', '.mp4', '.svg'], (module, filename) => {
- if (['.png', '.wav', '.mp3', '.mp4', '.svg'].some(extension => filename.endsWith(extension))) {
- module.exports = path.basename(filename);
- }
- });
- const exposedProperties = ['window', 'navigator', 'document'];
- const blacklistProperties = ['localStorage', 'sessionStorage'];
- global.window = (new JSDOM('')).window;
- global.document = window.document;
- class URL {
- static createObjectURL() {
- return 'foo';
- }
- }
- global.URL = URL;
- Object.keys(window).forEach(property => {
- if (!blacklistProperties.includes(property) && typeof global[property] === 'undefined') {
- exposedProperties.push(property);
- global[property] = window[property];
- }
- });
- const geolocation = {
- getCurrentPosition: () => null
- };
- global.navigator = {
- userAgent: 'node.js',
- geolocation
- };
- class MockImage extends EventEmitter {
- constructor() {
- super();
- this.src = null;
- this.onload = () => null;
- setTimeout(() => {
- this.onload();
- }, 50);
- }
- }
- global.Image = MockImage;
- window.HTMLMediaElement.prototype.load = () => null;
- window.HTMLMediaElement.prototype.play = () => null;
- window.HTMLMediaElement.prototype.pause = () => null;
- window.HTMLMediaElement.prototype.addTextTrack = () => null;
- window.requestAnimationFrame = () => null;
- window.cancelAnimationFrame = () => null;
- class MockFormData {
- constructor() {
- this.data = {};
- }
- set(key, value) {
- this.data[key] = value;
- }
- }
- global.FormData = MockFormData;
- global.documentRef = document; // eslint-disable-line no-undef
|