test_bundle.js 3.9 KB
Newer Older
W
Winnie Hellmann 已提交
1
/* eslint-disable jasmine/no-global-setup */
2 3 4 5
import $ from 'jquery';
import _ from 'underscore';
import 'jasmine-jquery';
import '~/commons';
F
Fatih Acet 已提交
6

W
Winnie Hellmann 已提交
7 8 9 10 11
import Vue from 'vue';
import VueResource from 'vue-resource';

Vue.use(VueResource);

12
// enable test fixtures
W
winh 已提交
13 14
jasmine.getFixtures().fixturesPath = '/base/spec/javascripts/fixtures';
jasmine.getJSONFixtures().fixturesPath = '/base/spec/javascripts/fixtures';
15

16 17 18
// globalize common libraries
window.$ = window.jQuery = $;
window._ = _;
19 20

// stub expected globals
21
window.gl = window.gl || {};
22 23
window.gl.TEST_HOST = 'http://test.host';
window.gon = window.gon || {};
24

M
Mike Greiling 已提交
25 26 27 28 29 30
// 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.
W
Winnie Hellmann 已提交
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
beforeEach(done => done());

beforeAll(() => {
  const origError = console.error;
  spyOn(console, 'error').and.callFake((message) => {
    if (/^\[Vue warn\]/.test(message)) {
      fail(message);
    } else {
      origError(message);
    }
  });
});

const builtinVueHttpInterceptors = Vue.http.interceptors.slice();

beforeEach(() => {
  // restore interceptors so we have no remaining ones from previous tests
  Vue.http.interceptors = builtinVueHttpInterceptors.slice();
});
M
Mike Greiling 已提交
50

51 52 53 54 55 56
// render all of our tests
const testsContext = require.context('.', true, /_spec$/);
testsContext.keys().forEach(function (path) {
  try {
    testsContext(path);
  } catch (err) {
57 58 59 60 61 62
    console.error('[ERROR] Unable to load spec: ', path);
    describe('Test bundle', function () {
      it(`includes '${path}'`, function () {
        expect(err).toBeNull();
      });
    });
63 64
  }
});
65

66 67 68 69 70
// 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
71
  const troubleMakers = [
72 73
    './blob_edit/blob_bundle.js',
    './boards/boards_bundle.js',
74
    './cycle_analytics/cycle_analytics_bundle.js',
75 76 77
    './cycle_analytics/components/stage_plan_component.js',
    './cycle_analytics/components/stage_staging_component.js',
    './cycle_analytics/components/stage_test_component.js',
78 79
    './commit/pipelines/pipelines_bundle.js',
    './diff_notes/diff_notes_bundle.js',
80 81
    './diff_notes/components/jump_to_discussion.js',
    './diff_notes/components/resolve_count.js',
82 83 84 85 86 87 88
    './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',
89 90
    './merge_conflicts/components/inline_conflict_lines.js',
    './merge_conflicts/components/parallel_conflict_lines.js',
91 92
    './monitoring/monitoring_bundle.js',
    './network/network_bundle.js',
93
    './network/branch_graph.js',
94 95 96 97 98
    './profile/profile_bundle.js',
    './protected_branches/protected_branches_bundle.js',
    './snippet/snippet_bundle.js',
    './terminal/terminal_bundle.js',
    './users/users_bundle.js',
R
Regis Boudinot 已提交
99
    './issue_show/index.js',
100 101
  ];

102 103 104 105 106 107 108
  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;
      }
109

110 111 112 113 114 115 116
      it(`includes '${path}'`, function () {
        try {
          sourceFiles(path);
        } catch (err) {
          if (troubleMakers.indexOf(path) === -1) {
            expect(err).toBeNull();
          }
117
        }
118
      });
119 120
    });
  });
121
}