/
karma.conf.js
87 lines (78 loc) · 2.54 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
// Dependencies
// =============================================================================
const fileFixturesPreprocessor = require('./index');
// Constants & Variables
// =============================================================================
const files = {
fixtures: './tests/fixtures/**/*',
test : './tests/**/*.test.js'
};
// Settings
// =============================================================================
const settings = {
browsers: [
'ChromeHeadless'
],
client: {
baseDir: process.cwd()
},
files: [
files.test,
// Served only (Access in tests by prepending /base/ to path)
{ pattern: files.fixtures, included: false, served: true, watched: true }
],
plugins: [
'karma-*',
fileFixturesPreprocessor
],
preprocessors: {
[files.fixtures]: ['file-fixtures'],
[files.test] : ['eslint', 'webpack']
},
frameworks: ['mocha', 'chai'],
reporters : ['mocha'],
webpack: {
mode: 'development'
},
webpackMiddleware: {
// https://webpack.js.org/configuration/stats/
stats: 'minimal'
},
mochaReporter: {
// https://www.npmjs.com/package/karma-mocha-reporter
output: 'autowatch'
},
autoWatch: false,
singleRun: true,
logLevel : 'WARN' // OFF, ERROR, WARN, INFO, DEBUG
};
// Export
// =============================================================================
module.exports = function(config) {
const isCustom = Boolean(process.argv.indexOf('--usepluginoptions') > -1);
// Custom plugin configuration
if (isCustom) {
settings.fileFixtures = {
globalName : '__TEXT_FIXTURES__',
stripBasePath: false,
stripPrefix : 'tests/fixtures/',
transformKey(path) {
return path + '-transformKey';
},
transformContent(path, content) {
return content + '-transformContent';
}
};
// Allow config settings to be accessed in tests via __karma__.config
settings.client = Object.assign({}, settings.client, {
fileFixtures: Object.assign({}, settings.fileFixtures, {
// Functions are not accessible from __karma__.config.client, so
// these keys indicate that callback functions were defined in
// config used by Karma.
transformKey : true,
transformContent: true
})
});
}
config.set(settings);
};