-
-
Notifications
You must be signed in to change notification settings - Fork 64
/
karma.conf.js
176 lines (166 loc) · 6.12 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
// Dependencies
// =============================================================================
const fs = require('fs');
const pkg = JSON.parse(fs.readFileSync('./package.json', 'utf8'));
const { execSync } = require('child_process');
// Variables
// =============================================================================
const files = {
fixtures: './tests/fixtures/**/*',
test : './tests/**/*.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: [
files.test,
// Served only (Access in tests by prepending /base/ to path)
{ pattern: files.fixtures, included: false, served: true, watched: true }
],
preprocessors: {
[files.fixtures]: ['file-fixtures'],
[files.test] : ['eslint', 'webpack', 'sourcemap']
},
frameworks: ['mocha', 'chai', 'webpack'],
reporters : ['mocha', 'coverage-istanbul'], // 'Browserstack' added below
fileFixtures: {
stripPrefix: 'tests/fixtures/'
},
webpack: {
mode : 'development',
module: {
rules: [
{
test : /\.js$/,
exclude: [/node_modules/],
use : [
{
loader : 'babel-loader',
options: {
// See .babelrc
plugins: [
['istanbul', { include: 'src/*' }]
]
},
}
]
}
]
}
},
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: {
// Prevent browser messages from appearing in terminal
captureConsole: false,
mocha: {
timeout: 1000*5 // default 2000
}
}
};
// Export
// =============================================================================
module.exports = function(config) {
const isDebug = Boolean(process.argv.indexOf('--debug') > -1);
const isRemote = Boolean(process.argv.indexOf('--remote') > -1);
// Remote test
if (isRemote) {
// Browsers
// https://www.browserstack.com/automate/capabilities
settings.customLaunchers = {
bs_chrome_latest: {
base : 'BrowserStack',
browser : 'Chrome',
os : 'Windows',
os_version : '10'
},
bs_chrome: {
base : 'BrowserStack',
browser : 'Chrome',
browser_version: '48.0',
os : 'Windows',
os_version : '10'
},
bs_ie_11: {
base : 'BrowserStack',
browser : 'IE',
browser_version: '11.0',
os : 'Windows',
os_version : '10'
}
};
settings.browsers = Object.keys(settings.customLaunchers);
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.customLaunchers = {
ChromeHeadlessDebug: {
base : 'ChromeHeadless',
flags: [
'--disable-extensions',
'--remote-debugging-port=9333'
]
},
};
settings.browsers = [].concat(
Object.keys(settings.customLaunchers)
// 'jsdom' // SSR Testing
);
settings.webpack.devtool = 'inline-source-map';
settings.coverageIstanbulReporter.reports.push('html');
if (isDebug) {
// Prevent disconnect during VSCode debugging
settings.browserDisconnectTimeout = 1000*6000; // default 2000
}
// 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);
};