-
Notifications
You must be signed in to change notification settings - Fork 439
Expand file tree
/
Copy pathutils.js
More file actions
116 lines (99 loc) · 3.38 KB
/
utils.js
File metadata and controls
116 lines (99 loc) · 3.38 KB
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
/*
* Copyright (c) 2024, Salesforce, Inc.
* All rights reserved.
* SPDX-License-Identifier: MIT
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
*/
'use strict';
const {
GITHUB_RUN_ID,
IS_CI,
SAUCE_ACCESS_KEY,
SAUCE_TUNNEL_ID,
SAUCE_USERNAME,
SAUCE_REGION,
} = require('../shared/options');
function getSauceSection({ suiteName, customData }) {
const username = SAUCE_USERNAME;
if (!username) {
throw new TypeError('Missing SAUCE_USERNAME environment variable');
}
const accessKey = SAUCE_ACCESS_KEY;
if (!accessKey) {
throw new TypeError('Missing SAUCE_ACCESS_KEY environment variable');
}
const buildId = GITHUB_RUN_ID || Date.now();
const testName = suiteName;
const build = `${suiteName} - ${buildId}`;
return {
username,
accessKey,
tunnelIdentifier: SAUCE_TUNNEL_ID,
region: SAUCE_REGION,
build,
testName,
customData: {
...customData,
ci: IS_CI,
buildId,
},
startConnect: false,
recordVideo: false,
recordScreenshots: false,
};
}
function createPattern(location, config = {}) {
return {
...config,
pattern: location,
};
}
function getSauceConfig(config, { suiteName, customData, browsers }) {
return {
sauceLabs: getSauceSection({ suiteName, customData }),
browsers: browsers.map((browser) => browser.label),
customLaunchers: browsers.reduce((acc, browser) => {
// Karma-sauce-launcher uses the browserVersion key to determine if the format is W3C or JWP (deprecated).
// https://github.com/karma-runner/karma-sauce-launcher/blob/59b0c5c877448e064ad56449cd906743721c6b62/src/utils.ts#L15-L18
// Standard karma tests need to be in W3C in order to pass the sauce:options.
// Details about W3C and JWP formats: https://saucelabs.com/platform/platform-configurator
const {
label,
browserName,
// platformName is only applicable for W3C
platformName,
// platform is only applicable for JWP
platform,
// browserVersion is only applicable for W3C
browserVersion,
// version is only applicable for JWP
version,
// sauce:options is only applicable for W3C
sauceOptions,
} = browser;
return {
...acc,
[label]: {
base: 'SauceLabs',
browserName,
platformName,
platform,
browserVersion,
version,
'sauce:options': sauceOptions,
},
};
}, {}),
// Use a less verbose reporter for the CI to avoid generating too much log.
reporters: IS_CI
? [...config.reporters, 'dots', 'saucelabs']
: [...config.reporters, 'progress', 'saucelabs'],
plugins: [...config.plugins, 'karma-sauce-launcher-fix-firefox'],
// Force Karma to run in singleRun mode in order to shutdown the server after the tests finished to run.
singleRun: true,
};
}
module.exports = {
createPattern,
getSauceConfig,
};