-
Notifications
You must be signed in to change notification settings - Fork 0
/
karmaConfigurator.js
101 lines (91 loc) · 2.83 KB
/
karmaConfigurator.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
/*
* @author David Menger
*/
require('webpack');
const webpackConfig = require('./webpack.config');
const path = require('path');
function karmaConfigurator (debug = false, coverage = false) {
const webpack = Object.assign({}, webpackConfig, {
devtool: '#inline-source-map', // just do inline source maps instead of the default
watch: debug,
externals: {
cheerio: 'window',
'react/lib/ExecutionEnvironment': true,
'react/lib/ReactContext': true,
'react/addons': true
}
});
// fakin sinon
Object.assign(webpack.module, {
noParse: [
/node_modules\/sinon\//
]
});
if (coverage) {
webpack.module.rules = webpack.module.rules
.map((mod) => {
Object.assign(mod, {
use: mod.use.map((use) => {
if (!use.loader.match(/^babel/)) {
return module;
}
Object.assign(use.options, {
plugins: ['istanbul']
});
return use;
})
});
return mod;
});
}
const config = {
browsers: ['Chrome', 'Firefox'],
singleRun: !debug,
frameworks: ['mocha', 'sinon'],
files: [
'webpack.tests.js'
],
plugins: [
'karma-mocha',
'karma-webpack',
'karma-spec-reporter',
'karma-chrome-launcher',
'karma-safari-launcher',
'karma-firefox-launcher',
'karma-opera-launcher',
'karma-sinon'
],
preprocessors: {
'webpack.tests.js': ['webpack']
},
webpack,
reporters: ['spec'],
webpackServer: {
noInfo: true
}
};
if (coverage) {
config.plugins.push('karma-sourcemap-loader', 'karma-coverage');
Object.assign(config, {
coverageReporter: {
// specify a common output directory
dir: path.join(__dirname, 'coverage'),
reporters: [
// reporters not supporting the `file` property
{ type: 'json', file: 'coverage-public.json', subdir: brwsr => `${brwsr}`.replace(/\s.*$/, '') },
{ type: 'lcov' }
// { type: 'html', subdir: 'report-html' }
],
instrumenterOptions: {
istanbul: { noCompact: true }
}
},
preprocessors: {
'webpack.tests.js': ['webpack', 'sourcemap']
},
reporters: ['spec', 'coverage']
});
}
return config;
}
module.exports = karmaConfigurator;