forked from mochajs/mocha
-
Notifications
You must be signed in to change notification settings - Fork 0
/
karma.conf.js
169 lines (155 loc) · 4.99 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
'use strict';
var fs = require('fs');
var path = require('path');
var mkdirp = require('mkdirp');
var baseBundleDirpath = path.join(__dirname, '.karma');
var osName = require('os-name');
module.exports = function (config) {
var bundleDirpath;
var cfg = {
frameworks: [
'browserify',
'expect',
'mocha'
],
files: [
// we use the BDD interface for all of the tests that
// aren't interface-specific.
'test/browser-fixtures/bdd.fixture.js',
'test/acceptance/*.spec.js'
],
exclude: [
'test/acceptance/http.spec.js',
'test/acceptance/fs.spec.js',
'test/acceptance/file-utils.spec.js',
'test/acceptance/require/**/*.js',
'test/acceptance/misc/**/*.js'
],
preprocessors: {
'test/**/*.js': ['browserify']
},
browserify: {
debug: true,
configure: function configure (b) {
b.ignore('glob')
.ignore('fs')
.ignore('path')
.ignore('supports-color')
.on('bundled', function (err, content) {
if (!err && bundleDirpath) {
// write bundle to directory for debugging
fs.writeFileSync(path.join(bundleDirpath,
'bundle.' + Date.now() + '.js'), content);
}
});
}
},
reporters: ['spec'],
colors: true,
browsers: [osName() === 'macOS Sierra' ? 'Chrome' : 'PhantomJS'], // This is the default browser to run, locally
logLevel: config.LOG_INFO,
client: {
mocha: {
reporter: 'html'
}
}
};
// see https://github.com/saucelabs/karma-sauce-example
// We define the browser to run on the Saucelabs Infrastructure
// via the environment variables BROWSER and PLATFORM.
// PLATFORM is e.g. "Windows"
// BROWSER is expected to be in the format "<name>@<version>",
// e.g. "MicrosoftEdge@latest"
// See https://wiki.saucelabs.com/display/DOCS/Platform+Configurator#/
// for available browsers.
// TO RUN LOCALLY, execute:
// `CI=1 SAUCE_USERNAME=<user> SAUCE_ACCESS_KEY=<key> BROWSER=<browser> PLATFORM=<platform> make test-browser`
var env = process.env;
var 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.BROWSER && env.PLATFORM) {
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
};
console.error('Configured SauceLabs');
} else {
console.error('No SauceLabs credentials present');
}
}
} else if (env.APPVEYOR) {
console.error('AppVeyor detected');
bundleDirpath = path.join(baseBundleDirpath, process.env.APPVEYOR_BUILD_ID);
} 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)) {
console.error('No SauceLabs credentials present');
} else {
sauceConfig = {
build: require('os').hostname() + ' (' + Date.now() + ')'
};
console.error('Configured SauceLabs');
}
}
mkdirp.sync(bundleDirpath);
} else {
console.error('CI mode disabled');
}
if (sauceConfig) {
cfg.sauceLabs = sauceConfig;
addSauceTests(cfg);
}
// the MOCHA_UI env var will determine if we're running interface-specific
// tests. since you can only load one at a time, each must be run separately.
// each has its own set of acceptance tests and a fixture.
// the "bdd" fixture is used by default.
var ui = env.MOCHA_UI;
if (ui) {
if (cfg.sauceLabs) {
cfg.sauceLabs.testName = 'Interface "' + ui + '" integration tests';
}
cfg.files = [
'test/browser-fixtures/' + ui + '.fixture.js',
'test/acceptance/interfaces/' + ui + '.spec.js'
];
} else if (cfg.sauceLabs) {
cfg.sauceLabs.testName = 'Unit Tests';
}
config.set(cfg);
};
function addSauceTests (cfg) {
var env = process.env;
cfg.reporters.push('saucelabs');
cfg.customLaunchers = {};
cfg.customLaunchers[env.BROWSER] = {
base: 'SauceLabs',
browserName: env.BROWSER.split('@')[0],
version: env.BROWSER.split('@')[1],
platform: env.PLATFORM
};
cfg.browsers = [env.BROWSER];
// See https://github.com/karma-runner/karma-sauce-launcher
// See https://github.com/bermi/sauce-connect-launcher#advanced-usage
cfg.sauceLabs = {
public: 'public',
startConnect: true,
connectOptions: {
connectRetries: 10,
connectRetryTimeout: 60000
}
};
cfg.concurrency = 5;
cfg.retryLimit = 5;
// for slow browser booting, ostensibly
cfg.captureTimeout = 120000;
cfg.browserNoActivityTimeout = 20000;
}