debian-mirror-gitlab/spec/frontend/test_setup.js

72 lines
2 KiB
JavaScript
Raw Normal View History

2019-07-07 11:18:12 +05:30
import Vue from 'vue';
import * as jqueryMatchers from 'custom-jquery-matchers';
2019-09-30 21:07:59 +05:30
import $ from 'jquery';
2019-07-07 11:18:12 +05:30
import Translate from '~/vue_shared/translate';
2019-09-30 21:07:59 +05:30
import { config as testUtilsConfig } from '@vue/test-utils';
2019-07-07 11:18:12 +05:30
import { initializeTestTimeout } from './helpers/timeout';
2019-09-04 21:01:54 +05:30
import { loadHTMLFixture, setHTMLFixture } from './helpers/fixtures';
2019-09-30 21:07:59 +05:30
import { setupManualMocks } from './mocks/mocks_helper';
// Expose jQuery so specs using jQuery plugins can be imported nicely.
// Here is an issue to explore better alternatives:
// https://gitlab.com/gitlab-org/gitlab-ee/issues/12448
window.jQuery = $;
2019-02-15 15:39:39 +05:30
2019-07-07 11:18:12 +05:30
process.on('unhandledRejection', global.promiseRejectionHandler);
2019-02-15 15:39:39 +05:30
2019-09-30 21:07:59 +05:30
setupManualMocks();
2019-07-07 11:18:12 +05:30
afterEach(() =>
// give Promises a bit more time so they fail the right test
new Promise(setImmediate).then(() => {
// wait for pending setTimeout()s
jest.runAllTimers();
}),
);
2019-09-04 21:01:54 +05:30
initializeTestTimeout(process.env.CI ? 5000 : 500);
2019-07-07 11:18:12 +05:30
Vue.config.devtools = false;
Vue.config.productionTip = false;
Vue.use(Translate);
// workaround for JSDOM not supporting innerText
// see https://github.com/jsdom/jsdom/issues/1245
Object.defineProperty(global.Element.prototype, 'innerText', {
get() {
return this.textContent;
},
configurable: true, // make it so that it doesn't blow chunks on re-running tests with things like --watch
});
// convenience wrapper for migration from Karma
Object.assign(global, {
loadFixtures: loadHTMLFixture,
setFixtures: setHTMLFixture,
2019-09-04 21:01:54 +05:30
// The following functions fill the fixtures cache in Karma.
// This is not necessary in Jest because we make no Ajax request.
loadJSONFixtures() {},
preloadFixtures() {},
2019-02-15 15:39:39 +05:30
});
2019-09-30 21:07:59 +05:30
Object.assign(global, {
MutationObserver() {
return {
disconnect() {},
observe() {},
};
},
});
2019-07-07 11:18:12 +05:30
// custom-jquery-matchers was written for an old Jest version, we need to make it compatible
Object.entries(jqueryMatchers).forEach(([matcherName, matcherFactory]) => {
expect.extend({
[matcherName]: matcherFactory().compare,
});
2019-02-15 15:39:39 +05:30
});
2019-09-30 21:07:59 +05:30
// Tech debt issue TBD
testUtilsConfig.logModifiedComponents = false;