2018-07-24 08:27:59 -04:00
|
|
|
/* eslint-disable
|
2020-07-22 14:09:27 -04:00
|
|
|
jasmine/no-global-setup, no-underscore-dangle, no-console
|
2018-07-24 08:27:59 -04:00
|
|
|
*/
|
2018-03-30 13:58:34 -04:00
|
|
|
|
2021-02-15 16:08:59 -05:00
|
|
|
import { config as testUtilsConfig } from '@vue/test-utils';
|
|
|
|
import jasmineDiff from 'jasmine-diff';
|
2017-05-16 17:02:06 -04:00
|
|
|
import $ from 'jquery';
|
2019-07-11 15:32:37 -04:00
|
|
|
import 'core-js/features/set-immediate';
|
2018-02-20 17:20:48 -05:00
|
|
|
import 'vendor/jasmine-jquery';
|
2017-05-16 17:02:06 -04:00
|
|
|
import '~/commons';
|
2017-06-20 04:05:55 -04:00
|
|
|
import Vue from 'vue';
|
2018-01-23 14:16:26 -05:00
|
|
|
import { getDefaultAdapter } from '~/lib/utils/axios_utils';
|
2021-02-15 16:08:59 -05:00
|
|
|
import Translate from '~/vue_shared/translate';
|
2018-04-08 06:20:05 -04:00
|
|
|
|
2021-02-15 16:08:59 -05:00
|
|
|
import { FIXTURES_PATH, TEST_HOST } from './test_constants';
|
2018-01-23 14:16:26 -05:00
|
|
|
|
2019-06-28 08:53:56 -04:00
|
|
|
// Tech debt issue TBD
|
|
|
|
testUtilsConfig.logModifiedComponents = false;
|
|
|
|
|
2017-06-22 07:11:05 -04:00
|
|
|
const isHeadlessChrome = /\bHeadlessChrome\//.test(navigator.userAgent);
|
|
|
|
Vue.config.devtools = !isHeadlessChrome;
|
|
|
|
Vue.config.productionTip = false;
|
|
|
|
|
2017-11-02 10:17:57 -04:00
|
|
|
let hasVueWarnings = false;
|
|
|
|
Vue.config.warnHandler = (msg, vm, trace) => {
|
2019-01-25 04:54:54 -05:00
|
|
|
// The following workaround is necessary, so we are able to use setProps from Vue test utils
|
|
|
|
// see https://github.com/vuejs/vue-test-utils/issues/631#issuecomment-421108344
|
2019-01-25 05:47:41 -05:00
|
|
|
const currentStack = new Error().stack;
|
2019-01-25 04:54:54 -05:00
|
|
|
const isInVueTestUtils = currentStack
|
|
|
|
.split('\n')
|
2020-12-23 16:10:24 -05:00
|
|
|
.some((line) => line.startsWith(' at VueWrapper.setProps ('));
|
2019-01-25 04:54:54 -05:00
|
|
|
if (isInVueTestUtils) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-11-02 10:17:57 -04:00
|
|
|
hasVueWarnings = true;
|
|
|
|
fail(`${msg}${trace}`);
|
|
|
|
};
|
|
|
|
|
2017-12-10 04:58:40 -05:00
|
|
|
let hasVueErrors = false;
|
2020-12-23 07:10:26 -05:00
|
|
|
Vue.config.errorHandler = function (err) {
|
2017-12-10 04:58:40 -05:00
|
|
|
hasVueErrors = true;
|
|
|
|
fail(err);
|
|
|
|
};
|
|
|
|
|
2017-12-21 18:01:51 -05:00
|
|
|
Vue.use(Translate);
|
2017-06-20 04:05:55 -04:00
|
|
|
|
2017-05-16 17:02:06 -04:00
|
|
|
// enable test fixtures
|
2018-04-08 06:20:05 -04:00
|
|
|
jasmine.getFixtures().fixturesPath = FIXTURES_PATH;
|
|
|
|
jasmine.getJSONFixtures().fixturesPath = FIXTURES_PATH;
|
|
|
|
|
2018-07-09 17:31:33 -04:00
|
|
|
beforeAll(() => {
|
|
|
|
jasmine.addMatchers(
|
|
|
|
jasmineDiff(jasmine, {
|
2018-09-14 09:40:53 -04:00
|
|
|
colors: window.__karma__.config.color,
|
|
|
|
inline: window.__karma__.config.color,
|
2018-07-09 17:31:33 -04:00
|
|
|
}),
|
|
|
|
);
|
|
|
|
});
|
2017-01-06 19:19:42 -05:00
|
|
|
|
2017-05-16 17:02:06 -04:00
|
|
|
// globalize common libraries
|
2018-06-14 02:18:05 -04:00
|
|
|
window.$ = $;
|
|
|
|
window.jQuery = window.$;
|
2017-01-06 16:44:03 -05:00
|
|
|
|
|
|
|
// stub expected globals
|
2016-11-19 16:59:32 -05:00
|
|
|
window.gl = window.gl || {};
|
2018-04-08 06:20:05 -04:00
|
|
|
window.gl.TEST_HOST = TEST_HOST;
|
2016-12-30 19:14:33 -05:00
|
|
|
window.gon = window.gon || {};
|
2018-03-01 13:13:50 -05:00
|
|
|
window.gon.test_env = true;
|
2019-10-16 14:08:01 -04:00
|
|
|
window.gon.ee = process.env.IS_EE;
|
2018-04-10 11:48:02 -04:00
|
|
|
gon.relative_url_root = '';
|
2017-01-06 19:19:42 -05:00
|
|
|
|
2017-06-23 05:28:19 -04:00
|
|
|
let hasUnhandledPromiseRejections = false;
|
|
|
|
|
2020-12-23 16:10:24 -05:00
|
|
|
window.addEventListener('unhandledrejection', (event) => {
|
2017-06-23 05:28:19 -04:00
|
|
|
hasUnhandledPromiseRejections = true;
|
|
|
|
console.error('Unhandled promise rejection:');
|
|
|
|
console.error(event.reason.stack || event.reason);
|
|
|
|
});
|
|
|
|
|
2018-07-09 07:20:18 -04:00
|
|
|
let longRunningTestTimeoutHandle;
|
|
|
|
|
2020-12-23 16:10:24 -05:00
|
|
|
beforeEach((done) => {
|
2018-07-09 07:20:18 -04:00
|
|
|
longRunningTestTimeoutHandle = setTimeout(() => {
|
|
|
|
done.fail('Test is running too long!');
|
2019-05-28 23:38:00 -04:00
|
|
|
}, 4000);
|
2018-07-09 07:20:18 -04:00
|
|
|
done();
|
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(() => {
|
|
|
|
clearTimeout(longRunningTestTimeoutHandle);
|
|
|
|
});
|
|
|
|
|
2018-01-23 14:16:26 -05:00
|
|
|
const axiosDefaultAdapter = getDefaultAdapter();
|
|
|
|
|
2017-01-06 19:19:42 -05:00
|
|
|
// render all of our tests
|
2019-03-13 17:54:52 -04:00
|
|
|
const testContexts = [require.context('spec', true, /_spec$/)];
|
|
|
|
|
2019-10-16 14:08:01 -04:00
|
|
|
if (process.env.IS_EE) {
|
2019-03-13 17:54:52 -04:00
|
|
|
testContexts.push(require.context('ee_spec', true, /_spec$/));
|
|
|
|
}
|
2019-03-13 17:12:34 -04:00
|
|
|
|
2020-12-23 16:10:24 -05:00
|
|
|
testContexts.forEach((context) => {
|
|
|
|
context.keys().forEach((path) => {
|
2019-03-13 17:12:34 -04:00
|
|
|
try {
|
|
|
|
context(path);
|
|
|
|
} catch (err) {
|
|
|
|
console.log(err);
|
|
|
|
console.error('[GL SPEC RUNNER ERROR] Unable to load spec: ', path);
|
2020-12-23 07:10:26 -05:00
|
|
|
describe('Test bundle', function () {
|
|
|
|
it(`includes '${path}'`, function () {
|
2019-03-13 17:12:34 -04:00
|
|
|
expect(err).toBeNull();
|
|
|
|
});
|
2017-02-07 12:41:29 -05:00
|
|
|
});
|
2019-03-13 17:12:34 -04:00
|
|
|
}
|
|
|
|
});
|
2017-01-06 19:19:42 -05:00
|
|
|
});
|
2017-02-10 18:45:54 -05:00
|
|
|
|
2017-11-02 10:17:57 -04:00
|
|
|
describe('test errors', () => {
|
2020-12-23 16:10:24 -05:00
|
|
|
beforeAll((done) => {
|
2017-12-10 04:58:40 -05:00
|
|
|
if (hasUnhandledPromiseRejections || hasVueWarnings || hasVueErrors) {
|
2017-11-02 10:17:57 -04:00
|
|
|
setTimeout(done, 1000);
|
|
|
|
} else {
|
|
|
|
done();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
it('has no unhandled Promise rejections', () => {
|
|
|
|
expect(hasUnhandledPromiseRejections).toBe(false);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('has no Vue warnings', () => {
|
|
|
|
expect(hasVueWarnings).toBe(false);
|
|
|
|
});
|
2017-12-10 04:58:40 -05:00
|
|
|
|
|
|
|
it('has no Vue error', () => {
|
|
|
|
expect(hasVueErrors).toBe(false);
|
|
|
|
});
|
2018-01-23 14:16:26 -05:00
|
|
|
|
|
|
|
it('restores axios adapter after mocking', () => {
|
|
|
|
if (getDefaultAdapter() !== axiosDefaultAdapter) {
|
|
|
|
fail('axios adapter is not restored! Did you forget a restore() on MockAdapter?');
|
|
|
|
}
|
|
|
|
});
|
2017-06-23 05:28:19 -04:00
|
|
|
});
|