2018-03-30 17:58:34 +00:00
|
|
|
/* eslint-disable jasmine/no-global-setup, jasmine/no-unsafe-spy, no-underscore-dangle */
|
|
|
|
|
2017-05-16 21:02:06 +00:00
|
|
|
import $ from 'jquery';
|
2018-02-20 22:20:48 +00:00
|
|
|
import 'vendor/jasmine-jquery';
|
2017-05-16 21:02:06 +00:00
|
|
|
import '~/commons';
|
2017-06-20 08:05:55 +00:00
|
|
|
import Vue from 'vue';
|
|
|
|
import VueResource from 'vue-resource';
|
2017-12-21 23:01:51 +00:00
|
|
|
import Translate from '~/vue_shared/translate';
|
2018-07-09 21:31:33 +00:00
|
|
|
import jasmineDiff from 'jasmine-diff';
|
2017-06-20 08:05:55 +00:00
|
|
|
|
2018-01-23 19:16:26 +00:00
|
|
|
import { getDefaultAdapter } from '~/lib/utils/axios_utils';
|
2018-04-08 10:20:05 +00:00
|
|
|
import { FIXTURES_PATH, TEST_HOST } from './test_constants';
|
|
|
|
|
|
|
|
import customMatchers from './matchers';
|
2018-01-23 19:16:26 +00:00
|
|
|
|
2017-06-22 11:11:05 +00:00
|
|
|
const isHeadlessChrome = /\bHeadlessChrome\//.test(navigator.userAgent);
|
|
|
|
Vue.config.devtools = !isHeadlessChrome;
|
|
|
|
Vue.config.productionTip = false;
|
|
|
|
|
2017-11-02 14:17:57 +00:00
|
|
|
let hasVueWarnings = false;
|
|
|
|
Vue.config.warnHandler = (msg, vm, trace) => {
|
|
|
|
hasVueWarnings = true;
|
|
|
|
fail(`${msg}${trace}`);
|
|
|
|
};
|
|
|
|
|
2017-12-10 09:58:40 +00:00
|
|
|
let hasVueErrors = false;
|
2018-04-10 15:48:02 +00:00
|
|
|
Vue.config.errorHandler = function(err) {
|
2017-12-10 09:58:40 +00:00
|
|
|
hasVueErrors = true;
|
|
|
|
fail(err);
|
|
|
|
};
|
|
|
|
|
2017-06-20 08:05:55 +00:00
|
|
|
Vue.use(VueResource);
|
2017-12-21 23:01:51 +00:00
|
|
|
Vue.use(Translate);
|
2017-06-20 08:05:55 +00:00
|
|
|
|
2017-05-16 21:02:06 +00:00
|
|
|
// enable test fixtures
|
2018-04-08 10:20:05 +00:00
|
|
|
jasmine.getFixtures().fixturesPath = FIXTURES_PATH;
|
|
|
|
jasmine.getJSONFixtures().fixturesPath = FIXTURES_PATH;
|
|
|
|
|
2018-07-09 21:31:33 +00:00
|
|
|
beforeAll(() => {
|
|
|
|
jasmine.addMatchers(
|
|
|
|
jasmineDiff(jasmine, {
|
|
|
|
colors: true,
|
|
|
|
inline: true,
|
|
|
|
}),
|
|
|
|
);
|
|
|
|
jasmine.addMatchers(customMatchers);
|
|
|
|
});
|
2017-01-07 00:19:42 +00:00
|
|
|
|
2017-05-16 21:02:06 +00:00
|
|
|
// globalize common libraries
|
2018-06-14 06:18:05 +00:00
|
|
|
window.$ = $;
|
|
|
|
window.jQuery = window.$;
|
2017-01-06 21:44:03 +00:00
|
|
|
|
|
|
|
// stub expected globals
|
2016-11-19 21:59:32 +00:00
|
|
|
window.gl = window.gl || {};
|
2018-04-08 10:20:05 +00:00
|
|
|
window.gl.TEST_HOST = TEST_HOST;
|
2016-12-31 00:14:33 +00:00
|
|
|
window.gon = window.gon || {};
|
2018-03-01 18:13:50 +00:00
|
|
|
window.gon.test_env = true;
|
2018-04-10 15:48:02 +00:00
|
|
|
gon.relative_url_root = '';
|
2017-01-07 00:19:42 +00:00
|
|
|
|
2017-06-23 09:28:19 +00:00
|
|
|
let hasUnhandledPromiseRejections = false;
|
|
|
|
|
2018-04-10 15:48:02 +00:00
|
|
|
window.addEventListener('unhandledrejection', event => {
|
2017-06-23 09:28:19 +00:00
|
|
|
hasUnhandledPromiseRejections = true;
|
|
|
|
console.error('Unhandled promise rejection:');
|
|
|
|
console.error(event.reason.stack || event.reason);
|
|
|
|
});
|
|
|
|
|
2018-03-30 17:58:34 +00:00
|
|
|
// Add global function to spy on a module's dependencies via rewire
|
|
|
|
window.spyOnDependency = (module, name) => {
|
|
|
|
const dependency = module.__GetDependency__(name);
|
|
|
|
const spy = jasmine.createSpy(name, dependency);
|
|
|
|
module.__Rewire__(name, spy);
|
|
|
|
return spy;
|
|
|
|
};
|
|
|
|
|
|
|
|
// Reset any rewired modules after each test (see babel-plugin-rewire)
|
|
|
|
afterEach(__rewire_reset_all__); // eslint-disable-line
|
|
|
|
|
2017-06-16 20:40:28 +00:00
|
|
|
// HACK: Chrome 59 disconnects if there are too many synchronous tests in a row
|
|
|
|
// because it appears to lock up the thread that communicates to Karma's socket
|
|
|
|
// This async beforeEach gets called on every spec and releases the JS thread long
|
|
|
|
// enough for the socket to continue to communicate.
|
|
|
|
// The downside is that it creates a minor performance penalty in the time it takes
|
|
|
|
// to run our unit tests.
|
2017-06-20 08:05:55 +00:00
|
|
|
beforeEach(done => done());
|
|
|
|
|
|
|
|
const builtinVueHttpInterceptors = Vue.http.interceptors.slice();
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
// restore interceptors so we have no remaining ones from previous tests
|
|
|
|
Vue.http.interceptors = builtinVueHttpInterceptors.slice();
|
|
|
|
});
|
2017-06-16 20:40:28 +00:00
|
|
|
|
2018-01-23 19:16:26 +00:00
|
|
|
const axiosDefaultAdapter = getDefaultAdapter();
|
|
|
|
|
2017-01-07 00:19:42 +00:00
|
|
|
// render all of our tests
|
|
|
|
const testsContext = require.context('.', true, /_spec$/);
|
2018-04-10 15:48:02 +00:00
|
|
|
testsContext.keys().forEach(function(path) {
|
2017-01-07 00:19:42 +00:00
|
|
|
try {
|
2018-05-01 17:40:35 +00:00
|
|
|
testsContext(path);
|
2017-01-07 00:19:42 +00:00
|
|
|
} catch (err) {
|
2018-06-21 12:22:40 +00:00
|
|
|
console.log(err);
|
|
|
|
console.error('[GL SPEC RUNNER ERROR] Unable to load spec: ', path);
|
2018-04-10 15:48:02 +00:00
|
|
|
describe('Test bundle', function() {
|
|
|
|
it(`includes '${path}'`, function() {
|
2017-02-07 17:41:29 +00:00
|
|
|
expect(err).toBeNull();
|
|
|
|
});
|
|
|
|
});
|
2017-01-07 00:19:42 +00:00
|
|
|
}
|
|
|
|
});
|
2017-02-10 23:45:54 +00:00
|
|
|
|
2017-11-02 14:17:57 +00:00
|
|
|
describe('test errors', () => {
|
2018-04-10 15:48:02 +00:00
|
|
|
beforeAll(done => {
|
2017-12-10 09:58:40 +00:00
|
|
|
if (hasUnhandledPromiseRejections || hasVueWarnings || hasVueErrors) {
|
2017-11-02 14:17:57 +00: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 09:58:40 +00:00
|
|
|
|
|
|
|
it('has no Vue error', () => {
|
|
|
|
expect(hasVueErrors).toBe(false);
|
|
|
|
});
|
2018-01-23 19:16:26 +00: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 09:28:19 +00:00
|
|
|
});
|
|
|
|
|
2017-03-20 22:29:45 +00:00
|
|
|
// if we're generating coverage reports, make sure to include all files so
|
|
|
|
// that we can catch files with 0% coverage
|
|
|
|
// see: https://github.com/deepsweet/istanbul-instrumenter-loader/issues/15
|
|
|
|
if (process.env.BABEL_ENV === 'coverage') {
|
|
|
|
// exempt these files from the coverage report
|
2017-02-10 23:45:54 +00:00
|
|
|
const troubleMakers = [
|
2017-03-08 00:04:20 +00:00
|
|
|
'./blob_edit/blob_bundle.js',
|
2018-06-21 12:55:17 +00:00
|
|
|
'./boards/components/modal/empty_state.vue',
|
2018-02-23 18:28:45 +00:00
|
|
|
'./boards/components/modal/footer.js',
|
|
|
|
'./boards/components/modal/header.js',
|
2017-03-24 22:08:46 +00:00
|
|
|
'./cycle_analytics/cycle_analytics_bundle.js',
|
2017-02-10 23:45:54 +00:00
|
|
|
'./cycle_analytics/components/stage_plan_component.js',
|
|
|
|
'./cycle_analytics/components/stage_staging_component.js',
|
|
|
|
'./cycle_analytics/components/stage_test_component.js',
|
2017-03-24 22:08:46 +00:00
|
|
|
'./commit/pipelines/pipelines_bundle.js',
|
|
|
|
'./diff_notes/diff_notes_bundle.js',
|
2017-02-10 23:45:54 +00:00
|
|
|
'./diff_notes/components/jump_to_discussion.js',
|
|
|
|
'./diff_notes/components/resolve_count.js',
|
2017-03-24 22:08:46 +00:00
|
|
|
'./dispatcher.js',
|
|
|
|
'./environments/environments_bundle.js',
|
|
|
|
'./graphs/graphs_bundle.js',
|
|
|
|
'./issuable/time_tracking/time_tracking_bundle.js',
|
|
|
|
'./main.js',
|
|
|
|
'./merge_conflicts/merge_conflicts_bundle.js',
|
2017-02-10 23:45:54 +00:00
|
|
|
'./merge_conflicts/components/inline_conflict_lines.js',
|
|
|
|
'./merge_conflicts/components/parallel_conflict_lines.js',
|
2017-03-24 22:08:46 +00:00
|
|
|
'./monitoring/monitoring_bundle.js',
|
|
|
|
'./network/network_bundle.js',
|
2017-02-10 23:45:54 +00:00
|
|
|
'./network/branch_graph.js',
|
2017-03-24 22:08:46 +00:00
|
|
|
'./profile/profile_bundle.js',
|
|
|
|
'./protected_branches/protected_branches_bundle.js',
|
|
|
|
'./snippet/snippet_bundle.js',
|
|
|
|
'./terminal/terminal_bundle.js',
|
|
|
|
'./users/users_bundle.js',
|
2017-04-06 01:13:06 +00:00
|
|
|
'./issue_show/index.js',
|
2017-02-10 23:45:54 +00:00
|
|
|
];
|
|
|
|
|
2018-04-10 15:48:02 +00:00
|
|
|
describe('Uncovered files', function() {
|
2018-07-06 12:41:53 +00:00
|
|
|
const sourceFiles = require.context('~', true, /\.(js|vue)$/);
|
2018-02-20 22:20:48 +00:00
|
|
|
|
|
|
|
$.holdReady(true);
|
|
|
|
|
2018-04-10 15:48:02 +00:00
|
|
|
sourceFiles.keys().forEach(function(path) {
|
2017-03-20 22:29:45 +00:00
|
|
|
// ignore if there is a matching spec file
|
2018-07-06 12:41:53 +00:00
|
|
|
if (testsContext.keys().indexOf(`${path.replace(/\.(js|vue)$/, '')}_spec`) > -1) {
|
2017-03-20 22:29:45 +00:00
|
|
|
return;
|
|
|
|
}
|
2017-02-10 23:45:54 +00:00
|
|
|
|
2018-04-10 15:48:02 +00:00
|
|
|
it(`includes '${path}'`, function() {
|
2017-03-20 22:29:45 +00:00
|
|
|
try {
|
|
|
|
sourceFiles(path);
|
|
|
|
} catch (err) {
|
|
|
|
if (troubleMakers.indexOf(path) === -1) {
|
|
|
|
expect(err).toBeNull();
|
|
|
|
}
|
2017-02-10 23:45:54 +00:00
|
|
|
}
|
2017-03-20 22:29:45 +00:00
|
|
|
});
|
2017-02-10 23:45:54 +00:00
|
|
|
});
|
|
|
|
});
|
2017-03-20 22:29:45 +00:00
|
|
|
}
|