text: global.XMLHttpRequest = require('xmlhttprequest').XMLHttpRequest;
  
  const { JSDOM } = require('jsdom');
  
  const jsdom = new JSDOM('<!doctype html><html><body></body></html>');
  const { window } = jsdom;
  
  function copyProps (src, target) {
    const props = Object.getOwnPropertyNames(src)
      .filter((prop) => typeof target[prop] === 'undefined')
      .map((prop) => Object.getOwnPropertyDescriptor(src, prop));
  
    Object.defineProperties(target, props);
  }
  
  global.window = window;
  global.document = window.document;
  global.navigator = {
    onLine: true,
    userAgent: 'node.js'
  };
  copyProps(window, global);
  const fetch = require('node-fetch');
  
  require('isomorphic-fetch');
  global.Headers = fetch.Headers;
  
  global.Buffer = global.Buffer || require('buffer').Buffer;
  
  if (typeof btoa === 'undefined') {
    global.btoa = function (str) {
      return new Buffer(str, 'binary').toString('base64');
    };
  }
  
  if (typeof atob === 'undefined') {
    global.atob = function (b64Encoded) {
      return new Buffer(b64Encoded, 'base64').toString('binary');
    };
  }
  
  // Request animationFrame polly
  
  (function () {
    var lastTime = 0;
    var vendors = ['ms', 'moz', 'webkit', 'o'];
  
    for (let x = 0; x < vendors.length && !window.requestAnimationFrame; ++x) {
      window.requestAnimationFrame = window[vendors[x] + 'RequestAnimationFrame'];
      window.cancelAnimationFrame =
        window[vendors[x] + 'CancelAnimationFrame'] || window[vendors[x] + 'CancelRequestAnimationFrame'];
    }
  
    if (!window.requestAnimationFrame) {
      window.requestAnimationFrame = function (callback, element) {
        var currTime = new Date().getTime();
        var timeToCall = Math.max(0, 16 - (currTime - lastTime));
        var id = window.setTimeout(function () {
          callback(currTime + timeToCall);
        }, timeToCall);
  
        lastTime = currTime + timeToCall;
        return id;
      };
    }
  
    if (!window.cancelAnimationFrame) {
      window.cancelAnimationFrame = function (id) {
        clearTimeout(id);
      };
    }
  })();
  