forked from shaka-project/shaka-player
-
Notifications
You must be signed in to change notification settings - Fork 0
/
karma.conf.js
257 lines (213 loc) · 7.7 KB
/
karma.conf.js
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
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
/**
* @license
* Copyright 2016 Google Inc.
*
* 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.
*/
// Karma configuration
// Install required modules by running "npm install"
module.exports = function(config) {
config.set({
// base path that will be used to resolve all patterns (eg. files, exclude)
basePath: '.',
// frameworks to use
// available frameworks: https://npmjs.org/browse/keyword/karma-adapter
frameworks: [
'jasmine-ajax', 'jasmine',
'sprintf-js',
],
plugins: [
'karma-*', // default
frameworkPluginForModule('sprintf-js'),
],
// list of files / patterns to load in the browser
files: [
// closure base first
'third_party/closure/goog/base.js',
// deps next
'dist/deps.js',
'shaka-player.uncompiled.js',
// requirejs next
'node_modules/requirejs/require.js',
// bootstrapping for the test suite
'test/test/boot.js',
// test utils next
'test/test/util/*.js',
// list of test assets next
'demo/assets.js',
// unit tests last
'test/**/*_unit.js',
// if --quick is not present, we will add integration tests.
// source files - these are only watched and served
{pattern: 'lib/**/*.js', included: false},
{pattern: 'third_party/closure/goog/**/*.js', included: false},
{pattern: 'test/test/assets/*', included: false},
{pattern: 'dist/shaka-player.compiled.js', included: false},
],
// NOTE: Do not use proxies at all! They cannot be used with the --hostname
// option, which is necessary for some of our lab testing.
proxies: {},
preprocessors: {
// Don't compute coverage over lib/debug/ or lib/polyfill/
'lib/!(debug|polyfill)/*.js': 'coverage',
// Player is not matched by the above, so add it explicitly
'lib/player.js': 'coverage',
},
// to avoid DISCONNECTED messages on Safari:
browserDisconnectTimeout: 10 * 1000, // 10s to reconnect
browserDisconnectTolerance: 1, // max of 1 disconnect is OK
browserNoActivityTimeout: 5 * 60 * 1000, // disconnect after 5m silence
captureTimeout: 1 * 60 * 1000, // give up if startup takes 1m
// https://support.saucelabs.com/customer/en/portal/articles/2440724
client: {
// don't capture the client's console logs
captureConsole: false,
// |args| must be an array; pass a key-value map as the sole client
// argument.
args: [{}],
},
// enable / disable colors in the output (reporters and logs)
colors: true,
// level of logging
// possible values: config.LOG_DISABLE || config.LOG_ERROR ||
// config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG
logLevel: config.LOG_WARN,
// do not execute tests whenever any file changes
autoWatch: false,
// do a single run of the tests on captured browsers and then quit
singleRun: true,
coverageReporter: {
includeAllSources: true,
reporters: [
{ type: 'text' },
],
},
specReporter: {
suppressSkipped: true,
},
});
if (flagPresent('html-coverage-report')) {
// Wipe out any old coverage reports to avoid confusion.
var rimraf = require('rimraf');
rimraf.sync('coverage', {}); // Like rm -rf
config.set({
reporters: [ 'coverage', 'progress' ],
coverageReporter: {
reporters: [
{ type: 'html', dir: 'coverage' },
{ type: 'cobertura', dir: 'coverage', file: 'coverage.xml' },
],
},
});
}
if (!flagPresent('quick')) {
// If --quick is present, we don't serve integration tests.
var files = config.files;
files.push('test/**/*_integration.js');
// We just modified the config in-place. No need for config.set().
}
var logLevel = getFlagValue('enable-logging');
if (logLevel !== null) {
if (logLevel === '')
logLevel = 3; // INFO
config.set({
reporters: ['spec'],
});
// Setting |config.client| using config.set will remove the
// |config.client.args| member.
config.client.captureConsole = true;
setClientArg(config, 'logLevel', logLevel);
}
if (flagPresent('external')) {
// Run Player integration tests against external assets.
// Skipped by default.
setClientArg(config, 'external', true);
}
if (flagPresent('drm')) {
// Run Player integration tests against DRM license servers.
// Skipped by default.
setClientArg(config, 'drm', true);
}
if (flagPresent('quarantined')) {
// Run quarantined tests which do not consistently pass.
// Skipped by default.
setClientArg(config, 'quarantined', true);
}
if (flagPresent('uncompiled')) {
// Run Player integration tests with uncompiled code for debugging.
setClientArg(config, 'uncompiled', true);
}
if (flagPresent('random')) {
// Run tests in a random order.
setClientArg(config, 'random', true);
// If --seed was specified use that value, else generate a seed so that the
// exact order can be reproduced if it catches an issue.
var seed = getFlagValue('seed') || new Date().getTime();
setClientArg(config, 'seed', seed);
console.log("Using a random test order (--random) with --seed=" + seed);
}
if (flagPresent('specFilter')) {
setClientArg(config, 'specFilter', getFlagValue('specFilter'));
}
};
// Sets the value of an argument passed to the client.
function setClientArg(config, name, value) {
config.client.args[0][name] = value;
}
// Find a custom command-line flag that has a value (e.g. --option=12).
// Returns:
// * string value --option=12
// * empty string --option= or --option
// * null not present
function getFlagValue(name) {
var re = /^--([^=]+)(?:=(.*))?$/;
for (var i = 0; i < process.argv.length; i++) {
var match = re.exec(process.argv[i]);
if (match && match[1] == name) {
if (match[2] !== undefined)
return match[2];
else
return '';
}
}
return null;
}
// Find custom command-line flags.
function flagPresent(name) {
return getFlagValue(name) !== null;
}
// Construct framework plugins on-the-fly for arbitrary node modules.
// A call to this must be placed in the config in the 'plugins' array,
// and the module name must be added to the config in the 'frameworks' array.
function frameworkPluginForModule(name) {
// The framework injects files into the client which runs the tests.
var framework = function(files) {
// Locate the main file for the node module.
var path = require('path');
var mainFile = path.resolve(require.resolve(name));
// Add a file entry to the list of files to be served.
// This follows the same syntax as above in config.set({files: ...}).
files.unshift({
pattern: mainFile, included: true, served: true, watched: false
});
};
// The framework factory function takes one argument, which is the list of
// files from the karma config.
framework.$inject = ['config.files'];
// This is the plugin interface to register a new framework. Adding this to
// the list of plugins makes the named module available as a framework. That
// framework then injects the module into the client.
var obj = {};
obj['framework:' + name] = ['factory', framework];
return obj;
}