-
Notifications
You must be signed in to change notification settings - Fork 0
/
karma.conf.js
181 lines (159 loc) · 6.64 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
169
170
171
172
173
174
175
176
177
178
179
180
181
const path = require('path')
/**
* See:
* - https://github.com/xdissent/karma-chai
* - https://github.com/kmees/karma-sinon-chai
* - https://github.com/karma-runner/karma-chrome-launcher
* - https://github.com/karma-runner/karma-mocha
* - https://github.com/litixsoft/karma-mocha-reporter
* - https://github.com/webpack-contrib/karma-webpack
* - (https://github.com/aaronjensen/karma-webpack => fast sourcemaps)
* - https://github.com/demerzel3/karma-sourcemap-loader
* - https://github.com/karma-runner/karma-coverage
* - (https://github.com/mattlewis92/karma-coverage-istanbul-reporter)
*/
// const karmaWebpack = require('karma-webpack-with-fast-source-maps')
const karmaWebpack = require('karma-webpack')
const karmaMocha = require('karma-mocha')
const karmaChai = require('karma-chai')
const karmaSinonChai = require('karma-sinon-chai')
const karmaChromeLauncher = require('karma-chrome-launcher')
const karmaFirefoxLauncher = require('karma-firefox-launcher')
const karmaPhantomLauncher = require('karma-phantomjs-launcher')
const karmaMochaReporter = require('karma-mocha-reporter')
const karmaHtmlReporter = require('karma-html-reporter')
const karmaSourceMapLoader = require('karma-sourcemap-loader')
const karmaCoverage = require('karma-coverage')
const karmaCoverageIstanbulReporter = require('karma-coverage-istanbul-reporter')
const webpackConfig = require('./webpack.karma')
module.exports = function (config) {
config.set({
// base path used to resolve all patterns
basePath: '',
// frameworks to use
// available frameworks: https://npmjs.org/browse/keyword/karma-adapter
frameworks: ['mocha', 'chai', 'sinon-chai'],
// list of files/patterns to load in the browser
files: [
{ pattern: 'src/lib/**/*.js', watched: false },
{ pattern: 'src/tests/**/*.js', watched: false }
// { pattern: 'src/**/*.js', watched: true }
],
// files to exclude
// exclude: [],
reporters: ['progress', 'mocha', 'html', 'coverage-istanbul'],
coverageIstanbulReporter: {
// see valid options: https://github.com/istanbuljs/istanbuljs/blob/aae256fb8b9a3d19414dcf069c592e88712c32c6/packages/istanbul-api/lib/config.js#L33-L39
reports: [ 'html', 'lcovonly', 'text-summary' ],
// base output directory. If you include %browser% in the path it will be replaced with the karma browser name
dir: path.join(__dirname, 'build/coverage'),
// if using webpack and pre-loaders, work around webpack breaking the source path
fixWebpackSourcePaths: true,
// Combines coverage information from multiple browsers into one report rather than outputting a report
// for each browser.
combineBrowserReports: true,
// stop istanbul outputting messages like `File [${filename}] ignored, nothing could be mapped`
// skipFilesWithNoCoverage: true,
skipFilesWithNoCoverage: false,
// Most reporters accept additional config options. You can pass these through the `report-config` option
'report-config': {
// see valid options: https://github.com/istanbuljs/istanbuljs/blob/aae256fb8b9a3d19414dcf069c592e88712c32c6/packages/istanbul-reports/lib/html/index.js#L135-L137
html: {
// outputs the report in ./coverage/html
subdir: 'html'
}
},
// enforce percentage thresholds
// anything under these percentages will cause karma to fail with an exit code of 1 if not running in watch mode
thresholds: {
emitWarning: false, // set to `true` to not fail the test command when thresholds are not met
global: { // thresholds for all files
statements: 100,
lines: 100,
branches: 100,
functions: 100
},
each: { // thresholds per file
statements: 100,
lines: 100,
branches: 100,
functions: 100
// overrides: {
// 'baz/component/**/*.js': {
// statements: 98
// }
// }
}
}
},
htmlReporter: {
outputDir: 'build',
templatePath: null, // set if you moved jasmine_template.html
focusOnFailures: true, // reports show failures on start
namedFiles: false, // name files instead of creating sub-directories
pageTitle: null, // page title for reports; browser info by default
urlFriendlyName: false, // simply replaces spaces with _ for files/dirs
reportName: 'spec-html', // report summary filename; browser info by default
// experimental
preserveDescribeNesting: false, // folded suites stay folded
foldAll: false // reports start folded (only with preserveDescribeNesting)
},
plugins: [
karmaWebpack,
karmaMocha,
karmaChai,
karmaSinonChai,
karmaChromeLauncher,
karmaFirefoxLauncher,
karmaPhantomLauncher,
karmaSourceMapLoader,
karmaCoverage,
karmaMochaReporter,
karmaHtmlReporter,
karmaCoverageIstanbulReporter
],
// preprocess matching files before serving them to the browser
// available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor
preprocessors: { 'src/**/*.js': ['webpack', 'sourcemap'] },
webpack: webpackConfig,
// prevent console spamming when running in Karma!
webpackServer: {
noInfo: true // prevent console spamming when running in Karma!
// noInfo: false
},
// web server port
port: 9876,
// enable colors in the output
colors: true,
// level of logging
// possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG
logLevel: config.LOG_INFO,
// toggle whether to watch files and rerun tests upon incurring changes
autoWatch: false,
// autoWatch: true,
// start these browsers
// available browser launchers: https://npmjs.org/browse/keyword/karma-launcher
// see also for IE for linux on VMs: https://stackoverflow.com/questions/3701484/how-to-test-in-ie-with-linux
// browsers: ['Chrome', 'ChromeCanary', 'ChromeHeadless', 'Firefox', 'Safari', 'PhantomJS', 'Opera', 'IE'],
browsers: process.env.TESTING === 'bdd'
? ['Chrome', 'Firefox']
: ['ChromeHeadlessDocker', 'PhantomJS'],
// : ['ChromeHeadless', 'ChromeHeadlessDocker', 'PhantomJS'],
// if true, Karma runs tests once and exits
singleRun: true,
// singleRun: false,
customLaunchers: {
ChromeHeadlessDocker: {
base: 'ChromeHeadless',
flags: [
'--no-sandbox' // needed to run test cases in docker
]
}
},
webpackMiddleware: {
// webpack-dev-middleware configuration
// i. e.
stats: 'errors-only'
}
})
}