forked from mochajs/mocha
-
Notifications
You must be signed in to change notification settings - Fork 0
/
karma.conf.js
197 lines (183 loc) · 5.44 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
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
'use strict';
const fs = require('fs');
const path = require('path');
const mkdirp = require('mkdirp');
const baseBundleDirpath = path.join(__dirname, '.karma');
const browserPlatformPairs = {
'chrome@latest': 'Windows 8',
'MicrosoftEdge@latest': 'Windows 10',
'internet [email protected]': 'Windows 8.1',
'firefox@latest': 'Windows 10',
'safari@latest': 'OS X 10.12'
};
module.exports = config => {
let bundleDirpath;
const cfg = {
frameworks: ['browserify', 'mocha'],
files: [
// we use the BDD interface for all of the tests that
// aren't interface-specific.
'test/browser-fixtures/bdd.fixture.js',
'test/unit/*.spec.js'
],
preprocessors: {
'test/**/*.js': ['browserify']
},
browserify: {
debug: true,
configure: function configure(b) {
b
.ignore('glob')
.ignore('fs')
.ignore('path')
.ignore('supports-color')
.on('bundled', (err, content) => {
if (err) {
throw err;
}
if (bundleDirpath) {
// write bundle to directory for debugging
fs.writeFileSync(
path.join(bundleDirpath, `mocha.${Date.now()}.js`),
content
);
}
});
}
},
reporters: ['mocha'],
colors: true,
browsers: ['ChromeHeadless'],
logLevel: config.LOG_INFO,
client: {
mocha: {
reporter: 'html',
timeout: 500
}
},
mochaReporter: {
showDiff: true
},
customLaunchers: {
ChromeDebug: {
base: 'Chrome',
flags: ['--remote-debugging-port=9333']
}
}
};
// TO RUN AGAINST SAUCELABS LOCALLY, execute:
// `CI=1 SAUCE_USERNAME=<user> SAUCE_ACCESS_KEY=<key> npm start test.browser`
const env = process.env;
let sauceConfig;
if (env.CI) {
console.error('CI mode enabled');
if (env.TRAVIS) {
console.error('Travis-CI detected');
bundleDirpath = path.join(baseBundleDirpath, process.env.TRAVIS_BUILD_ID);
if (env.SAUCE_USERNAME && env.SAUCE_ACCESS_KEY) {
// correlate build/tunnel with Travis
sauceConfig = {
build: `TRAVIS #${env.TRAVIS_BUILD_NUMBER} (${env.TRAVIS_BUILD_ID})`,
tunnelIdentifier: env.TRAVIS_JOB_NUMBER,
startConnect: false
};
console.error('Configured SauceLabs');
} else {
console.error('No SauceLabs credentials present');
}
} else if (env.APPVEYOR) {
throw new Error('no browser tests should run on AppVeyor!');
} else {
console.error('Local/unknown environment detected');
bundleDirpath = path.join(baseBundleDirpath, 'local');
// don't need to run sauce from appveyor b/c travis does it.
if (env.SAUCE_USERNAME || env.SAUCE_ACCESS_KEY) {
const id = `${require('os').hostname()} (${Date.now()})`;
sauceConfig = {
build: id,
tunnelIdentifier: id,
startConnect: true
};
console.error('Configured SauceLabs');
} else {
console.error('No SauceLabs credentials present');
}
}
mkdirp.sync(bundleDirpath);
} else {
console.error('CI mode disabled');
}
if (sauceConfig) {
cfg.sauceLabs = sauceConfig;
addSauceTests(cfg);
}
/* the MOCHA_TEST env var will be set for "special" cases of tests.
* these may require different interfaces or other setup which make
* them unable to be batched w/ the rest.
*/
const MOCHA_TEST = env.MOCHA_TEST;
switch (MOCHA_TEST) {
case 'bdd':
case 'tdd':
case 'qunit':
if (cfg.sauceLabs) {
cfg.sauceLabs.testName = `Interface "${MOCHA_TEST}" Integration Tests`;
}
cfg.files = [
`test/browser-fixtures/${MOCHA_TEST}.fixture.js`,
`test/interfaces/${MOCHA_TEST}.spec.js`
];
break;
case 'esm':
// just run against ChromeHeadless, since other browsers may not
// support
cfg.browsers = ['ChromeHeadless'];
cfg.files = [
'test/browser-specific/esm.spec.js',
'test/browser-fixtures/esm.fixture.html'
];
break;
default:
if (cfg.sauceLabs) {
cfg.sauceLabs.testName = 'Unit Tests';
}
}
cfg.files.unshift(
'node_modules/unexpected/unexpected.js',
{pattern: 'node_modules/unexpected/unexpected.js.map', included: false},
'test/browser-specific/setup.js'
);
config.set(cfg);
};
function addSauceTests(cfg) {
cfg.reporters.push('saucelabs');
const browsers = Object.keys(browserPlatformPairs);
cfg.browsers = cfg.browsers.concat(browsers);
cfg.customLaunchers = browsers.reduce((acc, browser) => {
const platform = browserPlatformPairs[browser];
const [browserName, version] = browser.split('@');
acc[browser] = {
base: 'SauceLabs',
browserName: browserName,
version: version,
platform: platform
};
return acc;
}, cfg.customLaunchers);
// See https://github.com/karma-runner/karma-sauce-launcher
// See https://github.com/bermi/sauce-connect-launcher#advanced-usage
Object.assign(cfg.sauceLabs, {
public: 'public',
connectOptions: {
connectRetries: 2,
connectRetryTimeout: 30000,
detached: cfg.sauceLabs.startConnect,
tunnelIdentifier: cfg.sauceLabs.tunnelIdentifier
}
});
cfg.concurrency = Infinity;
cfg.retryLimit = 1;
// for slow browser booting, ostensibly
cfg.captureTimeout = 120000;
cfg.browserNoActivityTimeout = 20000;
}