-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
154 lines (126 loc) · 4.27 KB
/
index.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
'use strict';
const DEFAULT_OPTIONS = {
port : 55556,
reporter : 'spec',
browser : 'Chrome',
logLevel : 'LOG_INFO',
watch : false,
buildDir : './app-build',
testDir : './app-test',
releaseDir: './app-release'
};
var merge = require('merge-env');
var getDirectoriesExcluding = require('./lib/get-directories-excluding');
/**
* Create a Karma configuration function.
* @param {...object} [options] Any number of options hashes to be merged
* @returns {function(object)} A karma configuration function
*/
function configFactory(options) {
// merge options
var args = Array.prototype.slice.call(arguments);
options = merge.apply(null, [{}, DEFAULT_OPTIONS].concat(args));
// make a glob prefix of all directories that sources may exist in
var directoryList = getDirectoriesExcluding([
'node_modules',
'bower_components',
options.buildDir,
options.testDir,
options.releaseDir
]),
directoryPattern = '{' + directoryList.join(',') + '}';
return function configuration(config) {
config.set({
// base path, that will be used to resolve files and exclude
basePath: process.cwd(),
//make sure we use karma-jasmine as the test framework
frameworks: ['jasmine'],
// list of files / patterns to load in the browser
files: [
{
pattern : './app-test/vendor*.js',
included: true,
watched : true
}, {
pattern : './app-test/test*.js',
included: true,
watched : true
}, {
pattern : './app-test/{test,vendor}*.js.map',
watched : false,
included: false
}, {
pattern : './' + directoryPattern + '/**/*.js',
watched : false,
included: false
}
],
preprocessors: {
'**/*.js.map': ['generic']
},
// append to existing value to preserve plugins loaded automatically
plugins: []
.concat(config.plugins)
.concat(
require('karma-generic-preprocessor'),
require('karma-chrome-launcher'),
require('karma-spec-reporter'),
require('karma-teamcity-reporter'),
require('karma-jasmine')
)
.concat(options.plugins)
.filter(Boolean),
// use dots reporter, as travis terminal does not support escaping sequences
// possible values: 'dots', 'progress', 'junit', 'teamcity'
reporters: [].concat(options.reporter),
// web server port
port: options.port,
// enable / disable colors in the output (reporters and logs)
colors: true,
// level of logging
// possible values: LOG_DISABLE || LOG_ERROR || LOG_WARN || LOG_INFO || LOG_DEBUG
logLevel: config[options.logLevel],
// enable / disable watching file and executing tests whenever any file changes
autoWatch: !!options.watch,
// batch multiple changes into a single run
autoWatchBatchDelay: 1000,
// Start these browsers, currently available:
// - Chrome
// - ChromeCanary
// - Firefox
// - Opera
// - Safari (only Mac)
// - PhantomJS
// - IE (only Windows)
browsers: [].concat(options.browser),
// How long will Karma wait for a message from a browser before disconnecting from it (in ms)
browserNoActivityTimeout: 20000,
// If browser does not capture in given timeout [ms], kill it
captureTimeout: 20000,
// Auto run tests on start (when browsers are captured) and exit
singleRun: !options.watch,
// report which specs are slow
reportSlowerThan: 0,
// adjust sourcemaps
genericPreprocessor: {
rules: [{
process: function (content, file, done, log) {
// parse existing source-map
try {
var json = JSON.parse(content);
} catch (exception) {
log.error('file ' + file + ' is not a valid sourcemap');
}
// remove sourcesContent, apply a sourceRoot
delete json.sourcesContent;
json.sourceRoot = '/base';
var text = JSON.stringify(json, null, 2);
// complete
done(text);
}
}]
}
});
};
}
module.exports = configFactory;