2019-01-15 18:53:27 -05:00
|
|
|
/**
|
|
|
|
* Licensed to the Apache Software Foundation (ASF) under one
|
|
|
|
* or more contributor license agreements. See the NOTICE file
|
|
|
|
* distributed with this work for additional information
|
|
|
|
* regarding copyright ownership. The ASF licenses this file
|
|
|
|
* to you under the Apache License, Version 2.0 (the
|
|
|
|
* "License"); you may not use this file except in compliance
|
|
|
|
* with the License. You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing,
|
|
|
|
* software distributed under the License is distributed on an
|
|
|
|
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
|
|
* KIND, either express or implied. See the License for the
|
|
|
|
* specific language governing permissions and limitations
|
|
|
|
* under the License.
|
|
|
|
*/
|
2019-08-20 18:32:50 -04:00
|
|
|
import 'core-js/stable';
|
|
|
|
import 'regenerator-runtime/runtime';
|
2018-10-15 19:52:19 -04:00
|
|
|
import 'abortcontroller-polyfill/dist/abortcontroller-polyfill-only';
|
2020-07-29 13:53:06 -04:00
|
|
|
import 'jest-enzyme';
|
|
|
|
import jQuery from 'jquery';
|
2018-09-10 17:48:06 -04:00
|
|
|
import { configure } from 'enzyme';
|
|
|
|
import Adapter from 'enzyme-adapter-react-16';
|
2021-11-29 19:29:57 -05:00
|
|
|
// https://jestjs.io/docs/jest-object#jestmockmodulename-factory-options
|
|
|
|
// in order to mock modules in test case, so avoid absolute import module
|
|
|
|
import { configure as configureTranslation } from '../../packages/superset-ui-core/src/translation';
|
2021-01-26 02:40:59 -05:00
|
|
|
import { Worker } from './Worker';
|
2021-06-16 07:17:14 -04:00
|
|
|
import { IntersectionObserver } from './IntersectionObserver';
|
2022-01-28 15:42:16 -05:00
|
|
|
import { ResizeObserver } from './ResizeObserver';
|
2018-10-18 13:40:30 -04:00
|
|
|
import setupSupersetClient from './setupSupersetClient';
|
2021-11-29 19:29:57 -05:00
|
|
|
import CacheStorage from './CacheStorage';
|
2018-10-18 13:40:30 -04:00
|
|
|
|
2018-09-10 17:48:06 -04:00
|
|
|
configure({ adapter: new Adapter() });
|
2016-07-14 22:50:47 -04:00
|
|
|
|
2016-07-27 19:57:05 -04:00
|
|
|
const exposedProperties = ['window', 'navigator', 'document'];
|
2016-07-14 22:50:47 -04:00
|
|
|
|
2020-09-14 13:11:20 -04:00
|
|
|
const { defaultView } = document;
|
2020-07-29 13:53:06 -04:00
|
|
|
if (defaultView != null) {
|
|
|
|
Object.keys(defaultView).forEach(property => {
|
|
|
|
if (typeof global[property] === 'undefined') {
|
|
|
|
exposedProperties.push(property);
|
|
|
|
global[property] = defaultView[property];
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2016-07-14 22:50:47 -04:00
|
|
|
|
2020-07-29 13:53:06 -04:00
|
|
|
const g = global as any;
|
|
|
|
g.window = g.window || {};
|
|
|
|
g.window.location = { href: 'about:blank' };
|
|
|
|
g.window.performance = { now: () => new Date().getTime() };
|
2021-01-26 02:40:59 -05:00
|
|
|
g.window.Worker = Worker;
|
2021-06-16 07:17:14 -04:00
|
|
|
g.window.IntersectionObserver = IntersectionObserver;
|
2022-01-28 15:42:16 -05:00
|
|
|
g.window.ResizeObserver = ResizeObserver;
|
2022-09-01 11:42:07 -04:00
|
|
|
g.window.featureFlags = {};
|
2021-01-26 02:40:59 -05:00
|
|
|
g.URL.createObjectURL = () => '';
|
2021-11-29 19:29:57 -05:00
|
|
|
g.caches = new CacheStorage();
|
2021-01-26 02:40:59 -05:00
|
|
|
|
2020-11-30 17:21:53 -05:00
|
|
|
Object.defineProperty(window, 'matchMedia', {
|
|
|
|
writable: true,
|
|
|
|
value: jest.fn().mockImplementation(query => ({
|
|
|
|
matches: false,
|
|
|
|
media: query,
|
|
|
|
onchange: null,
|
|
|
|
addListener: jest.fn(), // Deprecated
|
|
|
|
removeListener: jest.fn(), // Deprecated
|
|
|
|
addEventListener: jest.fn(),
|
|
|
|
removeEventListener: jest.fn(),
|
|
|
|
dispatchEvent: jest.fn(),
|
|
|
|
})),
|
|
|
|
});
|
2020-07-29 13:53:06 -04:00
|
|
|
|
|
|
|
g.$ = jQuery(g.window);
|
2018-10-18 13:40:30 -04:00
|
|
|
|
2018-10-30 17:51:44 -04:00
|
|
|
configureTranslation();
|
2018-10-18 13:40:30 -04:00
|
|
|
setupSupersetClient();
|
2022-02-14 15:09:06 -05:00
|
|
|
|
|
|
|
// The useTabId hook depends on BroadcastChannel. Jest has a memory leak problem when
|
|
|
|
// dealing with native modules. See https://chanind.github.io/javascript/2019/10/12/jest-tests-memory-leak.html
|
|
|
|
// and https://github.com/facebook/jest/issues/6814 for more information.
|
|
|
|
jest.mock('src/hooks/useTabId', () => ({
|
|
|
|
useTabId: () => 1,
|
|
|
|
}));
|
2022-06-21 08:38:58 -04:00
|
|
|
|
|
|
|
process.env.WEBPACK_MODE = 'test';
|