2017-06-20 04:05:55 -04:00
|
|
|
/* eslint-disable jasmine/no-global-setup */
|
2017-05-16 17:02:06 -04:00
|
|
|
import $ from 'jquery';
|
|
|
|
import 'jasmine-jquery';
|
|
|
|
import '~/commons';
|
2016-07-24 16:45:11 -04:00
|
|
|
|
2017-06-20 04:05:55 -04:00
|
|
|
import Vue from 'vue';
|
|
|
|
import VueResource from 'vue-resource';
|
|
|
|
|
2018-01-23 14:16:26 -05:00
|
|
|
import { getDefaultAdapter } from '~/lib/utils/axios_utils';
|
|
|
|
|
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) => {
|
|
|
|
hasVueWarnings = true;
|
|
|
|
fail(`${msg}${trace}`);
|
|
|
|
};
|
|
|
|
|
2017-12-10 04:58:40 -05:00
|
|
|
let hasVueErrors = false;
|
|
|
|
Vue.config.errorHandler = function (err) {
|
|
|
|
hasVueErrors = true;
|
|
|
|
fail(err);
|
|
|
|
};
|
|
|
|
|
2017-06-20 04:05:55 -04:00
|
|
|
Vue.use(VueResource);
|
|
|
|
|
2017-05-16 17:02:06 -04:00
|
|
|
// enable test fixtures
|
2017-05-05 15:14:58 -04:00
|
|
|
jasmine.getFixtures().fixturesPath = '/base/spec/javascripts/fixtures';
|
|
|
|
jasmine.getJSONFixtures().fixturesPath = '/base/spec/javascripts/fixtures';
|
2017-01-06 19:19:42 -05:00
|
|
|
|
2017-05-16 17:02:06 -04:00
|
|
|
// globalize common libraries
|
|
|
|
window.$ = window.jQuery = $;
|
2017-01-06 16:44:03 -05:00
|
|
|
|
|
|
|
// stub expected globals
|
2016-11-19 16:59:32 -05:00
|
|
|
window.gl = window.gl || {};
|
2016-12-30 19:14:33 -05:00
|
|
|
window.gl.TEST_HOST = 'http://test.host';
|
|
|
|
window.gon = window.gon || {};
|
2017-01-06 19:19:42 -05:00
|
|
|
|
2017-06-23 05:28:19 -04:00
|
|
|
let hasUnhandledPromiseRejections = false;
|
|
|
|
|
|
|
|
window.addEventListener('unhandledrejection', (event) => {
|
|
|
|
hasUnhandledPromiseRejections = true;
|
|
|
|
console.error('Unhandled promise rejection:');
|
|
|
|
console.error(event.reason.stack || event.reason);
|
|
|
|
});
|
|
|
|
|
2017-06-16 16:40:28 -04: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 04:05:55 -04: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 16:40:28 -04:00
|
|
|
|
2018-01-23 14:16:26 -05:00
|
|
|
const axiosDefaultAdapter = getDefaultAdapter();
|
|
|
|
|
2017-01-06 19:19:42 -05:00
|
|
|
// render all of our tests
|
|
|
|
const testsContext = require.context('.', true, /_spec$/);
|
|
|
|
testsContext.keys().forEach(function (path) {
|
|
|
|
try {
|
|
|
|
testsContext(path);
|
|
|
|
} catch (err) {
|
2017-02-07 12:41:29 -05:00
|
|
|
console.error('[ERROR] Unable to load spec: ', path);
|
|
|
|
describe('Test bundle', function () {
|
|
|
|
it(`includes '${path}'`, function () {
|
|
|
|
expect(err).toBeNull();
|
|
|
|
});
|
|
|
|
});
|
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', () => {
|
|
|
|
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
|
|
|
});
|
|
|
|
|
2017-03-20 18:29:45 -04: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 18:45:54 -05:00
|
|
|
const troubleMakers = [
|
2017-03-07 19:04:20 -05:00
|
|
|
'./blob_edit/blob_bundle.js',
|
|
|
|
'./boards/boards_bundle.js',
|
2017-03-24 18:08:46 -04:00
|
|
|
'./cycle_analytics/cycle_analytics_bundle.js',
|
2017-02-10 18:45:54 -05: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 18:08:46 -04:00
|
|
|
'./commit/pipelines/pipelines_bundle.js',
|
|
|
|
'./diff_notes/diff_notes_bundle.js',
|
2017-02-10 18:45:54 -05:00
|
|
|
'./diff_notes/components/jump_to_discussion.js',
|
|
|
|
'./diff_notes/components/resolve_count.js',
|
2017-03-24 18:08:46 -04:00
|
|
|
'./dispatcher.js',
|
|
|
|
'./environments/environments_bundle.js',
|
|
|
|
'./filtered_search/filtered_search_bundle.js',
|
|
|
|
'./graphs/graphs_bundle.js',
|
|
|
|
'./issuable/time_tracking/time_tracking_bundle.js',
|
|
|
|
'./main.js',
|
|
|
|
'./merge_conflicts/merge_conflicts_bundle.js',
|
2017-02-10 18:45:54 -05:00
|
|
|
'./merge_conflicts/components/inline_conflict_lines.js',
|
|
|
|
'./merge_conflicts/components/parallel_conflict_lines.js',
|
2017-03-24 18:08:46 -04:00
|
|
|
'./monitoring/monitoring_bundle.js',
|
|
|
|
'./network/network_bundle.js',
|
2017-02-10 18:45:54 -05:00
|
|
|
'./network/branch_graph.js',
|
2017-03-24 18:08:46 -04: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-05 21:13:06 -04:00
|
|
|
'./issue_show/index.js',
|
2017-02-10 18:45:54 -05:00
|
|
|
];
|
|
|
|
|
2017-03-20 18:29:45 -04:00
|
|
|
describe('Uncovered files', function () {
|
|
|
|
const sourceFiles = require.context('~', true, /\.js$/);
|
|
|
|
sourceFiles.keys().forEach(function (path) {
|
|
|
|
// ignore if there is a matching spec file
|
|
|
|
if (testsContext.keys().indexOf(`${path.replace(/\.js$/, '')}_spec`) > -1) {
|
|
|
|
return;
|
|
|
|
}
|
2017-02-10 18:45:54 -05:00
|
|
|
|
2017-03-20 18:29:45 -04:00
|
|
|
it(`includes '${path}'`, function () {
|
|
|
|
try {
|
|
|
|
sourceFiles(path);
|
|
|
|
} catch (err) {
|
|
|
|
if (troubleMakers.indexOf(path) === -1) {
|
|
|
|
expect(err).toBeNull();
|
|
|
|
}
|
2017-02-10 18:45:54 -05:00
|
|
|
}
|
2017-03-20 18:29:45 -04:00
|
|
|
});
|
2017-02-10 18:45:54 -05:00
|
|
|
});
|
|
|
|
});
|
2017-03-20 18:29:45 -04:00
|
|
|
}
|