summaryrefslogtreecommitdiff
path: root/openstack_dashboard/karma.conf.js
blob: 4d1168c7333acaa1025b3b19a0497e99b729279d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
/*
 *    (c) Copyright 2015 Hewlett-Packard Development Company, L.P.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

'use strict';

var fs = require('fs');
var path = require('path');

module.exports = function (config) {
  var xstaticPath = path.resolve('./.tox/npm');

  if (!xstaticPath) {
    console.error('xStatic libraries not found, please run `tox -e npm`');
    process.exit(1);
  }
  xstaticPath += '/lib/';
  xstaticPath += fs.readdirSync(xstaticPath).find(function(directory) {
    return directory.indexOf('python') === 0;
  });
  xstaticPath += '/site-packages/xstatic/pkg/';

  config.set({
    preprocessors: {
      // Used to collect templates for preprocessing.
      // NOTE: the templates must also be listed in the files section below.
      './**/*.html': ['ng-html2js'],
      // Used to indicate files requiring coverage reports.
      './static/app/**/!(*.spec).js': ['coverage'],
      './dashboards/**/static/**/!(*.spec).js': ['coverage']
    },

    // Sets up module to process templates.
    ngHtml2JsPreprocessor: {
      moduleName: 'templates',
      cacheIdFromPath: function(filepath) {
        // This function takes the raw provided path from the file searches
        // below (in the files: pattern list), applies the filter from the
        // preprocessor above (basically, finds the html files), then uses
        // this function to translate the relative file path into a path
        // that matches what would actually be called in production.
        //
        // e.g.
        // dashboards/project/static/dashboard/project/workflow/launch-instance/configuration/load-edit.html
        // becomes:
        // /static/dashboard/project/workflow/launch-instance/configuration/load-edit.html
        // We can't just use stripPrefix because there are a couple of
        // prefixes that need to be altered (and may be more).
        return filepath.replace(/^dashboards\/[^\/]+/, '')
          .replace(/^static\/app/, '/static/app');
      },
    },

    // This establishes the base for most referenced paths as being relative
    // to this file, i.e. ./openstack_dashboard.
    basePath: './',

    // Contains both source and test files.
    files: [
      /*
       * shim, partly stolen from /i18n/js/horizon/
       * Contains expected items not provided elsewhere (dynamically by
       * Django or via jasmine template.  This is in the project root.
       */
      '../test-shim.js',

      // from jasmine.html
      xstaticPath + 'jquery/data/jquery.js',
      xstaticPath + 'angular/data/angular.js',
      xstaticPath + 'angular/data/angular-route.js',
      xstaticPath + 'angular/data/angular-mocks.js',
      xstaticPath + 'angular/data/angular-cookies.js',
      xstaticPath + 'angular_bootstrap/data/angular-bootstrap.js',
      xstaticPath + 'angular_gettext/data/angular-gettext.js',
      xstaticPath + 'angular_fileupload/data/ng-file-upload-all.js',
      xstaticPath + 'angular/data/angular-sanitize.js',
      xstaticPath + 'd3/data/d3.js',
      xstaticPath + 'rickshaw/data/rickshaw.js',
      xstaticPath + 'angular_smart_table/data/smart-table.js',
      xstaticPath + 'angular_lrdragndrop/data/lrdragndrop.js',
      xstaticPath + 'tv4/data/tv4.js',
      xstaticPath + 'objectpath/data/ObjectPath.js',
      xstaticPath + 'angular_schema_form/data/schema-form.js',

      // TODO: These should be mocked.  However, that could be complex
      // and there's less harm in exposing these directly.  These are
      // located in the project's ./horizon directory.
      '../horizon/static/horizon/js/horizon.js',

      /**
       * Include framework source code from horizon that we need.
       * Otherwise, karma will not be able to find them when testing.
       * These files should be mocked in the foreseeable future.
       * These are located within the project's ./horizon directory.
       */
      '../horizon/static/framework/**/*.module.js',
      '../horizon/static/framework/**/!(*.spec|*.mock).js',

      /**
       * Standard openstack_dashboard JS locations
       *
       * For now, all Angular code is located in ./static/app or
       * ./dashboard/.../static/.
       *
       * Some other JS code exists in other directories (contrib, test) but
       * but it isn't conformant to our current practices, etc.
       */

      /**
       * First, list all the files that defines application's angular modules.
       * Those files have extension of `.module.js`. The order among them is
       * not significant.
       */
      './static/app/**/*.module.js',
      './dashboards/**/static/**/*.module.js',

      /**
       * Followed by other JavaScript files that defines angular providers
       * on the modules defined in files listed above. And they are not mock
       * files or spec files defined below. The order among them is not
       * significant.
       */
      './static/app/**/!(*.spec|*.mock).js',
      './dashboards/**/static/**/!(*.spec|*.mock).js',

      /**
       * Then, list files for mocks with `mock.js` extension. The order
       * among them should not be significant.
       */
      './static/app/**/*.mock.js',
      './dashboards/**/static/**/*.mock.js',

      /**
       * Finally, list files for spec with `spec.js` extension. The order
       * among them should not be significant.
       */
      './static/app/**/*.spec.js',
      './dashboards/**/static/**/*.spec.js',

      /**
       * Angular external templates
       */
      './static/app/**/*.html',
      './dashboards/**/static/**/*.html'
    ],

    autoWatch: true,

    frameworks: ['jasmine'],

    browsers: ['Firefox'],

    browserNoActivityTimeout: 60000,

    reporters: ['progress', 'coverage', 'threshold'],

    plugins: [
      'karma-firefox-launcher',
      'karma-jasmine',
      'karma-ng-html2js-preprocessor',
      'karma-coverage',
      'karma-threshold-reporter'
    ],

    // Places coverage report in HTML format in the subdirectory below.
    coverageReporter: {
      type: 'html',
      dir: '../cover/openstack_dashboard'
    },

    client: {
      jasmine: {
        random: false
      }
    },

    // Coverage threshold values.
    thresholdReporter: {
      statements: 96, // target 100
      branches: 93, // target 100
      functions: 95, // target 100
      lines: 96 // target 100
    }
  });
};