shim.js 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. /**
  2. * Licensed to the Apache Software Foundation (ASF) under one
  3. * or more contributor license agreements. See the NOTICE file
  4. * distributed with this work for additional information
  5. * regarding copyright ownership. The ASF licenses this file
  6. * to you under the Apache License, Version 2.0 (the
  7. * "License"); you may not use this file except in compliance
  8. * with the License. You may obtain a copy of the License at
  9. *
  10. * http://www.apache.org/licenses/LICENSE-2.0
  11. *
  12. * Unless required by applicable law or agreed to in writing,
  13. * software distributed under the License is distributed on an
  14. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  15. * KIND, either express or implied. See the License for the
  16. * specific language governing permissions and limitations
  17. * under the License.
  18. */
  19. /* eslint no-native-reassign: 0 */
  20. import 'core-js/stable';
  21. import 'regenerator-runtime/runtime';
  22. import 'abortcontroller-polyfill/dist/abortcontroller-polyfill-only';
  23. import jsdom from 'jsdom';
  24. import { configure } from 'enzyme';
  25. import Adapter from 'enzyme-adapter-react-16';
  26. import { configure as configureTranslation } from '@superset-ui/translation';
  27. import setupSupersetClient from './setupSupersetClient';
  28. configure({ adapter: new Adapter() });
  29. const exposedProperties = ['window', 'navigator', 'document'];
  30. global.jsdom = jsdom.jsdom;
  31. global.document = global.jsdom('<!doctype html><html><body></body></html>');
  32. global.window = document.defaultView;
  33. global.HTMLElement = window.HTMLElement;
  34. Object.keys(document.defaultView).forEach(property => {
  35. if (typeof global[property] === 'undefined') {
  36. exposedProperties.push(property);
  37. global[property] = document.defaultView[property];
  38. }
  39. });
  40. global.navigator = {
  41. userAgent: 'node.js',
  42. platform: 'linux',
  43. appName: 'Netscape',
  44. };
  45. // Fix `Option is not defined`
  46. // https://stackoverflow.com/questions/39501589/jsdom-option-is-not-defined-when-running-my-mocha-test
  47. global.Option = window.Option;
  48. // Configuration copied from https://github.com/sinonjs/sinon/issues/657
  49. // allowing for sinon.fakeServer to work
  50. global.window = global.document.defaultView;
  51. global.XMLHttpRequest = global.window.XMLHttpRequest;
  52. global.sinon = require('sinon');
  53. global.sinon.useFakeXMLHttpRequest();
  54. global.window.XMLHttpRequest = global.XMLHttpRequest;
  55. global.window.location = { href: 'about:blank' };
  56. global.window.performance = { now: () => new Date().getTime() };
  57. global.$ = require('jquery')(global.window);
  58. configureTranslation();
  59. setupSupersetClient();