forked from Harvest-Dev/ng-walkthrough
-
Notifications
You must be signed in to change notification settings - Fork 0
/
karma.conf.js
113 lines (96 loc) · 3.17 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
'use strict';
const erectorUtils = require('erector-set/src/utils');
const fs = require('fs');
const path = require('path');
module.exports = function (config) {
const base = {
basePath: '',
frameworks: ['jasmine'],
files: [
{ pattern: './src/test.js', watched: false }
],
mime: {
'text/x-typescript': ['ts','tsx']
},
plugins: [
'karma-chrome-launcher',
'karma-jasmine',
'karma-phantomjs-launcher',
'karma-coverage-istanbul-reporter',
'karma-sourcemap-loader',
'karma-webpack'
],
preprocessors: {
'./src/test.js': ['webpack', 'sourcemap']
},
coverageIstanbulReporter: {
dir: './coverage',
fixWebpackSourcePaths: true,
reports: ['html', 'lcovonly']
},
reporters: ['progress', 'coverage-istanbul'],
port: 9876,
colors: true,
logLevel: config.LOG_INFO,
autoWatch: true,
browsers: ['Chrome', 'PhantomJS'],
singleRun: false,
webpackServer: { noInfo: true }
};
const fullConfig = mergeCustomConfig(base, config);
config.set(fullConfig);
};
const mergeCustomConfig = (base, karmaConfig) => {
const customConfigPath = path.resolve(
__dirname,
'configs',
'karma.conf.js'
);
let fullConfig = base;
if (fs.existsSync(customConfigPath)) {
fullConfig = mergeConfigs(base, require(customConfigPath), karmaConfig);
}
return fullConfig;
};
const mergeConfigs = (base, custom, karmaConfig) => {
let mergedConfig = base;
if (erectorUtils.checkIsType(custom, 'function')) {
custom = custom(karmaConfig);
}
if (custom) {
const arrays = mergeConfigArrays(base, custom);
const objects = mergeConfigObjects(base, custom);
const primitives = mergeConfigPrimitives(base, custom);
const customAttributes = Object.assign({}, arrays, objects, primitives);
mergedConfig = Object.assign(
{}, base, customAttributes
);
}
return mergedConfig;
};
const mergeConfigArrays = (base, custom) => {
const attributes = ['browsers', 'files', 'plugins', 'reporters'];
return mergeConfigAttributes(base, custom, attributes, (baseAttribute, customAttribute) =>
erectorUtils.mergeDeep(baseAttribute, customAttribute)
);
};
const mergeConfigObjects = (base, custom) => {
const attributes = ['preprocessors'];
return mergeConfigAttributes(base, custom, attributes, (baseAttribute, customAttribute) =>
Object.assign(customAttribute, baseAttribute)
);
};
const mergeConfigPrimitives = (base, custom) => {
const attributes = ['color', 'logLevel', 'port'];
return mergeConfigAttributes(base, custom, attributes, (baseAttribute, customAttribute) =>
customAttribute
);
};
const mergeConfigAttributes = (base, custom, attributes, callback) => {
return attributes.reduce((config, attribute) => {
if (attribute in custom) {
config[attribute] = callback(base[attribute], custom[attribute]);
}
return config;
}, {});
};