browserstack-cypress-cli 1.25.2 → 1.26.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/accessibility-automation/constants.js +1 -0
- package/bin/accessibility-automation/cypress/index.js +140 -0
- package/bin/accessibility-automation/helper.js +218 -0
- package/bin/accessibility-automation/plugin/index.js +43 -0
- package/bin/commands/runs.js +16 -0
- package/bin/helpers/capabilityHelper.js +17 -0
- package/bin/helpers/helper.js +305 -0
- package/bin/helpers/utils.js +17 -0
- package/bin/testObservability/helper/helper.js +8 -224
- package/package.json +1 -1
- package/log/usage.log +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
exports.API_URL = 'https://accessibility.browserstack.com/api';
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
/* Event listeners + custom commands for Cypress */
|
|
2
|
+
|
|
3
|
+
Cypress.on('test:before:run', () => {
|
|
4
|
+
try {
|
|
5
|
+
if (Cypress.env("IS_ACCESSIBILITY_EXTENSION_LOADED") !== "true") return
|
|
6
|
+
const extensionPath = Cypress.env("ACCESSIBILITY_EXTENSION_PATH")
|
|
7
|
+
|
|
8
|
+
if (extensionPath !== undefined) {
|
|
9
|
+
new Promise((resolve, reject) => {
|
|
10
|
+
window.parent.addEventListener('A11Y_TAP_STARTED', () => {
|
|
11
|
+
resolve("A11Y_TAP_STARTED");
|
|
12
|
+
});
|
|
13
|
+
const e = new CustomEvent('A11Y_FORCE_START');
|
|
14
|
+
window.parent.dispatchEvent(e);
|
|
15
|
+
})
|
|
16
|
+
}
|
|
17
|
+
} catch {}
|
|
18
|
+
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
Cypress.on('test:after:run', (attributes, runnable) => {
|
|
22
|
+
try {
|
|
23
|
+
if (Cypress.env("IS_ACCESSIBILITY_EXTENSION_LOADED") !== "true") return
|
|
24
|
+
const extensionPath = Cypress.env("ACCESSIBILITY_EXTENSION_PATH")
|
|
25
|
+
const isHeaded = Cypress.browser.isHeaded;
|
|
26
|
+
if (isHeaded && extensionPath !== undefined) {
|
|
27
|
+
|
|
28
|
+
let shouldScanTestForAccessibility = true;
|
|
29
|
+
if (Cypress.env("INCLUDE_TAGS_FOR_ACCESSIBILITY") || Cypress.env("EXCLUDE_TAGS_FOR_ACCESSIBILITY")) {
|
|
30
|
+
|
|
31
|
+
try {
|
|
32
|
+
let includeTagArray = [];
|
|
33
|
+
let excludeTagArray = [];
|
|
34
|
+
if (Cypress.env("INCLUDE_TAGS_FOR_ACCESSIBILITY")) {
|
|
35
|
+
includeTagArray = Cypress.env("INCLUDE_TAGS_FOR_ACCESSIBILITY").split(";")
|
|
36
|
+
}
|
|
37
|
+
if (Cypress.env("EXCLUDE_TAGS_FOR_ACCESSIBILITY")) {
|
|
38
|
+
excludeTagArray = Cypress.env("EXCLUDE_TAGS_FOR_ACCESSIBILITY").split(";")
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
const fullTestName = attributes.title;
|
|
42
|
+
const excluded = excludeTagArray.some((exclude) => fullTestName.includes(exclude));
|
|
43
|
+
const included = includeTagArray.length === 0 || includeTags.some((include) => fullTestName.includes(include));
|
|
44
|
+
shouldScanTestForAccessibility = !excluded && included;
|
|
45
|
+
} catch (error) {
|
|
46
|
+
console.log("Error while validating test case for accessibility before scanning. Error : ", error);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
let os_data;
|
|
50
|
+
if (Cypress.env("OS")) {
|
|
51
|
+
os_data = Cypress.env("OS");
|
|
52
|
+
} else {
|
|
53
|
+
os_data = Cypress.platform === 'linux' ? 'mac' : "win"
|
|
54
|
+
}
|
|
55
|
+
let filePath = '';
|
|
56
|
+
if (attributes.invocationDetails !== undefined && attributes.invocationDetails.relativeFile !== undefined) {
|
|
57
|
+
filePath = attributes.invocationDetails.relativeFile;
|
|
58
|
+
}
|
|
59
|
+
const dataForExtension = {
|
|
60
|
+
"saveResults": shouldScanTestForAccessibility,
|
|
61
|
+
"testDetails": {
|
|
62
|
+
"name": attributes.title,
|
|
63
|
+
"testRunId": '5058', // variable not consumed, shouldn't matter what we send
|
|
64
|
+
"filePath": filePath,
|
|
65
|
+
"scopeList": [
|
|
66
|
+
filePath,
|
|
67
|
+
attributes.title
|
|
68
|
+
]
|
|
69
|
+
},
|
|
70
|
+
"platform": {
|
|
71
|
+
"os_name": os_data,
|
|
72
|
+
"os_version": Cypress.env("OS_VERSION"),
|
|
73
|
+
"browser_name": Cypress.browser.name,
|
|
74
|
+
"browser_version": Cypress.browser.version
|
|
75
|
+
}
|
|
76
|
+
};
|
|
77
|
+
return new Promise((resolve, reject) => {
|
|
78
|
+
if (dataForExtension.saveResults) {
|
|
79
|
+
window.parent.addEventListener('A11Y_TAP_TRANSPORTER', (event) => {
|
|
80
|
+
resolve(event.detail);
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
const e = new CustomEvent('A11Y_TEST_END', {detail: dataForExtension});
|
|
84
|
+
window.parent.dispatchEvent(e);
|
|
85
|
+
if (dataForExtension.saveResults !== true )
|
|
86
|
+
resolve();
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
} catch {}
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
Cypress.Commands.add('getAccessibilityResultsSummary', () => {
|
|
94
|
+
try {
|
|
95
|
+
if (Cypress.env("IS_ACCESSIBILITY_EXTENSION_LOADED") !== "true") {
|
|
96
|
+
console.log(`Not a Accessibility Automation session, cannot retrieve Accessibility results.`);
|
|
97
|
+
return
|
|
98
|
+
}
|
|
99
|
+
return new Promise(function (resolve, reject) {
|
|
100
|
+
try{
|
|
101
|
+
const e = new CustomEvent('A11Y_TAP_GET_RESULTS_SUMMARY');
|
|
102
|
+
const fn = function (event) {
|
|
103
|
+
window.parent.removeEventListener('A11Y_RESULTS_SUMMARY_RESPONSE', fn);
|
|
104
|
+
resolve(event.detail.summary);
|
|
105
|
+
};
|
|
106
|
+
window.parent.addEventListener('A11Y_RESULTS_SUMMARY_RESPONSE', fn);
|
|
107
|
+
window.parent.dispatchEvent(e);
|
|
108
|
+
} catch (err) {
|
|
109
|
+
console.log("No accessibility results summary was found.");
|
|
110
|
+
reject(err);
|
|
111
|
+
}
|
|
112
|
+
});
|
|
113
|
+
} catch {}
|
|
114
|
+
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
Cypress.Commands.add('getAccessibilityResults', () => {
|
|
118
|
+
try {
|
|
119
|
+
if (Cypress.env("IS_ACCESSIBILITY_EXTENSION_LOADED") !== "true") {
|
|
120
|
+
console.log(`Not a Accessibility Automation session, cannot retrieve Accessibility results.`);
|
|
121
|
+
return
|
|
122
|
+
}
|
|
123
|
+
return new Promise(function (resolve, reject) {
|
|
124
|
+
try{
|
|
125
|
+
const e = new CustomEvent('A11Y_TAP_GET_RESULTS');
|
|
126
|
+
const fn = function (event) {
|
|
127
|
+
window.parent.removeEventListener('A11Y_RESULTS_RESPONSE', fn);
|
|
128
|
+
resolve(event.detail.summary);
|
|
129
|
+
};
|
|
130
|
+
window.parent.addEventListener('A11Y_RESULTS_RESPONSE', fn);
|
|
131
|
+
window.parent.dispatchEvent(e);
|
|
132
|
+
} catch (err) {
|
|
133
|
+
console.log("No accessibility results were found.");
|
|
134
|
+
reject(err);
|
|
135
|
+
}
|
|
136
|
+
});
|
|
137
|
+
} catch {}
|
|
138
|
+
|
|
139
|
+
});
|
|
140
|
+
|
|
@@ -0,0 +1,218 @@
|
|
|
1
|
+
const logger = require("../helpers/logger").winstonLogger;
|
|
2
|
+
const { API_URL } = require('./constants');
|
|
3
|
+
const utils = require('../helpers/utils');
|
|
4
|
+
const fs = require('fs');
|
|
5
|
+
const path = require('path');
|
|
6
|
+
const request = require('request');
|
|
7
|
+
const os = require('os');
|
|
8
|
+
const glob = require('glob');
|
|
9
|
+
const helper = require('../helpers/helper');
|
|
10
|
+
const { CYPRESS_V10_AND_ABOVE_CONFIG_FILE_EXTENSIONS } = require('../helpers/constants');
|
|
11
|
+
const supportFileContentMap = {}
|
|
12
|
+
|
|
13
|
+
exports.checkAccessibilityPlatform = (user_config) => {
|
|
14
|
+
let accessibility = false;
|
|
15
|
+
try {
|
|
16
|
+
user_config.browsers.forEach(browser => {
|
|
17
|
+
if (browser.accessibility) {
|
|
18
|
+
accessibility = true;
|
|
19
|
+
}
|
|
20
|
+
})
|
|
21
|
+
} catch {}
|
|
22
|
+
|
|
23
|
+
return accessibility;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
exports.setAccessibilityCypressCapabilities = async (user_config, accessibilityResponse) => {
|
|
27
|
+
if (utils.isUndefined(user_config.run_settings.accessibilityOptions)) {
|
|
28
|
+
user_config.run_settings.accessibilityOptions = {}
|
|
29
|
+
}
|
|
30
|
+
user_config.run_settings.accessibilityOptions["authToken"] = accessibilityResponse.data.accessibilityToken;
|
|
31
|
+
user_config.run_settings.accessibilityOptions["auth"] = accessibilityResponse.data.accessibilityToken;
|
|
32
|
+
user_config.run_settings.accessibilityOptions["scannerVersion"] = accessibilityResponse.data.scannerVersion;
|
|
33
|
+
user_config.run_settings.system_env_vars.push(`ACCESSIBILITY_AUTH=${accessibilityResponse.data.accessibilityToken}`)
|
|
34
|
+
user_config.run_settings.system_env_vars.push(`ACCESSIBILITY_SCANNERVERSION=${accessibilityResponse.data.scannerVersion}`)
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
exports.isAccessibilitySupportedCypressVersion = (cypress_config_filename) => {
|
|
38
|
+
const extension = cypress_config_filename.split('.').pop();
|
|
39
|
+
return CYPRESS_V10_AND_ABOVE_CONFIG_FILE_EXTENSIONS.includes(extension);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
exports.createAccessibilityTestRun = async (user_config, framework) => {
|
|
43
|
+
|
|
44
|
+
try {
|
|
45
|
+
if (!this.isAccessibilitySupportedCypressVersion(user_config.run_settings.cypress_config_file) ){
|
|
46
|
+
logger.warn(`Accessibility Testing is not supported on Cypress version 9 and below.`)
|
|
47
|
+
process.env.BROWSERSTACK_TEST_ACCESSIBILITY = 'false';
|
|
48
|
+
user_config.run_settings.accessibility = false;
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
const userName = user_config["auth"]["username"];
|
|
52
|
+
const accessKey = user_config["auth"]["access_key"];
|
|
53
|
+
let settings = utils.isUndefined(user_config.run_settings.accessibilityOptions) ? {} : user_config.run_settings.accessibilityOptions
|
|
54
|
+
|
|
55
|
+
const {
|
|
56
|
+
buildName,
|
|
57
|
+
projectName,
|
|
58
|
+
buildDescription
|
|
59
|
+
} = helper.getBuildDetails(user_config);
|
|
60
|
+
|
|
61
|
+
const data = {
|
|
62
|
+
'projectName': projectName,
|
|
63
|
+
'buildName': buildName,
|
|
64
|
+
'startTime': (new Date()).toISOString(),
|
|
65
|
+
'description': buildDescription,
|
|
66
|
+
'source': {
|
|
67
|
+
frameworkName: "Cypress",
|
|
68
|
+
frameworkVersion: helper.getPackageVersion('cypress', user_config),
|
|
69
|
+
sdkVersion: helper.getAgentVersion()
|
|
70
|
+
},
|
|
71
|
+
'settings': settings,
|
|
72
|
+
'versionControl': await helper.getGitMetaData(),
|
|
73
|
+
'ciInfo': helper.getCiInfo(),
|
|
74
|
+
'hostInfo': {
|
|
75
|
+
hostname: os.hostname(),
|
|
76
|
+
platform: os.platform(),
|
|
77
|
+
type: os.type(),
|
|
78
|
+
version: os.version(),
|
|
79
|
+
arch: os.arch()
|
|
80
|
+
},
|
|
81
|
+
'browserstackAutomation': process.env.BROWSERSTACK_AUTOMATION === 'true'
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
const config = {
|
|
85
|
+
auth: {
|
|
86
|
+
user: userName,
|
|
87
|
+
pass: accessKey
|
|
88
|
+
},
|
|
89
|
+
headers: {
|
|
90
|
+
'Content-Type': 'application/json'
|
|
91
|
+
}
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
const response = await nodeRequest(
|
|
95
|
+
'POST', 'test_runs', data, config, API_URL
|
|
96
|
+
);
|
|
97
|
+
if(!utils.isUndefined(response.data)) {
|
|
98
|
+
process.env.BS_A11Y_JWT = response.data.data.accessibilityToken;
|
|
99
|
+
process.env.BS_A11Y_TEST_RUN_ID = response.data.data.id;
|
|
100
|
+
}
|
|
101
|
+
if (process.env.BS_A11Y_JWT) {
|
|
102
|
+
process.env.BROWSERSTACK_TEST_ACCESSIBILITY = 'true';
|
|
103
|
+
}
|
|
104
|
+
logger.debug(`BrowserStack Accessibility Automation Test Run ID: ${response.data.data.id}`);
|
|
105
|
+
|
|
106
|
+
this.setAccessibilityCypressCapabilities(user_config, response.data);
|
|
107
|
+
setAccessibilityEventListeners();
|
|
108
|
+
helper.setBrowserstackCypressCliDependency(user_config);
|
|
109
|
+
|
|
110
|
+
} catch (error) {
|
|
111
|
+
if (error.response) {
|
|
112
|
+
logger.error(
|
|
113
|
+
`Exception while creating test run for BrowserStack Accessibility Automation: ${
|
|
114
|
+
error.response.status
|
|
115
|
+
} ${error.response.statusText} ${JSON.stringify(error.response.data)}`
|
|
116
|
+
);
|
|
117
|
+
} else {
|
|
118
|
+
if(error.message === 'Invalid configuration passed.') {
|
|
119
|
+
logger.error(
|
|
120
|
+
`Exception while creating test run for BrowserStack Accessibility Automation: ${
|
|
121
|
+
error.message || error.stack
|
|
122
|
+
}`
|
|
123
|
+
);
|
|
124
|
+
for(const errorkey of error.errors){
|
|
125
|
+
logger.error(errorkey.message);
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
} else {
|
|
129
|
+
logger.error(
|
|
130
|
+
`Exception while creating test run for BrowserStack Accessibility Automation: ${
|
|
131
|
+
error.message || error.stack
|
|
132
|
+
}`
|
|
133
|
+
);
|
|
134
|
+
}
|
|
135
|
+
// since create accessibility session failed
|
|
136
|
+
process.env.BROWSERSTACK_TEST_ACCESSIBILITY = 'false';
|
|
137
|
+
user_config.run_settings.accessibility = false;
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
const nodeRequest = (type, url, data, config) => {
|
|
143
|
+
return new Promise(async (resolve, reject) => {
|
|
144
|
+
const options = {...config,...{
|
|
145
|
+
method: type,
|
|
146
|
+
url: `${API_URL}/${url}`,
|
|
147
|
+
body: data,
|
|
148
|
+
json: config.headers['Content-Type'] === 'application/json',
|
|
149
|
+
}};
|
|
150
|
+
|
|
151
|
+
request(options, function callback(error, response, body) {
|
|
152
|
+
if(error) {
|
|
153
|
+
logger.info("error in nodeRequest", error);
|
|
154
|
+
reject(error);
|
|
155
|
+
} else if(!(response.statusCode == 201 || response.statusCode == 200)) {
|
|
156
|
+
logger.info("response.statusCode in nodeRequest", response.statusCode);
|
|
157
|
+
reject(response && response.body ? response.body : `Received response from BrowserStack Server with status : ${response.statusCode}`);
|
|
158
|
+
} else {
|
|
159
|
+
try {
|
|
160
|
+
if(typeof(body) !== 'object') body = JSON.parse(body);
|
|
161
|
+
} catch(e) {
|
|
162
|
+
if(!url.includes('/stop')) {
|
|
163
|
+
reject('Not a JSON response from BrowserStack Server');
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
resolve({
|
|
167
|
+
data: body
|
|
168
|
+
});
|
|
169
|
+
}
|
|
170
|
+
});
|
|
171
|
+
});
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
exports.supportFileCleanup = () => {
|
|
175
|
+
logger.debug("Cleaning up support file changes added for accessibility. ")
|
|
176
|
+
Object.keys(supportFileContentMap).forEach(file => {
|
|
177
|
+
try {
|
|
178
|
+
fs.writeFileSync(file, supportFileContentMap[file], {encoding: 'utf-8'});
|
|
179
|
+
} catch(e) {
|
|
180
|
+
logger.debug(`Error while replacing file content for ${file} with it's original content with error : ${e}`, true, e);
|
|
181
|
+
}
|
|
182
|
+
});
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
const getAccessibilityCypressCommandEventListener = () => {
|
|
186
|
+
return (
|
|
187
|
+
`require('browserstack-cypress-cli/bin/accessibility-automation/cypress');`
|
|
188
|
+
);
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
const setAccessibilityEventListeners = () => {
|
|
192
|
+
try {
|
|
193
|
+
const cypressCommandEventListener = getAccessibilityCypressCommandEventListener();
|
|
194
|
+
glob(process.cwd() + '/cypress/support/*.js', {}, (err, files) => {
|
|
195
|
+
if(err) return logger.debug('EXCEPTION IN BUILD START EVENT : Unable to parse cypress support files');
|
|
196
|
+
files.forEach(file => {
|
|
197
|
+
try {
|
|
198
|
+
if(!file.includes('commands.js')) {
|
|
199
|
+
const defaultFileContent = fs.readFileSync(file, {encoding: 'utf-8'});
|
|
200
|
+
|
|
201
|
+
if(!defaultFileContent.includes(cypressCommandEventListener)) {
|
|
202
|
+
let newFileContent = defaultFileContent +
|
|
203
|
+
'\n' +
|
|
204
|
+
cypressCommandEventListener +
|
|
205
|
+
'\n'
|
|
206
|
+
fs.writeFileSync(file, newFileContent, {encoding: 'utf-8'});
|
|
207
|
+
supportFileContentMap[file] = defaultFileContent;
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
} catch(e) {
|
|
211
|
+
logger.debug(`Unable to modify file contents for ${file} to set event listeners with error ${e}`, true, e);
|
|
212
|
+
}
|
|
213
|
+
});
|
|
214
|
+
});
|
|
215
|
+
} catch(e) {
|
|
216
|
+
logger.debug(`Unable to parse support files to set event listeners with error ${e}`, true, e);
|
|
217
|
+
}
|
|
218
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
|
|
2
|
+
const path = require("node:path");
|
|
3
|
+
|
|
4
|
+
const browserstackAccessibility = (on, config) => {
|
|
5
|
+
let browser_validation = true;
|
|
6
|
+
on('before:browser:launch', (browser = {}, launchOptions) => {
|
|
7
|
+
try {
|
|
8
|
+
|
|
9
|
+
if (process.env.ACCESSIBILITY_EXTENSION_PATH !== undefined) {
|
|
10
|
+
if (browser.name !== 'chrome') {
|
|
11
|
+
console.log(`Accessibility Automation will run only on Chrome browsers.`);
|
|
12
|
+
browser_validation = false;
|
|
13
|
+
}
|
|
14
|
+
if (browser.name === 'chrome' && browser.majorVersion <= 94) {
|
|
15
|
+
console.log(`Accessibility Automation will run only on Chrome browser version greater than 94.`);
|
|
16
|
+
browser_validation = false;
|
|
17
|
+
}
|
|
18
|
+
if (browser.isHeadless === true) {
|
|
19
|
+
console.log(`Accessibility Automation will not run on legacy headless mode. Switch to new headless mode or avoid using headless mode.`);
|
|
20
|
+
browser_validation = false;
|
|
21
|
+
}
|
|
22
|
+
if (browser_validation) {
|
|
23
|
+
const ally_path = path.dirname(process.env.ACCESSIBILITY_EXTENSION_PATH)
|
|
24
|
+
launchOptions.extensions.push(ally_path);
|
|
25
|
+
return launchOptions
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
} catch(err) {}
|
|
29
|
+
|
|
30
|
+
})
|
|
31
|
+
config.env.ACCESSIBILITY_EXTENSION_PATH = process.env.ACCESSIBILITY_EXTENSION_PATH
|
|
32
|
+
config.env.OS_VERSION = process.env.OS_VERSION
|
|
33
|
+
config.env.OS = process.env.OS
|
|
34
|
+
|
|
35
|
+
config.env.IS_ACCESSIBILITY_EXTENSION_LOADED = browser_validation.toString()
|
|
36
|
+
|
|
37
|
+
config.env.INCLUDE_TAGS_FOR_ACCESSIBILITY = process.env.ACCESSIBILITY_INCLUDETAGSINTESTINGSCOPE
|
|
38
|
+
config.env.EXCLUDE_TAGS_FOR_ACCESSIBILITY = process.env.ACCESSIBILITY_EXCLUDETAGSINTESTINGSCOPE
|
|
39
|
+
|
|
40
|
+
return config;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
module.exports = browserstackAccessibility;
|
package/bin/commands/runs.js
CHANGED
|
@@ -30,6 +30,13 @@ const {
|
|
|
30
30
|
printBuildLink
|
|
31
31
|
} = require('../testObservability/helper/helper');
|
|
32
32
|
|
|
33
|
+
|
|
34
|
+
const {
|
|
35
|
+
createAccessibilityTestRun,
|
|
36
|
+
checkAccessibilityPlatform,
|
|
37
|
+
supportFileCleanup
|
|
38
|
+
} = require('../accessibility-automation/helper');
|
|
39
|
+
|
|
33
40
|
module.exports = function run(args, rawArgs) {
|
|
34
41
|
|
|
35
42
|
markBlockStart('preBuild');
|
|
@@ -57,6 +64,8 @@ module.exports = function run(args, rawArgs) {
|
|
|
57
64
|
Set testObservability & browserstackAutomation flags
|
|
58
65
|
*/
|
|
59
66
|
const [isTestObservabilitySession, isBrowserstackInfra] = setTestObservabilityFlags(bsConfig);
|
|
67
|
+
const checkAccessibility = checkAccessibilityPlatform(bsConfig);
|
|
68
|
+
const isAccessibilitySession = bsConfig.run_settings.accessibility || checkAccessibility;
|
|
60
69
|
|
|
61
70
|
utils.setUsageReportingFlag(bsConfig, args.disableUsageReporting);
|
|
62
71
|
|
|
@@ -131,6 +140,10 @@ module.exports = function run(args, rawArgs) {
|
|
|
131
140
|
|
|
132
141
|
// add cypress dependency if missing
|
|
133
142
|
utils.setCypressNpmDependency(bsConfig);
|
|
143
|
+
|
|
144
|
+
if (isAccessibilitySession && isBrowserstackInfra) {
|
|
145
|
+
await createAccessibilityTestRun(bsConfig);
|
|
146
|
+
}
|
|
134
147
|
}
|
|
135
148
|
|
|
136
149
|
const { packagesInstalled } = !isBrowserstackInfra ? false : await packageInstaller.packageSetupAndInstaller(bsConfig, config.packageDirName, {markBlockStart, markBlockEnd});
|
|
@@ -232,6 +245,9 @@ module.exports = function run(args, rawArgs) {
|
|
|
232
245
|
markBlockEnd('zip.zipUpload');
|
|
233
246
|
markBlockEnd('zip');
|
|
234
247
|
|
|
248
|
+
if (process.env.BROWSERSTACK_TEST_ACCESSIBILITY === 'true') {
|
|
249
|
+
supportFileCleanup();
|
|
250
|
+
}
|
|
235
251
|
// Create build
|
|
236
252
|
//setup Local Testing
|
|
237
253
|
markBlockStart('localSetup');
|
|
@@ -121,6 +121,10 @@ const caps = (bsConfig, zip) => {
|
|
|
121
121
|
logger.info(`Running your tests in headless mode. Use --headed arg to run in headful mode.`);
|
|
122
122
|
}
|
|
123
123
|
|
|
124
|
+
if (process.env.BROWSERSTACK_TEST_ACCESSIBILITY === 'true') {
|
|
125
|
+
bsConfig.run_settings["accessibilityPlatforms"] = getAccessibilityPlatforms(bsConfig);
|
|
126
|
+
}
|
|
127
|
+
|
|
124
128
|
// send run_settings as is for other capabilities
|
|
125
129
|
obj.run_settings = JSON.stringify(bsConfig.run_settings);
|
|
126
130
|
}
|
|
@@ -138,9 +142,22 @@ const caps = (bsConfig, zip) => {
|
|
|
138
142
|
if (obj.parallels) logger.info(`Parallels limit specified: ${obj.parallels}`);
|
|
139
143
|
|
|
140
144
|
var data = JSON.stringify(obj);
|
|
145
|
+
|
|
141
146
|
resolve(data);
|
|
142
147
|
})
|
|
143
148
|
}
|
|
149
|
+
const getAccessibilityPlatforms = (bsConfig) => {
|
|
150
|
+
const browserList = bsConfig.browsers;
|
|
151
|
+
const accessibilityPlatforms = Array(browserList.length).fill(false);
|
|
152
|
+
let rootLevelAccessibility = false;
|
|
153
|
+
if (!Utils.isUndefined(bsConfig.run_settings.accessibility)) {
|
|
154
|
+
rootLevelAccessibility = bsConfig.run_settings.accessibility.toString() === 'true'
|
|
155
|
+
}
|
|
156
|
+
browserList.forEach((browserDetails, idx) => {
|
|
157
|
+
accessibilityPlatforms[idx] = (browserDetails.accessibility === undefined) ? rootLevelAccessibility : browserDetails.accessibility
|
|
158
|
+
});
|
|
159
|
+
return accessibilityPlatforms;
|
|
160
|
+
}
|
|
144
161
|
|
|
145
162
|
const addCypressZipStartLocation = (runSettings) => {
|
|
146
163
|
let resolvedHomeDirectoryPath = path.resolve(runSettings.home_directory);
|
|
@@ -0,0 +1,305 @@
|
|
|
1
|
+
/* Helper methods used by Accessibility and Observability */
|
|
2
|
+
|
|
3
|
+
const logger = require("../helpers/logger").winstonLogger;
|
|
4
|
+
const utils = require('../helpers/utils');
|
|
5
|
+
const fs = require('fs');
|
|
6
|
+
const path = require('path');
|
|
7
|
+
const http = require('http');
|
|
8
|
+
const https = require('https');
|
|
9
|
+
const request = require('request');
|
|
10
|
+
const gitLastCommit = require('git-last-commit');
|
|
11
|
+
const { v4: uuidv4 } = require('uuid');
|
|
12
|
+
const os = require('os');
|
|
13
|
+
const { promisify } = require('util');
|
|
14
|
+
const getRepoInfo = require('git-repo-info');
|
|
15
|
+
const gitconfig = require('gitconfiglocal');
|
|
16
|
+
const { spawn, execSync } = require('child_process');
|
|
17
|
+
const glob = require('glob');
|
|
18
|
+
const pGitconfig = promisify(gitconfig);
|
|
19
|
+
const CrashReporter = require('../testObservability/crashReporter');
|
|
20
|
+
|
|
21
|
+
exports.debug = (text, shouldReport = false, throwable = null) => {
|
|
22
|
+
if (process.env.BROWSERSTACK_OBSERVABILITY_DEBUG === "true" || process.env.BROWSERSTACK_OBSERVABILITY_DEBUG === "1") {
|
|
23
|
+
logger.info(`[ OBSERVABILITY ] ${text}`);
|
|
24
|
+
}
|
|
25
|
+
if(shouldReport) {
|
|
26
|
+
CrashReporter.getInstance().uploadCrashReport(text, throwable ? throwable && throwable.stack : null);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
exports.getFileSeparatorData = () => {
|
|
31
|
+
return /^win/.test(process.platform) ? "\\" : "/";
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
exports.findGitConfig = (filePath) => {
|
|
35
|
+
const fileSeparator = exports.getFileSeparatorData();
|
|
36
|
+
if(filePath == null || filePath == '' || filePath == fileSeparator) {
|
|
37
|
+
return null;
|
|
38
|
+
}
|
|
39
|
+
try {
|
|
40
|
+
fs.statSync(filePath + fileSeparator + '.git' + fileSeparator + 'config');
|
|
41
|
+
return filePath;
|
|
42
|
+
} catch(e) {
|
|
43
|
+
let parentFilePath = filePath.split(fileSeparator);
|
|
44
|
+
parentFilePath.pop();
|
|
45
|
+
return exports.findGitConfig(parentFilePath.join(fileSeparator));
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
let packages = {};
|
|
50
|
+
exports.getPackageVersion = (package_, bsConfig = null) => {
|
|
51
|
+
if(packages[package_]) return packages[package_];
|
|
52
|
+
let packageVersion;
|
|
53
|
+
/* Try to find version from module path */
|
|
54
|
+
try {
|
|
55
|
+
packages[package_] = this.requireModule(`${package_}/package.json`).version;
|
|
56
|
+
logger.info(`Getting ${package_} package version from module path = ${packages[package_]}`);
|
|
57
|
+
packageVersion = packages[package_];
|
|
58
|
+
} catch(e) {
|
|
59
|
+
exports.debug(`Unable to find package ${package_} at module path with error ${e}`);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/* Read package version from npm_dependencies in browserstack.json file if present */
|
|
63
|
+
if(utils.isUndefined(packageVersion) && bsConfig && (process.env.BROWSERSTACK_AUTOMATION == "true" || process.env.BROWSERSTACK_AUTOMATION == "1")) {
|
|
64
|
+
const runSettings = bsConfig.run_settings;
|
|
65
|
+
if (runSettings && runSettings.npm_dependencies !== undefined &&
|
|
66
|
+
Object.keys(runSettings.npm_dependencies).length !== 0 &&
|
|
67
|
+
typeof runSettings.npm_dependencies === 'object') {
|
|
68
|
+
if (package_ in runSettings.npm_dependencies) {
|
|
69
|
+
packages[package_] = runSettings.npm_dependencies[package_];
|
|
70
|
+
logger.info(`Getting ${package_} package version from browserstack.json = ${packages[package_]}`);
|
|
71
|
+
packageVersion = packages[package_];
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/* Read package version from project's package.json if present */
|
|
77
|
+
const packageJSONPath = path.join(process.cwd(), 'package.json');
|
|
78
|
+
if(utils.isUndefined(packageVersion) && fs.existsSync(packageJSONPath)) {
|
|
79
|
+
const packageJSONContents = require(packageJSONPath);
|
|
80
|
+
if(packageJSONContents.devDependencies && !utils.isUndefined(packageJSONContents.devDependencies[package_])) packages[package_] = packageJSONContents.devDependencies[package_];
|
|
81
|
+
if(packageJSONContents.dependencies && !utils.isUndefined(packageJSONContents.dependencies[package_])) packages[package_] = packageJSONContents.dependencies[package_];
|
|
82
|
+
logger.info(`Getting ${package_} package version from package.json = ${packages[package_]}`);
|
|
83
|
+
packageVersion = packages[package_];
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
return packageVersion;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
exports.getAgentVersion = () => {
|
|
90
|
+
let _path = path.join(__dirname, '../../package.json');
|
|
91
|
+
if(fs.existsSync(_path))
|
|
92
|
+
return require(_path).version;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
exports.getGitMetaData = () => {
|
|
96
|
+
return new Promise(async (resolve, reject) => {
|
|
97
|
+
try {
|
|
98
|
+
var info = getRepoInfo();
|
|
99
|
+
if(!info.commonGitDir) {
|
|
100
|
+
logger.debug(`Unable to find a Git directory`);
|
|
101
|
+
exports.debug(`Unable to find a Git directory`);
|
|
102
|
+
resolve({});
|
|
103
|
+
}
|
|
104
|
+
if(!info.author && exports.findGitConfig(process.cwd())) {
|
|
105
|
+
/* commit objects are packed */
|
|
106
|
+
gitLastCommit.getLastCommit(async (err, commit) => {
|
|
107
|
+
if(err) {
|
|
108
|
+
logger.debug(`Exception in populating Git Metadata with error : ${err}`, true, err);
|
|
109
|
+
exports.debug(`Exception in populating Git Metadata with error : ${err}`, true, err);
|
|
110
|
+
return resolve({});
|
|
111
|
+
}
|
|
112
|
+
try {
|
|
113
|
+
info["author"] = info["author"] || `${commit["author"]["name"].replace(/[“]+/g, '')} <${commit["author"]["email"].replace(/[“]+/g, '')}>`;
|
|
114
|
+
info["authorDate"] = info["authorDate"] || commit["authoredOn"];
|
|
115
|
+
info["committer"] = info["committer"] || `${commit["committer"]["name"].replace(/[“]+/g, '')} <${commit["committer"]["email"].replace(/[“]+/g, '')}>`;
|
|
116
|
+
info["committerDate"] = info["committerDate"] || commit["committedOn"];
|
|
117
|
+
info["commitMessage"] = info["commitMessage"] || commit["subject"];
|
|
118
|
+
|
|
119
|
+
const { remote } = await pGitconfig(info.commonGitDir);
|
|
120
|
+
const remotes = Object.keys(remote).map(remoteName => ({name: remoteName, url: remote[remoteName]['url']}));
|
|
121
|
+
resolve({
|
|
122
|
+
"name": "git",
|
|
123
|
+
"sha": info["sha"],
|
|
124
|
+
"short_sha": info["abbreviatedSha"],
|
|
125
|
+
"branch": info["branch"],
|
|
126
|
+
"tag": info["tag"],
|
|
127
|
+
"committer": info["committer"],
|
|
128
|
+
"committer_date": info["committerDate"],
|
|
129
|
+
"author": info["author"],
|
|
130
|
+
"author_date": info["authorDate"],
|
|
131
|
+
"commit_message": info["commitMessage"],
|
|
132
|
+
"root": info["root"],
|
|
133
|
+
"common_git_dir": info["commonGitDir"],
|
|
134
|
+
"worktree_git_dir": info["worktreeGitDir"],
|
|
135
|
+
"last_tag": info["lastTag"],
|
|
136
|
+
"commits_since_last_tag": info["commitsSinceLastTag"],
|
|
137
|
+
"remotes": remotes
|
|
138
|
+
});
|
|
139
|
+
} catch(e) {
|
|
140
|
+
exports.debug(`Exception in populating Git Metadata with error : ${e}`, true, e);
|
|
141
|
+
logger.debug(`Exception in populating Git Metadata with error : ${e}`, true, e);
|
|
142
|
+
return resolve({});
|
|
143
|
+
}
|
|
144
|
+
}, {dst: exports.findGitConfig(process.cwd())});
|
|
145
|
+
} else {
|
|
146
|
+
const { remote } = await pGitconfig(info.commonGitDir);
|
|
147
|
+
const remotes = Object.keys(remote).map(remoteName => ({name: remoteName, url: remote[remoteName]['url']}));
|
|
148
|
+
resolve({
|
|
149
|
+
"name": "git",
|
|
150
|
+
"sha": info["sha"],
|
|
151
|
+
"short_sha": info["abbreviatedSha"],
|
|
152
|
+
"branch": info["branch"],
|
|
153
|
+
"tag": info["tag"],
|
|
154
|
+
"committer": info["committer"],
|
|
155
|
+
"committer_date": info["committerDate"],
|
|
156
|
+
"author": info["author"],
|
|
157
|
+
"author_date": info["authorDate"],
|
|
158
|
+
"commit_message": info["commitMessage"],
|
|
159
|
+
"root": info["root"],
|
|
160
|
+
"common_git_dir": info["commonGitDir"],
|
|
161
|
+
"worktree_git_dir": info["worktreeGitDir"],
|
|
162
|
+
"last_tag": info["lastTag"],
|
|
163
|
+
"commits_since_last_tag": info["commitsSinceLastTag"],
|
|
164
|
+
"remotes": remotes
|
|
165
|
+
});
|
|
166
|
+
}
|
|
167
|
+
} catch(err) {
|
|
168
|
+
exports.debug(`Exception in populating Git metadata with error : ${err}`, true, err);
|
|
169
|
+
logger.debug(`Exception in populating Git metadata with error : ${err}`, true, err);
|
|
170
|
+
resolve({});
|
|
171
|
+
}
|
|
172
|
+
})
|
|
173
|
+
}
|
|
174
|
+
exports.getCiInfo = () => {
|
|
175
|
+
var env = process.env;
|
|
176
|
+
// Jenkins
|
|
177
|
+
if ((typeof env.JENKINS_URL === "string" && env.JENKINS_URL.length > 0) || (typeof env.JENKINS_HOME === "string" && env.JENKINS_HOME.length > 0)) {
|
|
178
|
+
return {
|
|
179
|
+
name: "Jenkins",
|
|
180
|
+
build_url: env.BUILD_URL,
|
|
181
|
+
job_name: env.JOB_NAME,
|
|
182
|
+
build_number: env.BUILD_NUMBER
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
// CircleCI
|
|
186
|
+
if (env.CI === "true" && env.CIRCLECI === "true") {
|
|
187
|
+
return {
|
|
188
|
+
name: "CircleCI",
|
|
189
|
+
build_url: env.CIRCLE_BUILD_URL,
|
|
190
|
+
job_name: env.CIRCLE_JOB,
|
|
191
|
+
build_number: env.CIRCLE_BUILD_NUM
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
// Travis CI
|
|
195
|
+
if (env.CI === "true" && env.TRAVIS === "true") {
|
|
196
|
+
return {
|
|
197
|
+
name: "Travis CI",
|
|
198
|
+
build_url: env.TRAVIS_BUILD_WEB_URL,
|
|
199
|
+
job_name: env.TRAVIS_JOB_NAME,
|
|
200
|
+
build_number: env.TRAVIS_BUILD_NUMBER
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
// Codeship
|
|
204
|
+
if (env.CI === "true" && env.CI_NAME === "codeship") {
|
|
205
|
+
return {
|
|
206
|
+
name: "Codeship",
|
|
207
|
+
build_url: null,
|
|
208
|
+
job_name: null,
|
|
209
|
+
build_number: null
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
// Bitbucket
|
|
213
|
+
if (env.BITBUCKET_BRANCH && env.BITBUCKET_COMMIT) {
|
|
214
|
+
return {
|
|
215
|
+
name: "Bitbucket",
|
|
216
|
+
build_url: env.BITBUCKET_GIT_HTTP_ORIGIN,
|
|
217
|
+
job_name: null,
|
|
218
|
+
build_number: env.BITBUCKET_BUILD_NUMBER
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
// Drone
|
|
222
|
+
if (env.CI === "true" && env.DRONE === "true") {
|
|
223
|
+
return {
|
|
224
|
+
name: "Drone",
|
|
225
|
+
build_url: env.DRONE_BUILD_LINK,
|
|
226
|
+
job_name: null,
|
|
227
|
+
build_number: env.DRONE_BUILD_NUMBER
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
// Semaphore
|
|
231
|
+
if (env.CI === "true" && env.SEMAPHORE === "true") {
|
|
232
|
+
return {
|
|
233
|
+
name: "Semaphore",
|
|
234
|
+
build_url: env.SEMAPHORE_ORGANIZATION_URL,
|
|
235
|
+
job_name: env.SEMAPHORE_JOB_NAME,
|
|
236
|
+
build_number: env.SEMAPHORE_JOB_ID
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
// GitLab
|
|
240
|
+
if (env.CI === "true" && env.GITLAB_CI === "true") {
|
|
241
|
+
return {
|
|
242
|
+
name: "GitLab",
|
|
243
|
+
build_url: env.CI_JOB_URL,
|
|
244
|
+
job_name: env.CI_JOB_NAME,
|
|
245
|
+
build_number: env.CI_JOB_ID
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
// Buildkite
|
|
249
|
+
if (env.CI === "true" && env.BUILDKITE === "true") {
|
|
250
|
+
return {
|
|
251
|
+
name: "Buildkite",
|
|
252
|
+
build_url: env.BUILDKITE_BUILD_URL,
|
|
253
|
+
job_name: env.BUILDKITE_LABEL || env.BUILDKITE_PIPELINE_NAME,
|
|
254
|
+
build_number: env.BUILDKITE_BUILD_NUMBER
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
// Visual Studio Team Services
|
|
258
|
+
if (env.TF_BUILD === "True") {
|
|
259
|
+
return {
|
|
260
|
+
name: "Visual Studio Team Services",
|
|
261
|
+
build_url: `${env.SYSTEM_TEAMFOUNDATIONSERVERURI}${env.SYSTEM_TEAMPROJECTID}`,
|
|
262
|
+
job_name: env.SYSTEM_DEFINITIONID,
|
|
263
|
+
build_number: env.BUILD_BUILDID
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
// if no matches, return null
|
|
267
|
+
return null;
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
exports.getBuildDetails = (bsConfig) => {
|
|
271
|
+
let buildName = '',
|
|
272
|
+
projectName = '',
|
|
273
|
+
buildDescription = '',
|
|
274
|
+
buildTags = [];
|
|
275
|
+
|
|
276
|
+
/* Pick from environment variables */
|
|
277
|
+
buildName = process.env.BROWSERSTACK_BUILD_NAME || buildName;
|
|
278
|
+
projectName = process.env.BROWSERSTACK_PROJECT_NAME || projectName;
|
|
279
|
+
|
|
280
|
+
/* Pick from run settings */
|
|
281
|
+
buildName = buildName || bsConfig["run_settings"]["build_name"];
|
|
282
|
+
projectName = projectName || bsConfig["run_settings"]["project_name"];
|
|
283
|
+
if(!utils.isUndefined(bsConfig["run_settings"]["build_tag"])) buildTags = [...buildTags, bsConfig["run_settings"]["build_tag"]];
|
|
284
|
+
|
|
285
|
+
buildName = buildName || path.basename(path.resolve(process.cwd()));
|
|
286
|
+
|
|
287
|
+
return {
|
|
288
|
+
buildName,
|
|
289
|
+
projectName,
|
|
290
|
+
buildDescription,
|
|
291
|
+
buildTags
|
|
292
|
+
};
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
exports.setBrowserstackCypressCliDependency = (bsConfig) => {
|
|
296
|
+
const runSettings = bsConfig.run_settings;
|
|
297
|
+
if (runSettings.npm_dependencies !== undefined &&
|
|
298
|
+
typeof runSettings.npm_dependencies === 'object') {
|
|
299
|
+
if (!("browserstack-cypress-cli" in runSettings.npm_dependencies)) {
|
|
300
|
+
logger.warn("Missing browserstack-cypress-cli not found in npm_dependencies");
|
|
301
|
+
runSettings.npm_dependencies['browserstack-cypress-cli'] = this.getAgentVersion() || "latest";
|
|
302
|
+
logger.warn(`Adding browserstack-cypress-cli version ${runSettings.npm_dependencies['browserstack-cypress-cli']} in npm_dependencies`);
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
}
|
package/bin/helpers/utils.js
CHANGED
|
@@ -558,6 +558,23 @@ exports.setSystemEnvs = (bsConfig) => {
|
|
|
558
558
|
});
|
|
559
559
|
}
|
|
560
560
|
|
|
561
|
+
try {
|
|
562
|
+
const accessibilityOptions = bsConfig.run_settings.accessibilityOptions;
|
|
563
|
+
if (accessibilityOptions) {
|
|
564
|
+
Object.keys(accessibilityOptions).forEach(key => {
|
|
565
|
+
const a11y_env_key = `ACCESSIBILITY_${key.toUpperCase()}`
|
|
566
|
+
if (["includeTagsInTestingScope", "excludeTagsInTestingScope"].includes(key))
|
|
567
|
+
envKeys[a11y_env_key] = accessibilityOptions[key].join(";")
|
|
568
|
+
else if (key === "includeIssueType")
|
|
569
|
+
envKeys[a11y_env_key] = JSON.stringify(accessibilityOptions.includeIssueType).replaceAll('"', "")
|
|
570
|
+
else
|
|
571
|
+
envKeys[a11y_env_key] = accessibilityOptions[key];
|
|
572
|
+
})
|
|
573
|
+
}
|
|
574
|
+
} catch (error) {
|
|
575
|
+
logger.error(`Error in adding accessibility configs ${error}`)
|
|
576
|
+
}
|
|
577
|
+
|
|
561
578
|
try {
|
|
562
579
|
OBSERVABILITY_ENV_VARS.forEach(key => {
|
|
563
580
|
envKeys[key] = process.env[key];
|
|
@@ -3,11 +3,9 @@ const path = require('path');
|
|
|
3
3
|
const http = require('http');
|
|
4
4
|
const https = require('https');
|
|
5
5
|
const request = require('request');
|
|
6
|
-
var gitLastCommit = require('git-last-commit');
|
|
7
6
|
const { v4: uuidv4 } = require('uuid');
|
|
8
7
|
const os = require('os');
|
|
9
8
|
const { promisify } = require('util');
|
|
10
|
-
const getRepoInfo = require('git-repo-info');
|
|
11
9
|
const gitconfig = require('gitconfiglocal');
|
|
12
10
|
const { spawn, execSync } = require('child_process');
|
|
13
11
|
const glob = require('glob');
|
|
@@ -16,6 +14,8 @@ const pGitconfig = promisify(gitconfig);
|
|
|
16
14
|
|
|
17
15
|
const logger = require("../../helpers/logger").winstonLogger;
|
|
18
16
|
const utils = require('../../helpers/utils');
|
|
17
|
+
const helper = require('../../helpers/helper');
|
|
18
|
+
|
|
19
19
|
const CrashReporter = require('../crashReporter');
|
|
20
20
|
|
|
21
21
|
// Getting global packages path
|
|
@@ -181,169 +181,6 @@ exports.findGitConfig = (filePath) => {
|
|
|
181
181
|
}
|
|
182
182
|
}
|
|
183
183
|
|
|
184
|
-
const getGitMetaData = () => {
|
|
185
|
-
return new Promise(async (resolve, reject) => {
|
|
186
|
-
try {
|
|
187
|
-
var info = getRepoInfo();
|
|
188
|
-
if(!info.commonGitDir) {
|
|
189
|
-
exports.debug(`Unable to find a Git directory`);
|
|
190
|
-
resolve({});
|
|
191
|
-
}
|
|
192
|
-
if(!info.author && exports.findGitConfig(process.cwd())) {
|
|
193
|
-
/* commit objects are packed */
|
|
194
|
-
gitLastCommit.getLastCommit(async (err, commit) => {
|
|
195
|
-
info["author"] = info["author"] || `${commit["author"]["name"].replace(/[“]+/g, '')} <${commit["author"]["email"].replace(/[“]+/g, '')}>`;
|
|
196
|
-
info["authorDate"] = info["authorDate"] || commit["authoredOn"];
|
|
197
|
-
info["committer"] = info["committer"] || `${commit["committer"]["name"].replace(/[“]+/g, '')} <${commit["committer"]["email"].replace(/[“]+/g, '')}>`;
|
|
198
|
-
info["committerDate"] = info["committerDate"] || commit["committedOn"]
|
|
199
|
-
info["commitMessage"] = info["commitMessage"] || commit["subject"];
|
|
200
|
-
|
|
201
|
-
const { remote } = await pGitconfig(info.commonGitDir);
|
|
202
|
-
const remotes = Object.keys(remote).map(remoteName => ({name: remoteName, url: remote[remoteName]['url']}));
|
|
203
|
-
resolve({
|
|
204
|
-
"name": "git",
|
|
205
|
-
"sha": info["sha"],
|
|
206
|
-
"short_sha": info["abbreviatedSha"],
|
|
207
|
-
"branch": info["branch"],
|
|
208
|
-
"tag": info["tag"],
|
|
209
|
-
"committer": info["committer"],
|
|
210
|
-
"committer_date": info["committerDate"],
|
|
211
|
-
"author": info["author"],
|
|
212
|
-
"author_date": info["authorDate"],
|
|
213
|
-
"commit_message": info["commitMessage"],
|
|
214
|
-
"root": info["root"],
|
|
215
|
-
"common_git_dir": info["commonGitDir"],
|
|
216
|
-
"worktree_git_dir": info["worktreeGitDir"],
|
|
217
|
-
"last_tag": info["lastTag"],
|
|
218
|
-
"commits_since_last_tag": info["commitsSinceLastTag"],
|
|
219
|
-
"remotes": remotes
|
|
220
|
-
});
|
|
221
|
-
}, {dst: exports.findGitConfig(process.cwd())});
|
|
222
|
-
} else {
|
|
223
|
-
const { remote } = await pGitconfig(info.commonGitDir);
|
|
224
|
-
const remotes = Object.keys(remote).map(remoteName => ({name: remoteName, url: remote[remoteName]['url']}));
|
|
225
|
-
resolve({
|
|
226
|
-
"name": "git",
|
|
227
|
-
"sha": info["sha"],
|
|
228
|
-
"short_sha": info["abbreviatedSha"],
|
|
229
|
-
"branch": info["branch"],
|
|
230
|
-
"tag": info["tag"],
|
|
231
|
-
"committer": info["committer"],
|
|
232
|
-
"committer_date": info["committerDate"],
|
|
233
|
-
"author": info["author"],
|
|
234
|
-
"author_date": info["authorDate"],
|
|
235
|
-
"commit_message": info["commitMessage"],
|
|
236
|
-
"root": info["root"],
|
|
237
|
-
"common_git_dir": info["commonGitDir"],
|
|
238
|
-
"worktree_git_dir": info["worktreeGitDir"],
|
|
239
|
-
"last_tag": info["lastTag"],
|
|
240
|
-
"commits_since_last_tag": info["commitsSinceLastTag"],
|
|
241
|
-
"remotes": remotes
|
|
242
|
-
});
|
|
243
|
-
}
|
|
244
|
-
} catch(err) {
|
|
245
|
-
exports.debug(`Exception in populating Git metadata with error : ${err}`, true, err);
|
|
246
|
-
resolve({});
|
|
247
|
-
}
|
|
248
|
-
})
|
|
249
|
-
}
|
|
250
|
-
|
|
251
|
-
const getCiInfo = () => {
|
|
252
|
-
var env = process.env;
|
|
253
|
-
// Jenkins
|
|
254
|
-
if ((typeof env.JENKINS_URL === "string" && env.JENKINS_URL.length > 0) || (typeof env.JENKINS_HOME === "string" && env.JENKINS_HOME.length > 0)) {
|
|
255
|
-
return {
|
|
256
|
-
name: "Jenkins",
|
|
257
|
-
build_url: env.BUILD_URL,
|
|
258
|
-
job_name: env.JOB_NAME,
|
|
259
|
-
build_number: env.BUILD_NUMBER
|
|
260
|
-
}
|
|
261
|
-
}
|
|
262
|
-
// CircleCI
|
|
263
|
-
if (env.CI === "true" && env.CIRCLECI === "true") {
|
|
264
|
-
return {
|
|
265
|
-
name: "CircleCI",
|
|
266
|
-
build_url: env.CIRCLE_BUILD_URL,
|
|
267
|
-
job_name: env.CIRCLE_JOB,
|
|
268
|
-
build_number: env.CIRCLE_BUILD_NUM
|
|
269
|
-
}
|
|
270
|
-
}
|
|
271
|
-
// Travis CI
|
|
272
|
-
if (env.CI === "true" && env.TRAVIS === "true") {
|
|
273
|
-
return {
|
|
274
|
-
name: "Travis CI",
|
|
275
|
-
build_url: env.TRAVIS_BUILD_WEB_URL,
|
|
276
|
-
job_name: env.TRAVIS_JOB_NAME,
|
|
277
|
-
build_number: env.TRAVIS_BUILD_NUMBER
|
|
278
|
-
}
|
|
279
|
-
}
|
|
280
|
-
// Codeship
|
|
281
|
-
if (env.CI === "true" && env.CI_NAME === "codeship") {
|
|
282
|
-
return {
|
|
283
|
-
name: "Codeship",
|
|
284
|
-
build_url: null,
|
|
285
|
-
job_name: null,
|
|
286
|
-
build_number: null
|
|
287
|
-
}
|
|
288
|
-
}
|
|
289
|
-
// Bitbucket
|
|
290
|
-
if (env.BITBUCKET_BRANCH && env.BITBUCKET_COMMIT) {
|
|
291
|
-
return {
|
|
292
|
-
name: "Bitbucket",
|
|
293
|
-
build_url: env.BITBUCKET_GIT_HTTP_ORIGIN,
|
|
294
|
-
job_name: null,
|
|
295
|
-
build_number: env.BITBUCKET_BUILD_NUMBER
|
|
296
|
-
}
|
|
297
|
-
}
|
|
298
|
-
// Drone
|
|
299
|
-
if (env.CI === "true" && env.DRONE === "true") {
|
|
300
|
-
return {
|
|
301
|
-
name: "Drone",
|
|
302
|
-
build_url: env.DRONE_BUILD_LINK,
|
|
303
|
-
job_name: null,
|
|
304
|
-
build_number: env.DRONE_BUILD_NUMBER
|
|
305
|
-
}
|
|
306
|
-
}
|
|
307
|
-
// Semaphore
|
|
308
|
-
if (env.CI === "true" && env.SEMAPHORE === "true") {
|
|
309
|
-
return {
|
|
310
|
-
name: "Semaphore",
|
|
311
|
-
build_url: env.SEMAPHORE_ORGANIZATION_URL,
|
|
312
|
-
job_name: env.SEMAPHORE_JOB_NAME,
|
|
313
|
-
build_number: env.SEMAPHORE_JOB_ID
|
|
314
|
-
}
|
|
315
|
-
}
|
|
316
|
-
// GitLab
|
|
317
|
-
if (env.CI === "true" && env.GITLAB_CI === "true") {
|
|
318
|
-
return {
|
|
319
|
-
name: "GitLab",
|
|
320
|
-
build_url: env.CI_JOB_URL,
|
|
321
|
-
job_name: env.CI_JOB_NAME,
|
|
322
|
-
build_number: env.CI_JOB_ID
|
|
323
|
-
}
|
|
324
|
-
}
|
|
325
|
-
// Buildkite
|
|
326
|
-
if (env.CI === "true" && env.BUILDKITE === "true") {
|
|
327
|
-
return {
|
|
328
|
-
name: "Buildkite",
|
|
329
|
-
build_url: env.BUILDKITE_BUILD_URL,
|
|
330
|
-
job_name: env.BUILDKITE_LABEL || env.BUILDKITE_PIPELINE_NAME,
|
|
331
|
-
build_number: env.BUILDKITE_BUILD_NUMBER
|
|
332
|
-
}
|
|
333
|
-
}
|
|
334
|
-
// Visual Studio Team Services
|
|
335
|
-
if (env.TF_BUILD === "True") {
|
|
336
|
-
return {
|
|
337
|
-
name: "Visual Studio Team Services",
|
|
338
|
-
build_url: `${env.SYSTEM_TEAMFOUNDATIONSERVERURI}${env.SYSTEM_TEAMPROJECTID}`,
|
|
339
|
-
job_name: env.SYSTEM_DEFINITIONID,
|
|
340
|
-
build_number: env.BUILD_BUILDID
|
|
341
|
-
}
|
|
342
|
-
}
|
|
343
|
-
// if no matches, return null
|
|
344
|
-
return null;
|
|
345
|
-
}
|
|
346
|
-
|
|
347
184
|
let packages = {};
|
|
348
185
|
|
|
349
186
|
exports.getPackageVersion = (package_, bsConfig = null) => {
|
|
@@ -385,12 +222,6 @@ exports.getPackageVersion = (package_, bsConfig = null) => {
|
|
|
385
222
|
return packageVersion;
|
|
386
223
|
}
|
|
387
224
|
|
|
388
|
-
exports.getAgentVersion = () => {
|
|
389
|
-
let _path = path.join(__dirname, '../../../package.json');
|
|
390
|
-
if(fs.existsSync(_path))
|
|
391
|
-
return require(_path).version;
|
|
392
|
-
}
|
|
393
|
-
|
|
394
225
|
const setEnvironmentVariablesForRemoteReporter = (BS_TESTOPS_JWT, BS_TESTOPS_BUILD_HASHED_ID, BS_TESTOPS_ALLOW_SCREENSHOTS, OBSERVABILITY_LAUNCH_SDK_VERSION) => {
|
|
395
226
|
process.env.BS_TESTOPS_JWT = BS_TESTOPS_JWT;
|
|
396
227
|
process.env.BS_TESTOPS_BUILD_HASHED_ID = BS_TESTOPS_BUILD_HASHED_ID;
|
|
@@ -433,53 +264,6 @@ const setEventListeners = () => {
|
|
|
433
264
|
}
|
|
434
265
|
}
|
|
435
266
|
|
|
436
|
-
const getBuildDetails = (bsConfig) => {
|
|
437
|
-
const isTestObservabilityOptionsPresent = !utils.isUndefined(bsConfig["testObservabilityOptions"]);
|
|
438
|
-
let buildName = '',
|
|
439
|
-
projectName = '',
|
|
440
|
-
buildDescription = '',
|
|
441
|
-
buildTags = [];
|
|
442
|
-
|
|
443
|
-
/* Pick from environment variables */
|
|
444
|
-
buildName = process.env.BROWSERSTACK_BUILD_NAME || buildName;
|
|
445
|
-
projectName = process.env.BROWSERSTACK_PROJECT_NAME || projectName;
|
|
446
|
-
|
|
447
|
-
/* Pick from testObservabilityOptions */
|
|
448
|
-
if(isTestObservabilityOptionsPresent) {
|
|
449
|
-
buildName = buildName || bsConfig["testObservabilityOptions"]["buildName"];
|
|
450
|
-
projectName = projectName || bsConfig["testObservabilityOptions"]["projectName"];
|
|
451
|
-
if(!utils.isUndefined(bsConfig["testObservabilityOptions"]["buildTag"])) buildTags = [...buildTags, ...bsConfig["testObservabilityOptions"]["buildTag"]];
|
|
452
|
-
buildDescription = buildDescription || bsConfig["testObservabilityOptions"]["buildDescription"];
|
|
453
|
-
}
|
|
454
|
-
|
|
455
|
-
/* Pick from run settings */
|
|
456
|
-
buildName = buildName || bsConfig["run_settings"]["build_name"];
|
|
457
|
-
projectName = projectName || bsConfig["run_settings"]["project_name"];
|
|
458
|
-
if(!utils.isUndefined(bsConfig["run_settings"]["build_tag"])) buildTags = [...buildTags, bsConfig["run_settings"]["build_tag"]];
|
|
459
|
-
|
|
460
|
-
buildName = buildName || path.basename(path.resolve(process.cwd()));
|
|
461
|
-
|
|
462
|
-
return {
|
|
463
|
-
buildName,
|
|
464
|
-
projectName,
|
|
465
|
-
buildDescription,
|
|
466
|
-
buildTags
|
|
467
|
-
};
|
|
468
|
-
}
|
|
469
|
-
|
|
470
|
-
const setBrowserstackCypressCliDependency = (bsConfig) => {
|
|
471
|
-
const runSettings = bsConfig.run_settings;
|
|
472
|
-
if (runSettings.npm_dependencies !== undefined &&
|
|
473
|
-
Object.keys(runSettings.npm_dependencies).length !== 0 &&
|
|
474
|
-
typeof runSettings.npm_dependencies === 'object') {
|
|
475
|
-
if (!("browserstack-cypress-cli" in runSettings.npm_dependencies)) {
|
|
476
|
-
logger.warn("Missing browserstack-cypress-cli not found in npm_dependencies");
|
|
477
|
-
runSettings.npm_dependencies['browserstack-cypress-cli'] = exports.getAgentVersion() || "latest";
|
|
478
|
-
logger.warn(`Adding browserstack-cypress-cli version ${runSettings.npm_dependencies['browserstack-cypress-cli']} in npm_dependencies`);
|
|
479
|
-
}
|
|
480
|
-
}
|
|
481
|
-
}
|
|
482
|
-
|
|
483
267
|
const getCypressConfigFileContent = (bsConfig, cypressConfigPath) => {
|
|
484
268
|
try {
|
|
485
269
|
const cypressConfigFile = require(path.resolve(bsConfig ? bsConfig.run_settings.cypress_config_file : cypressConfigPath));
|
|
@@ -543,7 +327,7 @@ exports.launchTestSession = async (user_config, bsConfigPath) => {
|
|
|
543
327
|
projectName,
|
|
544
328
|
buildDescription,
|
|
545
329
|
buildTags
|
|
546
|
-
} = getBuildDetails(user_config);
|
|
330
|
+
} = helper.getBuildDetails(user_config);
|
|
547
331
|
const data = {
|
|
548
332
|
'format': 'json',
|
|
549
333
|
'project_name': projectName,
|
|
@@ -558,14 +342,14 @@ exports.launchTestSession = async (user_config, bsConfigPath) => {
|
|
|
558
342
|
version: os.version(),
|
|
559
343
|
arch: os.arch()
|
|
560
344
|
},
|
|
561
|
-
'ci_info': getCiInfo(),
|
|
345
|
+
'ci_info': helper.getCiInfo(),
|
|
562
346
|
'build_run_identifier': process.env.BROWSERSTACK_BUILD_RUN_IDENTIFIER,
|
|
563
347
|
'failed_tests_rerun': process.env.BROWSERSTACK_RERUN || false,
|
|
564
|
-
'version_control': await getGitMetaData(),
|
|
348
|
+
'version_control': await helper.getGitMetaData(),
|
|
565
349
|
'observability_version': {
|
|
566
350
|
frameworkName: "Cypress",
|
|
567
351
|
frameworkVersion: exports.getPackageVersion('cypress', user_config),
|
|
568
|
-
sdkVersion:
|
|
352
|
+
sdkVersion: helper.getAgentVersion()
|
|
569
353
|
}
|
|
570
354
|
};
|
|
571
355
|
const config = {
|
|
@@ -583,8 +367,8 @@ exports.launchTestSession = async (user_config, bsConfigPath) => {
|
|
|
583
367
|
exports.debug('Build creation successfull!');
|
|
584
368
|
process.env.BS_TESTOPS_BUILD_COMPLETED = true;
|
|
585
369
|
setEnvironmentVariablesForRemoteReporter(response.data.jwt, response.data.build_hashed_id, response.data.allow_screenshots, data.observability_version.sdkVersion);
|
|
586
|
-
setEventListeners();
|
|
587
|
-
if(this.isBrowserstackInfra()) setBrowserstackCypressCliDependency(user_config);
|
|
370
|
+
// setEventListeners();
|
|
371
|
+
if(this.isBrowserstackInfra()) helper.setBrowserstackCypressCliDependency(user_config);
|
|
588
372
|
} catch(error) {
|
|
589
373
|
if(!error.errorType) {
|
|
590
374
|
if (error.response) {
|
package/package.json
CHANGED
package/log/usage.log
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"level":"info","message":"Sending {\"event_type\":\"cypress_cli_stats\",\"data\":{\"bstack_json\":\"null\",\"run_settings\":\"\",\"os\":\"darwin\",\"os_version\":\"21.6.0\",\"bstack_json_found_in_pwd\":false,\"cypress_config_file_found_in_pwd\":null,\"cli_version\":\"1.24.4\",\"cli_path\":\"/Users/archish/.nvm/versions/node/v16.16.0/lib/node_modules\",\"npm_version\":\"8.11.0\",\"local_cypress_version\":null,\"ci_environment\":null,\"event_timestamp\":\"7/27/2023, 4:39:59 PM\",\"data\":null,\"raw_args\":\"[\\\"run\\\",\\\"--async\\\"]\",\"cli_args\":\"{\\\"_\\\":[\\\"run\\\"],\\\"async\\\":true,\\\"cf\\\":\\\"browserstack.json\\\",\\\"config-file\\\":\\\"browserstack.json\\\",\\\"configFile\\\":\\\"browserstack.json\\\",\\\"cli-debug\\\":false,\\\"cliDebug\\\":false,\\\"ccf\\\":\\\"./cypress.json\\\",\\\"cypress-config-file\\\":\\\"./cypress.json\\\",\\\"cypressConfigFile\\\":\\\"./cypress.json\\\",\\\"disable-npm-warning\\\":false,\\\"disableNpmWarning\\\":false,\\\"sync\\\":true,\\\"force-upload\\\":false,\\\"forceUpload\\\":false,\\\"headed\\\":false,\\\"no-wrap\\\":false,\\\"noWrap\\\":false,\\\"$0\\\":\\\"browserstack-cypress\\\"}\",\"message_type\":\"error\",\"error_code\":\"bstack_json_invalid_unknown\"}} to https://eds.browserstack.com:443/send_event_cy_internal","timestamp":"2023-07-27T11:09:59.626Z"}
|