This repository has been archived by the owner on Mar 25, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathkarma.conf.js
168 lines (130 loc) · 4.76 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
var testWebpackConfig = require('./webpack.config.test.js');
var common = require('./webpack.common.js');
// detect testing mode from environment
var testMode = process.env.TEST_MODE;
if (! ['run-once', 'debug', 'watch'].includes(testMode))
{
testMode = 'run-once';
}
process.env.PHANTOMJS_BIN = 'node_modules/phantomjs-prebuilt/lib/phantom/bin/phantomjs.exe';
/*
* When testing with webpack and transpiled JS, we have to do some extra
* things to get testing to work right. Because we can only include JS
* tests in browser, we have to compile original tests as well.
* That's handled here in karma.conf.js with the karma-webpack preprocessor.
* Just like webpack will create JS bundle files for client code, when
* we running TS tests it will compile and bundle them all to JS as well.
*/
module.exports = function(config) {
var configOverride = {
// base path that will be used to resolve all patterns (e.g. files, exclude)
basePath: '',
// files to exclude
exclude: [
common.absPaths.nodeModules, // skip all node modules
common.absPaths.buildOutput, // skip output
common.absPaths.serverRoot, // skip server
],
// list of files/patterns to load in the browser, serve or watch. Order is important.
// with webpack plugin enabled, each file acts as entry point for webpack configuration
files: [
// shim entry point, to build test environment and run all spec files
{ pattern: common.absPaths.testEntry, included: true, watched: false },
// the actual test spec, only to be monitored for re-runs
////{ pattern: common.patterns.testSources, included: false, watched: true },
],
// explicitly list all Karma plugins to be loaded
plugins: [
'karma-phantomjs-launcher',
'karma-chrome-launcher',
'karma-jasmine',
'karma-sourcemap-loader',
'karma-webpack',
'karma-mocha-reporter',
'karma-jasmine-html-reporter',
'karma-coverage',
],
// preprocess matching files before serving them to the browser
// by running them through this plugins
// available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor
preprocessors: {
// added below
},
// report test results in those formats
// available reporters: https://npmjs.org/browse/keyword/karma-reporter
reporters: [
//'dots',
'progress',
'mocha',
'coverage',
],
mochaReporter: {
maxLogLines: 5,
},
coverageReporter: {
dir: common.absPaths.coverage,
reporters: [
{ type: 'text-summary' }, // log a tabled summary to console
// Add JSON output to enable webpack-bundle-size-analyzer
//{ type: 'json' }, // produce a JSON document
{ type: 'html' }, // produce a HTML document
],
},
// test framework to use
// available frameworks: https://npmjs.org/browse/keyword/karma-adapter
frameworks: [
'jasmine',
],
// start these browsers
// available browser launchers: https://npmjs.org/browse/keyword/karma-launcher
browsers: [
'PhantomJS',
],
// web server port
port: 9876,
// Continuous Integration mode
// if true, Karma captures browsers, runs the tests and exits
// if false, Karma will be listening on debug port in order to run the tests
singleRun: true,
// enable watching file and executing tests whenever any file changes
autoWatch: false,
// enable colors in the output (reporters and logs)
colors: true,
// logging level
// possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG
logLevel: config.LOG_INFO,
// webpack config
webpack: testWebpackConfig,
// don't spam the console with webpack info when running tests
webpackServer: {
noInfo: true,
},
};
// Preprocess matching files before serving them to the browser
// compile test files and generate maps
configOverride.preprocessors[common.absPaths.testEntry] = [
'webpack', // compile TS and ES6 files
'sourcemap', // generate source maps
];
// calculate coverage only on actual application files, excluding tests and libraries
configOverride.preprocessors[common.patterns.appSources] = [
'coverage',
];
// differences when debugging while testing
if (testMode == 'debug') {
configOverride.singleRun = false;
configOverride.browsers = [
'Chrome',
];
configOverride.reporters = [
'kjhtml',
];
}
// differences when watching while testing
if (testMode == 'watch') {
configOverride.singleRun = false;
configOverride.autoWatch = true;
configOverride.reporters = configOverride.reporters.filter(reporter => reporter != 'coverage');
}
config.set(configOverride);
};