-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
karma.conf.js
159 lines (149 loc) · 5.47 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
// Dependencies
// =============================================================================
const fs = require('fs');
const pkg = JSON.parse(fs.readFileSync('./package.json', 'utf8'));
const { execSync } = require('child_process');
// Variables
// =============================================================================
const files = {
test: './tests/browser.test.js'
};
const gitInfo = {
branch : execSync('git rev-parse --abbrev-ref HEAD').toString().trim(),
commitMsg: execSync('git log -1 --pretty=%B').toString().trim(),
isClean : Boolean(execSync('[[ -n $(git status -s) ]] || echo "clean"').toString().trim()),
isDirty : Boolean(execSync('[[ -z $(git status -s) ]] || echo "dirty"').toString().trim())
};
// Settings
// =============================================================================
const settings = {
files: [
'node_modules/@babel/polyfill/dist/polyfill.js',
files.test
],
preprocessors: {
[files.test]: ['eslint', 'webpack', 'sourcemap']
},
frameworks: ['mocha', 'chai', 'webpack'],
reporters : ['mocha', 'coverage-istanbul'], // 'Browserstack' added below
webpack: {
mode : 'development',
module: {
rules: [
{
test : /\.js$/,
exclude: [/node_modules/],
use : [
{
loader : 'babel-loader',
options: {
// See .babelrc
plugins: [
['istanbul', { exclude: 'tests/*' }]
]
},
}
]
}
]
}
},
webpackMiddleware: {
// https://webpack.js.org/configuration/stats/
stats: 'minimal'
},
// Code coverage
// https://github.com/mattlewis92/karma-coverage-istanbul-reporter
coverageIstanbulReporter: {
reports : ['lcovonly', 'text-summary'],
combineBrowserReports : true,
fixWebpackSourcePaths : true,
skipFilesWithNoCoverage: true
},
mochaReporter: {
// https://www.npmjs.com/package/karma-mocha-reporter
output: 'autowatch'
},
autoWatch : false,
colors : true,
concurrency: Infinity,
port : 9876,
singleRun : true,
// browserDisconnectTimeout : 1000*10, // default 2000
// browserDisconnectTolerance: 1, // default 0
// browserNoActivityTimeout : 1000*30, // default 10000
// captureTimeout : 1000*60, // default 60000
client: {
mocha: {
// timeout: 1000*20 // default 2000
}
}
};
// Export
// =============================================================================
module.exports = function(config) {
const isRemote = Boolean(process.argv.indexOf('--remote') > -1);
// Remote test
if (isRemote) {
// Browsers
// https://www.browserstack.com/automate/capabilities
settings.customLaunchers = {
bs_chrome: {
base : 'BrowserStack',
browser : 'Chrome',
browser_version: '48.0',
os : 'Windows',
os_version : '10'
},
bs_firefox: {
base : 'BrowserStack',
browser : 'Firefox',
browser_version: '32',
os : 'Windows',
os_version : '10'
},
bs_ie_11: {
base : 'BrowserStack',
browser : 'IE',
browser_version: '11.0',
os : 'Windows',
os_version : '10'
},
bs_safari: {
base : 'BrowserStack',
browser : 'Safari',
os : 'OS X',
os_version : 'Sierra'
}
};
settings.browsers = Object.keys(settings.customLaunchers);
// BrowserStack
settings.reporters.push('BrowserStack');
settings.browserStack = {
username : process.env.BROWSERSTACK_USERNAME,
accessKey: process.env.BROWSERSTACK_ACCESS_KEY,
build : [
`${process.env.GITHUB_RUN_ID ? 'GitHub' : 'Local'}:${gitInfo.branch} -`,
gitInfo.isClean ? gitInfo.commitMsg : 'Uncommitted changes',
`@ ${new Date().toLocaleString('en-US', { month: 'numeric', day: 'numeric', year: 'numeric', hour: 'numeric', minute: 'numeric', timeZoneName: 'short', hour12: true })}`
].join(' '),
project : pkg.name,
video : false
};
}
// Local
else {
settings.browsers = ['ChromeHeadless'];
settings.webpack.devtool = 'inline-source-map';
settings.coverageIstanbulReporter.reports.push('html');
// eslint-disable-next-line
console.log([
'============================================================\n',
`KARMA: localhost:${settings.port}/debug.html\n`,
'============================================================\n'
].join(''));
}
// Logging: LOG_DISABLE, LOG_ERROR, LOG_WARN, LOG_INFO, LOG_DEBUG
settings.logLevel = config.LOG_INFO;
config.set(settings);
};