2019-02-20 15:26:44 -05:00
|
|
|
import Vue from 'vue';
|
2020-09-21 11:09:44 -04:00
|
|
|
import 'jquery';
|
|
|
|
|
2019-04-01 14:55:57 -04:00
|
|
|
import * as jqueryMatchers from 'custom-jquery-matchers';
|
2019-06-28 08:53:56 -04:00
|
|
|
import { config as testUtilsConfig } from '@vue/test-utils';
|
2019-12-09 07:07:58 -05:00
|
|
|
import Translate from '~/vue_shared/translate';
|
2019-03-08 09:07:44 -05:00
|
|
|
import { initializeTestTimeout } from './helpers/timeout';
|
2019-09-18 10:02:45 -04:00
|
|
|
import { getJSONFixture, loadHTMLFixture, setHTMLFixture } from './helpers/fixtures';
|
2019-07-17 13:47:39 -04:00
|
|
|
import { setupManualMocks } from './mocks/mocks_helper';
|
2019-08-12 15:22:58 -04:00
|
|
|
import customMatchers from './matchers';
|
2019-02-20 14:59:44 -05:00
|
|
|
|
2019-10-02 05:05:53 -04:00
|
|
|
import './helpers/dom_shims';
|
2020-03-24 17:07:54 -04:00
|
|
|
import './helpers/jquery';
|
|
|
|
import '~/commons/bootstrap';
|
2019-06-21 23:35:51 -04:00
|
|
|
|
2019-03-25 16:15:25 -04:00
|
|
|
process.on('unhandledRejection', global.promiseRejectionHandler);
|
|
|
|
|
2019-07-17 13:47:39 -04:00
|
|
|
setupManualMocks();
|
|
|
|
|
2019-03-25 16:32:48 -04: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-03 20:09:37 -04:00
|
|
|
jest.runOnlyPendingTimers();
|
2019-03-25 16:32:48 -04:00
|
|
|
}),
|
|
|
|
);
|
2019-03-21 13:05:21 -04:00
|
|
|
|
2020-07-22 14:09:27 -04:00
|
|
|
initializeTestTimeout(process.env.CI ? 6000 : 500);
|
2019-02-20 14:59:44 -05:00
|
|
|
|
2019-03-28 09:17:52 -04:00
|
|
|
Vue.config.devtools = false;
|
|
|
|
Vue.config.productionTip = false;
|
|
|
|
|
2019-02-20 15:26:44 -05:00
|
|
|
Vue.use(Translate);
|
2019-03-28 15:42:32 -04:00
|
|
|
|
2019-03-27 09:55:40 -04:00
|
|
|
// convenience wrapper for migration from Karma
|
|
|
|
Object.assign(global, {
|
2019-09-18 10:02:45 -04:00
|
|
|
getJSONFixture,
|
2019-03-27 09:55:40 -04:00
|
|
|
loadFixtures: loadHTMLFixture,
|
|
|
|
setFixtures: setHTMLFixture,
|
2019-05-15 08:18:54 -04:00
|
|
|
|
|
|
|
// The following functions fill the fixtures cache in Karma.
|
|
|
|
// This is not necessary in Jest because we make no Ajax request.
|
|
|
|
loadJSONFixtures() {},
|
|
|
|
preloadFixtures() {},
|
2019-03-27 09:55:40 -04:00
|
|
|
});
|
2019-04-01 14:55:57 -04: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 07:09:15 -05:00
|
|
|
// Don't override existing Jest matcher
|
|
|
|
if (matcherName === 'toHaveLength') {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-04-01 14:55:57 -04:00
|
|
|
expect.extend({
|
|
|
|
[matcherName]: matcherFactory().compare,
|
|
|
|
});
|
|
|
|
});
|
2019-06-28 08:53:56 -04:00
|
|
|
|
2019-08-12 15:22:58 -04:00
|
|
|
expect.extend(customMatchers);
|
|
|
|
|
2019-06-28 08:53:56 -04:00
|
|
|
// Tech debt issue TBD
|
|
|
|
testUtilsConfig.logModifiedComponents = false;
|
2019-07-22 08:01:42 -04:00
|
|
|
|
2019-08-06 08:02:23 -04: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 14:20:08 -04:00
|
|
|
|
|
|
|
// make sure that each test actually tests something
|
|
|
|
// see https://jestjs.io/docs/en/expect#expecthasassertions
|
|
|
|
beforeEach(() => {
|
|
|
|
expect.hasAssertions();
|
|
|
|
});
|