-
Notifications
You must be signed in to change notification settings - Fork 139
/
karma.ci.conf.js
99 lines (88 loc) · 2.62 KB
/
karma.ci.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
const branchName = require('current-git-branch');
const staticConfig = require('./karma.conf').staticConfig;
const {
capabilities: launchers,
projectName: project
} = require('./test/conf/browserstack');
const {
BROWSER,
REPORT_COVERAGE,
TRAVIS_BUILD_NUMBER
} = process.env;
const localIdentifier = `${Math.round(Math.random() * 100)}-${Date.now()}`;
function runner (config) {
const reporters = ['mocha', 'BrowserStack'];
if (REPORT_COVERAGE) reporters.push('coverage');
const logLevel = config.LOG_INFO;
const launcherName = `bs_${BROWSER || 'chrome'}`;
const cfg = Object.assign({}, staticConfig, {
reporters,
logLevel,
browsers: [launcherName],
browserStack: {
project,
build: `${TRAVIS_BUILD_NUMBER || `local unit [${branchName()}]`}`,
autoAcceptAlerts: true,
forceLocal: true,
'browserstack.local': true,
'browserstack.debug': true,
'browserstack.console': 'verbose',
'browserstack.networkLogs': true,
captureTimeout: 1200,
localIdentifier,
pollingTimeout: 4000,
timeout: 1200
},
customLaunchers: {
[launcherName]: toLegacyLauncher(launchers[launcherName]),
bs_chrome_headless: {
base: 'ChromeHeadless',
flags: ['--no-sandbox']
},
bs_electron: {
base: 'Electron'
}
},
hostname: 'bs-local.com'
});
console.log(cfg)
config.set(cfg);
};
const server = require('./test/server');
module.exports = runner;
/**
* karma-browserstack-launcher only supports the legacy
* JSONWP WebDriver protocol
*
* @param {Object} launcher
* @return {Object}
*/
function toLegacyLauncher (launcher) {
const capabilities = Object.assign({}, launcher);
const translations = {
browserName: 'browser',
browserVersion: 'browser_version',
deviceName: 'device',
osVersion: 'os_version',
realMobile: 'real_mobile'
};
for (const [newCap, oldCap] of Object.entries(translations)) {
if (capabilities[newCap]) {
delete Object.assign(capabilities, { [oldCap]: capabilities[newCap] })[newCap];
}
}
capabilities.base = 'BrowserStack';
// Csutom transformations
if (capabilities.ie) {
capabilities.os_version = '10';
capabilities['browserstack.ie.enablePopups'] = capabilities.ie.enablePopups;
delete capabilities.ie;
} else if (capabilities.edge) {
capabilities['browserstack.edge.enablePopups'] = capabilities.edge.enablePopups;
delete capabilities.edge;
} else if (capabilities.safari) {
capabilities['browserstack.safari.enablePopups'] = capabilities.safari.enablePopups;
delete capabilities.safari;
}
return capabilities;
}