2021-02-15 21:08:59 +00:00
|
|
|
import { config as testUtilsConfig } from '@vue/test-utils';
|
|
|
|
import * as jqueryMatchers from 'custom-jquery-matchers';
|
2019-02-20 20:26:44 +00:00
|
|
|
import Vue from 'vue';
|
2020-09-21 15:09:44 +00:00
|
|
|
import 'jquery';
|
2021-02-10 15:11:19 +00:00
|
|
|
import { setGlobalDateToFakeDate } from 'helpers/fake_date';
|
2019-12-09 12:07:58 +00:00
|
|
|
import Translate from '~/vue_shared/translate';
|
2021-01-15 00:10:45 +00:00
|
|
|
import { getJSONFixture, loadHTMLFixture, setHTMLFixture } from './__helpers__/fixtures';
|
2021-02-14 18:09:20 +00:00
|
|
|
import { initializeTestTimeout } from './__helpers__/timeout';
|
2019-08-12 19:22:58 +00:00
|
|
|
import customMatchers from './matchers';
|
2021-02-14 18:09:20 +00:00
|
|
|
import { setupManualMocks } from './mocks/mocks_helper';
|
2019-02-20 19:59:44 +00:00
|
|
|
|
2021-01-15 00:10:45 +00:00
|
|
|
import './__helpers__/dom_shims';
|
|
|
|
import './__helpers__/jquery';
|
2020-03-24 21:07:54 +00:00
|
|
|
import '~/commons/bootstrap';
|
2019-06-22 03:35:51 +00:00
|
|
|
|
2021-01-08 09:10:50 +00:00
|
|
|
// This module has some fairly decent visual test coverage in it's own repository.
|
|
|
|
jest.mock('@gitlab/favicon-overlay');
|
|
|
|
|
2019-03-25 20:15:25 +00:00
|
|
|
process.on('unhandledRejection', global.promiseRejectionHandler);
|
|
|
|
|
2019-07-17 17:47:39 +00:00
|
|
|
setupManualMocks();
|
|
|
|
|
2021-02-10 15:11:19 +00:00
|
|
|
// Fake the `Date` for the rest of the jest spec runtime environment.
|
|
|
|
// https://gitlab.com/gitlab-org/gitlab/-/merge_requests/39496#note_503084332
|
|
|
|
setGlobalDateToFakeDate();
|
|
|
|
|
2019-03-25 20:32:48 +00:00
|
|
|
afterEach(() =>
|
|
|
|
// give Promises a bit more time so they fail the right test
|
|
|
|
new Promise(setImmediate).then(() => {
|
|
|
|
// wait for pending setTimeout()s
|
2020-04-04 00:09:37 +00:00
|
|
|
jest.runOnlyPendingTimers();
|
2019-03-25 20:32:48 +00:00
|
|
|
}),
|
|
|
|
);
|
2019-03-21 17:05:21 +00:00
|
|
|
|
2020-12-25 21:10:18 +00:00
|
|
|
initializeTestTimeout(process.env.CI ? 6000 : 500);
|
2019-02-20 19:59:44 +00:00
|
|
|
|
2019-03-28 13:17:52 +00:00
|
|
|
Vue.config.devtools = false;
|
|
|
|
Vue.config.productionTip = false;
|
|
|
|
|
2019-02-20 20:26:44 +00:00
|
|
|
Vue.use(Translate);
|
2019-03-28 19:42:32 +00:00
|
|
|
|
2019-03-27 13:55:40 +00:00
|
|
|
// convenience wrapper for migration from Karma
|
|
|
|
Object.assign(global, {
|
2019-09-18 14:02:45 +00:00
|
|
|
getJSONFixture,
|
2019-03-27 13:55:40 +00:00
|
|
|
loadFixtures: loadHTMLFixture,
|
|
|
|
setFixtures: setHTMLFixture,
|
|
|
|
});
|
2019-04-01 18:55:57 +00:00
|
|
|
|
|
|
|
// custom-jquery-matchers was written for an old Jest version, we need to make it compatible
|
|
|
|
Object.entries(jqueryMatchers).forEach(([matcherName, matcherFactory]) => {
|
2019-12-30 12:09:15 +00:00
|
|
|
// Don't override existing Jest matcher
|
|
|
|
if (matcherName === 'toHaveLength') {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-04-01 18:55:57 +00:00
|
|
|
expect.extend({
|
|
|
|
[matcherName]: matcherFactory().compare,
|
|
|
|
});
|
|
|
|
});
|
2019-06-28 12:53:56 +00:00
|
|
|
|
2019-08-12 19:22:58 +00:00
|
|
|
expect.extend(customMatchers);
|
|
|
|
|
2020-12-25 18:10:00 +00:00
|
|
|
testUtilsConfig.deprecationWarningHandler = (method, message) => {
|
|
|
|
const ALLOWED_DEPRECATED_METHODS = [
|
|
|
|
// https://gitlab.com/gitlab-org/gitlab/-/issues/295679
|
|
|
|
'finding components with `find` or `get`',
|
|
|
|
|
|
|
|
// https://gitlab.com/gitlab-org/gitlab/-/issues/295680
|
|
|
|
'finding components with `findAll`',
|
|
|
|
];
|
|
|
|
if (!ALLOWED_DEPRECATED_METHODS.includes(method)) {
|
|
|
|
global.console.error(message);
|
|
|
|
}
|
|
|
|
};
|
2019-07-22 12:01:42 +00:00
|
|
|
|
2019-08-06 12:02:23 +00:00
|
|
|
Object.assign(global, {
|
|
|
|
requestIdleCallback(cb) {
|
|
|
|
const start = Date.now();
|
|
|
|
return setTimeout(() => {
|
|
|
|
cb({
|
|
|
|
didTimeout: false,
|
|
|
|
timeRemaining: () => Math.max(0, 50 - (Date.now() - start)),
|
|
|
|
});
|
|
|
|
});
|
|
|
|
},
|
|
|
|
cancelIdleCallback(id) {
|
|
|
|
clearTimeout(id);
|
|
|
|
},
|
|
|
|
});
|
2019-08-21 18:20:08 +00:00
|
|
|
|
|
|
|
// make sure that each test actually tests something
|
|
|
|
// see https://jestjs.io/docs/en/expect#expecthasassertions
|
|
|
|
beforeEach(() => {
|
|
|
|
expect.hasAssertions();
|
|
|
|
});
|