/
browser-config.js
97 lines (84 loc) · 2.08 KB
/
browser-config.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
'use strict'
const path = require('path')
const _ = require('lodash')
const user = require('../config/user')
const webpackConfig = require('../config/webpack')
const CONFIG_FILE = path.join(__dirname, '..', 'config', 'karma.conf.js')
function getPatterns (ctx) {
if (ctx.files && ctx.files.length > 0) {
return ctx.files
}
return [
'test/browser.js',
'test/**/*.spec.js'
]
}
function webworkerClient (ctx) {
return {
mochaWebWorker: {
pattern: getPatterns(ctx),
mocha: {
timeout: ctx.timeout
}
}
}
}
function getClient (isWebworker, ctx) {
if (isWebworker) {
return webworkerClient(ctx)
}
return {
mocha: {
timeout: ctx.timeout
}
}
}
function getConfig (isWebworker, ctx) {
const ctxFiles = getPatterns(ctx).map((pattern) => ({
pattern: pattern,
included: !isWebworker
}))
const fixtureFiles = [{
pattern: 'test/fixtures/**/*',
watched: false,
served: true,
included: false
}]
const userKarma = user().karma
const userFiles = userKarma.files || []
return webpackConfig('test').then((webpack) => {
// no need for entry
webpack.entry = ''
return _.defaultsDeep({
files: ctxFiles.concat(fixtureFiles).concat(userFiles)
}, userKarma, {
configFile: CONFIG_FILE,
singleRun: !ctx.watch,
watch: ctx.watch,
frameworks: isWebworker ? ['mocha-webworker'] : ['mocha'],
logLevel: ctx.verbose ? 'debug' : 'error',
client: getClient(isWebworker, ctx),
mochaOwnReporter: {
reporter: 'spec'
},
junitReporter: {
outputFile: isWebworker ? 'junit-report-webworker.xml' : 'junit-report-browser.xml'
},
browserNoActivityTimeout: 50 * 1000,
customLaunchers: {
ChromeCustom: {
base: 'Chrome',
flags: [!ctx.cors ? '--disable-web-security' : '']
},
FirefoxCustom: {
base: 'Firefox',
prefs: {
'security.fileuri.strict_origin_policy': ctx.cors
}
}
},
webpack: webpack
})
})
}
module.exports = getConfig