BigW Consortium Gitlab

test_bundle.js 2.96 KB
Newer Older
1
// enable test fixtures
2
require('jasmine-jquery');
Fatih Acet committed
3

4 5 6
jasmine.getFixtures().fixturesPath = 'base/spec/javascripts/fixtures';
jasmine.getJSONFixtures().fixturesPath = 'base/spec/javascripts/fixtures';

7
// include common libraries
8
require('~/commons/index.js');
9 10 11 12
window.$ = window.jQuery = require('jquery');
window._ = require('underscore');

// stub expected globals
13
window.gl = window.gl || {};
14 15
window.gl.TEST_HOST = 'http://test.host';
window.gon = window.gon || {};
16 17 18 19 20 21 22

// render all of our tests
const testsContext = require.context('.', true, /_spec$/);
testsContext.keys().forEach(function (path) {
  try {
    testsContext(path);
  } catch (err) {
23 24 25 26 27 28
    console.error('[ERROR] Unable to load spec: ', path);
    describe('Test bundle', function () {
      it(`includes '${path}'`, function () {
        expect(err).toBeNull();
      });
    });
29 30
  }
});
31

32 33 34 35 36
// 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
37
  const troubleMakers = [
38 39
    './blob_edit/blob_bundle.js',
    './boards/boards_bundle.js',
40
    './cycle_analytics/cycle_analytics_bundle.js',
41 42 43
    './cycle_analytics/components/stage_plan_component.js',
    './cycle_analytics/components/stage_staging_component.js',
    './cycle_analytics/components/stage_test_component.js',
44 45
    './commit/pipelines/pipelines_bundle.js',
    './diff_notes/diff_notes_bundle.js',
46 47
    './diff_notes/components/jump_to_discussion.js',
    './diff_notes/components/resolve_count.js',
48 49 50 51 52 53 54 55
    './dispatcher.js',
    './environments/environments_bundle.js',
    './filtered_search/filtered_search_bundle.js',
    './graphs/graphs_bundle.js',
    './issuable/issuable_bundle.js',
    './issuable/time_tracking/time_tracking_bundle.js',
    './main.js',
    './merge_conflicts/merge_conflicts_bundle.js',
56 57
    './merge_conflicts/components/inline_conflict_lines.js',
    './merge_conflicts/components/parallel_conflict_lines.js',
58 59 60
    './merge_request_widget/ci_bundle.js',
    './monitoring/monitoring_bundle.js',
    './network/network_bundle.js',
61
    './network/branch_graph.js',
62 63 64 65 66
    './profile/profile_bundle.js',
    './protected_branches/protected_branches_bundle.js',
    './snippet/snippet_bundle.js',
    './terminal/terminal_bundle.js',
    './users/users_bundle.js',
Regis Boudinot committed
67
    './issue_show/index.js',
68 69
  ];

70 71 72 73 74 75 76
  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;
      }
77

78 79 80 81 82 83 84
      it(`includes '${path}'`, function () {
        try {
          sourceFiles(path);
        } catch (err) {
          if (troubleMakers.indexOf(path) === -1) {
            expect(err).toBeNull();
          }
85
        }
86
      });
87 88
    });
  });
89
}