-
Notifications
You must be signed in to change notification settings - Fork 139
/
karma.ci.conf.js
115 lines (98 loc) · 2.87 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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
const branchName = require('current-git-branch');
const staticConfig = require('./karma.conf').staticConfig;
const {
capabilities: browserStackCapabilities,
projectName: project
} = require('./test/conf/browserstack');
const {
BROWSER = 'Chrome',
REPORT_COVERAGE = false,
GITHUB_RUN_ID
} = process.env;
const BROWSER_STACK_CAPABILITY = browserStackCapabilities[BROWSER];
function runner (config) {
const cfg = Object.assign({}, staticConfig, {
reporters: ['mocha'],
logLevel: config.LOG_INFO,
browsers: [BROWSER],
customLaunchers: customLaunchers(),
hostname: hostname()
});
if (REPORT_COVERAGE) {
cfg.reporters.push('coverage');
}
if (BROWSER_STACK_CAPABILITY) {
let localIdentifier = `${Math.round(Math.random() * 100)}-${Date.now()}`;
cfg.browserStack = {
project,
build: `${GITHUB_RUN_ID || `local unit [${branchName()}]`}`,
autoAcceptAlerts: true,
forceLocal: true,
'browserstack.local': true,
'browserstack.debug': true,
'browserstack.console': 'verbose',
'browserstack.networkLogs': true,
captureTimeout: 1200,
pollingTimeout: 4000,
timeout: 1200,
localIdentifier,
};
cfg.reporters.push('BrowserStack');
}
console.log(cfg);
config.set(cfg);
}
require('@recurly/public-api-test-server');
module.exports = runner;
function customLaunchers () {
const launchers = {
ChromeHeadlessCI: {
base: 'ChromeHeadless',
flags: ['--no-sandbox']
}
};
if (BROWSER_STACK_CAPABILITY) {
launchers[BROWSER] = toLegacyLauncher(BROWSER_STACK_CAPABILITY);
}
return launchers;
}
/**
* karma-browserstack-launcher only supports the legacy
* JSONWP WebDriver protocol
*
* @param {Object} capability
* @return {Object}
*/
function toLegacyLauncher (capability) {
const capabilities = Object.assign({}, capability);
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;
}
function hostname () {
if (BROWSER_STACK_CAPABILITY) return 'bs-local.com';
return 'localhost';
}