browserstack-cypress-cli 1.32.7 → 1.33.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/cypress/index.js +1 -1
- package/bin/accessibility-automation/helper.js +59 -31
- package/bin/commands/runs.js +7 -3
- package/bin/helpers/atsHelper.js +1 -0
- package/bin/helpers/helper.js +2 -1
- package/bin/helpers/utils.js +32 -3
- package/bin/testObservability/crashReporter/index.js +2 -2
- package/bin/testObservability/cypress/index.js +194 -96
- package/bin/testObservability/helper/cleanupQueueSync.js +1 -2
- package/bin/testObservability/helper/constants.js +4 -0
- package/bin/testObservability/helper/helper.js +20 -21
- package/bin/testObservability/helper/requestQueueHandler.js +1 -1
- package/bin/testObservability/plugin/index.js +6 -0
- package/bin/testObservability/plugin/ipcServer.js +1 -1
- package/bin/testObservability/reporter/index.js +26 -18
- package/package.json +1 -1
- package/log/usage.log +0 -4
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
const browserStackLog = (message) => {
|
|
4
4
|
if (!Cypress.env('BROWSERSTACK_LOGS')) return;
|
|
5
5
|
cy.task('browserstack_log', message);
|
|
6
|
-
|
|
6
|
+
}
|
|
7
7
|
|
|
8
8
|
const commandsToWrap = ['visit', 'click', 'type', 'request', 'dblclick', 'rightclick', 'clear', 'check', 'uncheck', 'select', 'trigger', 'selectFile', 'scrollIntoView', 'scroll', 'scrollTo', 'blur', 'focus', 'go', 'reload', 'submit', 'viewport', 'origin'];
|
|
9
9
|
// scroll is not a default function in cypress.
|
|
@@ -21,7 +21,7 @@ exports.checkAccessibilityPlatform = (user_config) => {
|
|
|
21
21
|
}
|
|
22
22
|
})
|
|
23
23
|
} catch {}
|
|
24
|
-
|
|
24
|
+
|
|
25
25
|
return accessibility;
|
|
26
26
|
}
|
|
27
27
|
|
|
@@ -113,35 +113,33 @@ exports.createAccessibilityTestRun = async (user_config, framework) => {
|
|
|
113
113
|
|
|
114
114
|
} catch (error) {
|
|
115
115
|
if (error.response) {
|
|
116
|
-
logger.error("Incorrect Cred")
|
|
116
|
+
logger.error("Incorrect Cred");
|
|
117
117
|
logger.error(
|
|
118
118
|
`Exception while creating test run for BrowserStack Accessibility Automation: ${
|
|
119
119
|
error.response.status
|
|
120
|
-
} ${error.response.statusText} ${JSON.stringify(error.response.data)}
|
|
120
|
+
} ${error.response.statusText} ${JSON.stringify(error.response.data)}
|
|
121
|
+
`
|
|
121
122
|
);
|
|
122
|
-
} else {
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
logger.error(errorkey.message);
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
} else {
|
|
135
|
-
logger.error(
|
|
136
|
-
`Exception while creating test run for BrowserStack Accessibility Automation: ${
|
|
137
|
-
error.message || error.stack
|
|
138
|
-
}`
|
|
139
|
-
);
|
|
123
|
+
} else if (error.message === 'Invalid configuration passed.') {
|
|
124
|
+
logger.error("Invalid configuration passed.");
|
|
125
|
+
logger.error(
|
|
126
|
+
`Exception while creating test run for BrowserStack Accessibility Automation: ${
|
|
127
|
+
error.message || error.stack
|
|
128
|
+
}`
|
|
129
|
+
);
|
|
130
|
+
for (const errorkey of error.errors) {
|
|
131
|
+
logger.error(errorkey.message);
|
|
140
132
|
}
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
133
|
+
} else {
|
|
134
|
+
logger.error(
|
|
135
|
+
`Exception while creating test run for BrowserStack Accessibility Automation: ${
|
|
136
|
+
error.message || error.stack
|
|
137
|
+
}`
|
|
138
|
+
);
|
|
144
139
|
}
|
|
140
|
+
// since create accessibility session failed
|
|
141
|
+
process.env.BROWSERSTACK_TEST_ACCESSIBILITY = 'false';
|
|
142
|
+
user_config.run_settings.accessibility = false;
|
|
145
143
|
}
|
|
146
144
|
}
|
|
147
145
|
|
|
@@ -216,22 +214,52 @@ const getAccessibilityCypressCommandEventListener = (extName) => {
|
|
|
216
214
|
|
|
217
215
|
exports.setAccessibilityEventListeners = (bsConfig) => {
|
|
218
216
|
try {
|
|
219
|
-
|
|
217
|
+
|
|
220
218
|
const supportFilesData = helper.getSupportFiles(bsConfig, true);
|
|
221
219
|
if(!supportFilesData.supportFile) return;
|
|
222
|
-
|
|
223
|
-
|
|
220
|
+
|
|
221
|
+
const isPattern = glob.hasMagic(supportFilesData.supportFile);
|
|
222
|
+
if(!isPattern) {
|
|
223
|
+
logger.debug(`Using user defined support file: ${supportFilesData.supportFile}`);
|
|
224
|
+
let file;
|
|
225
|
+
try {
|
|
226
|
+
file = process.cwd() + supportFilesData.supportFile;
|
|
227
|
+
const defaultFileContent = fs.readFileSync(file, {encoding: 'utf-8'});
|
|
228
|
+
let cypressCommandEventListener = getAccessibilityCypressCommandEventListener(path.extname(file));
|
|
229
|
+
const alreadyIncludes = defaultFileContent.includes(cypressCommandEventListener);
|
|
230
|
+
if(!alreadyIncludes) {
|
|
231
|
+
let newFileContent = defaultFileContent +
|
|
232
|
+
'\n' +
|
|
233
|
+
cypressCommandEventListener +
|
|
234
|
+
'\n';
|
|
235
|
+
fs.writeFileSync(file, newFileContent, {encoding: 'utf-8'});
|
|
236
|
+
supportFileContentMap[file] = supportFilesData.cleanupParams ? supportFilesData.cleanupParams : defaultFileContent;
|
|
237
|
+
}
|
|
238
|
+
} catch(e) {
|
|
239
|
+
logger.debug(`Unable to modify file contents for ${file} to set event listeners with error ${e}`, true, e);
|
|
240
|
+
}
|
|
241
|
+
return;
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
const globPattern = process.cwd() + supportFilesData.supportFile;
|
|
245
|
+
glob(globPattern, {}, (err, files) => {
|
|
246
|
+
if(err) {
|
|
247
|
+
logger.debug('EXCEPTION IN BUILD START EVENT : Unable to parse cypress support files');
|
|
248
|
+
return;
|
|
249
|
+
}
|
|
250
|
+
|
|
224
251
|
files.forEach(file => {
|
|
225
252
|
try {
|
|
226
|
-
|
|
253
|
+
const fileName = path.basename(file);
|
|
254
|
+
if(['e2e.js', 'e2e.ts', 'component.ts', 'component.js'].includes(fileName) && !file.includes('node_modules')) {
|
|
255
|
+
|
|
227
256
|
const defaultFileContent = fs.readFileSync(file, {encoding: 'utf-8'});
|
|
228
|
-
|
|
229
257
|
let cypressCommandEventListener = getAccessibilityCypressCommandEventListener(path.extname(file));
|
|
230
258
|
if(!defaultFileContent.includes(cypressCommandEventListener)) {
|
|
231
|
-
let newFileContent =
|
|
259
|
+
let newFileContent = defaultFileContent +
|
|
232
260
|
'\n' +
|
|
233
261
|
cypressCommandEventListener +
|
|
234
|
-
'\n'
|
|
262
|
+
'\n';
|
|
235
263
|
fs.writeFileSync(file, newFileContent, {encoding: 'utf-8'});
|
|
236
264
|
supportFileContentMap[file] = supportFilesData.cleanupParams ? supportFilesData.cleanupParams : defaultFileContent;
|
|
237
265
|
}
|
package/bin/commands/runs.js
CHANGED
|
@@ -40,7 +40,7 @@ const { isTurboScaleSession, getTurboScaleGridDetails, patchCypressConfigFileCon
|
|
|
40
40
|
|
|
41
41
|
|
|
42
42
|
module.exports = function run(args, rawArgs) {
|
|
43
|
-
|
|
43
|
+
utils.normalizeTestReportingEnvVars();
|
|
44
44
|
markBlockStart('preBuild');
|
|
45
45
|
// set debug mode (--cli-debug)
|
|
46
46
|
utils.setDebugMode(args);
|
|
@@ -112,7 +112,7 @@ module.exports = function run(args, rawArgs) {
|
|
|
112
112
|
// set build tag caps
|
|
113
113
|
utils.setBuildTags(bsConfig, args);
|
|
114
114
|
|
|
115
|
-
// Send build start to
|
|
115
|
+
// Send build start to TEST REPORTING AND ANALYTICS
|
|
116
116
|
if(isTestObservabilitySession) {
|
|
117
117
|
await launchTestSession(bsConfig, bsConfigPath);
|
|
118
118
|
utils.setO11yProcessHooks(null, bsConfig, args, null, buildReportData);
|
|
@@ -192,6 +192,10 @@ module.exports = function run(args, rawArgs) {
|
|
|
192
192
|
logger.debug("Completed setting the configs");
|
|
193
193
|
|
|
194
194
|
if(!isBrowserstackInfra) {
|
|
195
|
+
if(process.env.BS_TESTOPS_BUILD_COMPLETED) {
|
|
196
|
+
setEventListeners(bsConfig);
|
|
197
|
+
}
|
|
198
|
+
|
|
195
199
|
return runCypressTestsLocally(bsConfig, args, rawArgs);
|
|
196
200
|
}
|
|
197
201
|
|
|
@@ -203,7 +207,7 @@ module.exports = function run(args, rawArgs) {
|
|
|
203
207
|
setAccessibilityEventListeners(bsConfig);
|
|
204
208
|
}
|
|
205
209
|
if(process.env.BS_TESTOPS_BUILD_COMPLETED) {
|
|
206
|
-
|
|
210
|
+
setEventListeners(bsConfig);
|
|
207
211
|
}
|
|
208
212
|
markBlockEnd('validateConfig');
|
|
209
213
|
logger.debug("Completed configs validation");
|
package/bin/helpers/atsHelper.js
CHANGED
|
@@ -82,6 +82,7 @@ exports.getTurboScaleGridDetails = async (bsConfig, args, rawArgs) => {
|
|
|
82
82
|
}
|
|
83
83
|
resolve(responseData);
|
|
84
84
|
}).catch(error => {
|
|
85
|
+
logger.warn(`Grid with name - ${gridName} not found`);
|
|
85
86
|
logger.warn(utils.formatRequest(error, null, null));
|
|
86
87
|
utils.sendUsageReport(bsConfig, args, error, Constants.messageTypes.ERROR, 'get_ats_details_failed', null, rawArgs);
|
|
87
88
|
resolve({});
|
package/bin/helpers/helper.js
CHANGED
|
@@ -19,10 +19,11 @@ const { readCypressConfigFile } = require('./readCypressConfigUtil');
|
|
|
19
19
|
const { MAX_GIT_META_DATA_SIZE_IN_BYTES, GIT_META_DATA_TRUNCATED } = require('./constants')
|
|
20
20
|
const CrashReporter = require('../testObservability/crashReporter');
|
|
21
21
|
const HttpsProxyAgent = require('https-proxy-agent');
|
|
22
|
+
const { TEST_REPORTING_ANALYTICS } = require("../testObservability/helper/constants");
|
|
22
23
|
|
|
23
24
|
exports.debug = (text, shouldReport = false, throwable = null) => {
|
|
24
25
|
if (process.env.BROWSERSTACK_OBSERVABILITY_DEBUG === "true" || process.env.BROWSERSTACK_OBSERVABILITY_DEBUG === "1") {
|
|
25
|
-
logger.info(`[
|
|
26
|
+
logger.info(`[ ${TEST_REPORTING_ANALYTICS} ] ${text}`);
|
|
26
27
|
}
|
|
27
28
|
if(shouldReport) {
|
|
28
29
|
CrashReporter.getInstance().uploadCrashReport(text, throwable ? throwable && throwable.stack : null);
|
package/bin/helpers/utils.js
CHANGED
|
@@ -33,6 +33,7 @@ exports.validateBstackJson = (bsConfigPath) => {
|
|
|
33
33
|
try {
|
|
34
34
|
logger.info(`Reading config from ${bsConfigPath}`);
|
|
35
35
|
let bsConfig = require(bsConfigPath);
|
|
36
|
+
bsConfig = exports.normalizeTestReportingConfig(bsConfig);
|
|
36
37
|
resolve(bsConfig);
|
|
37
38
|
} catch (e) {
|
|
38
39
|
reject(
|
|
@@ -492,7 +493,6 @@ exports.setNodeVersion = (bsConfig, args) => {
|
|
|
492
493
|
// specs can be passed via command line args as a string
|
|
493
494
|
// command line args takes precedence over config
|
|
494
495
|
exports.setUserSpecs = (bsConfig, args) => {
|
|
495
|
-
|
|
496
496
|
if(o11yHelpers.isBrowserstackInfra() && o11yHelpers.isTestObservabilitySession() && o11yHelpers.shouldReRunObservabilityTests()) {
|
|
497
497
|
bsConfig.run_settings.specs = process.env.BROWSERSTACK_RERUN_TESTS;
|
|
498
498
|
return;
|
|
@@ -1499,7 +1499,6 @@ exports.splitStringByCharButIgnoreIfWithinARange = (str, splitChar, leftLimiter,
|
|
|
1499
1499
|
|
|
1500
1500
|
// blindly send other passed configs with run_settings and handle at backend
|
|
1501
1501
|
exports.setOtherConfigs = (bsConfig, args) => {
|
|
1502
|
-
|
|
1503
1502
|
if(o11yHelpers.isTestObservabilitySession() && process.env.BS_TESTOPS_JWT) {
|
|
1504
1503
|
bsConfig["run_settings"]["reporter"] = TEST_OBSERVABILITY_REPORTER;
|
|
1505
1504
|
return;
|
|
@@ -1519,7 +1518,15 @@ exports.setOtherConfigs = (bsConfig, args) => {
|
|
|
1519
1518
|
exports.readBsConfigJSON = (bsConfigPath) => {
|
|
1520
1519
|
try {
|
|
1521
1520
|
fs.accessSync(bsConfigPath, fs.constants.R_OK);
|
|
1522
|
-
|
|
1521
|
+
const configContent = fs.readFileSync(bsConfigPath, 'utf-8');
|
|
1522
|
+
try {
|
|
1523
|
+
const bsConfig = JSON.parse(configContent);
|
|
1524
|
+
const normalizedBsConfig = exports.normalizeTestReportingConfig(bsConfig);
|
|
1525
|
+
return JSON.stringify(normalizedBsConfig);
|
|
1526
|
+
} catch (err) {
|
|
1527
|
+
logger.error(`Error parsing JSON from ${bsConfigPath}:`, err);
|
|
1528
|
+
return null;
|
|
1529
|
+
}
|
|
1523
1530
|
} catch (err) {
|
|
1524
1531
|
return null;
|
|
1525
1532
|
}
|
|
@@ -1804,3 +1811,25 @@ exports.decodeJWTToken = (token) => {
|
|
|
1804
1811
|
return undefined;
|
|
1805
1812
|
}
|
|
1806
1813
|
}
|
|
1814
|
+
|
|
1815
|
+
exports.normalizeTestReportingEnvVars = () => {
|
|
1816
|
+
if (!this.isUndefined(process.env.BROWSERSTACK_TEST_REPORTING)){
|
|
1817
|
+
process.env.BROWSERSTACK_TEST_OBSERVABILITY = process.env.BROWSERSTACK_TEST_REPORTING;
|
|
1818
|
+
}
|
|
1819
|
+
|
|
1820
|
+
if (!this.isUndefined(process.env.BROWSERSTACK_TEST_REPORTING_DEBUG)){
|
|
1821
|
+
process.env.BROWSERSTACK_OBSERVABILITY_DEBUG = process.env.BROWSERSTACK_TEST_REPORTING_DEBUG;
|
|
1822
|
+
}
|
|
1823
|
+
}
|
|
1824
|
+
|
|
1825
|
+
exports.normalizeTestReportingConfig = (bsConfig) => {
|
|
1826
|
+
if (!this.isUndefined(bsConfig["testReporting"])) {
|
|
1827
|
+
bsConfig["testObservability"] = bsConfig["testReporting"];
|
|
1828
|
+
}
|
|
1829
|
+
|
|
1830
|
+
if (!this.isUndefined(bsConfig["testReportingOptions"])) {
|
|
1831
|
+
bsConfig["testObservabilityOptions"] = bsConfig["testReportingOptions"];
|
|
1832
|
+
}
|
|
1833
|
+
|
|
1834
|
+
return bsConfig;
|
|
1835
|
+
}
|
|
@@ -7,7 +7,7 @@ const HttpsProxyAgent = require('https-proxy-agent');
|
|
|
7
7
|
const logger = require("../../helpers/logger").winstonLogger;
|
|
8
8
|
const utils = require('../../helpers/utils');
|
|
9
9
|
|
|
10
|
-
const { API_URL, consoleHolder } = require('../helper/constants');
|
|
10
|
+
const { API_URL, consoleHolder, TEST_REPORTING_ANALYTICS } = require('../helper/constants');
|
|
11
11
|
|
|
12
12
|
/* Below global methods are added here to remove cyclic dependency with helper.js, refactor later */
|
|
13
13
|
const httpsKeepAliveAgent = new https.Agent({
|
|
@@ -19,7 +19,7 @@ const httpsKeepAliveAgent = new https.Agent({
|
|
|
19
19
|
|
|
20
20
|
const debug = (text) => {
|
|
21
21
|
if (process.env.BROWSERSTACK_OBSERVABILITY_DEBUG === "true" || process.env.BROWSERSTACK_OBSERVABILITY_DEBUG === "1") {
|
|
22
|
-
logger.info(`[
|
|
22
|
+
logger.info(`[ ${TEST_REPORTING_ANALYTICS} ] ${text}`);
|
|
23
23
|
}
|
|
24
24
|
}
|
|
25
25
|
|
|
@@ -1,86 +1,137 @@
|
|
|
1
1
|
/* Event listeners + custom commands for Cypress */
|
|
2
2
|
|
|
3
3
|
/* Used to detect Gherkin steps */
|
|
4
|
+
|
|
5
|
+
const util = require('util');
|
|
6
|
+
|
|
7
|
+
let eventsQueue = [];
|
|
8
|
+
let testRunStarted = false;
|
|
9
|
+
|
|
10
|
+
const browserStackLog = (message) => {
|
|
11
|
+
|
|
12
|
+
if (!Cypress.env('BROWSERSTACK_LOGS')) return;
|
|
13
|
+
cy.task('browserstack_log', message);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
const shouldSkipCommand = (command) => {
|
|
17
|
+
if (!Cypress.env('BROWSERSTACK_O11Y_LOGS')) {
|
|
18
|
+
return true;
|
|
19
|
+
}
|
|
20
|
+
return command.attributes.name == 'log' || (command.attributes.name == 'task' && (['test_observability_platform_details', 'test_observability_step', 'test_observability_command', 'browserstack_log', 'test_observability_log'].some(event => command.attributes.args.includes(event))));
|
|
21
|
+
}
|
|
22
|
+
|
|
4
23
|
Cypress.on('log:added', (log) => {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
}, {log: false})
|
|
24
|
+
return () => {
|
|
25
|
+
if (shouldSkipCommand(command)) {
|
|
26
|
+
return;
|
|
9
27
|
}
|
|
10
|
-
|
|
11
|
-
|
|
28
|
+
eventsQueue.push({
|
|
29
|
+
task: 'test_observability_step',
|
|
30
|
+
data: {
|
|
31
|
+
log,
|
|
32
|
+
started_at: new Date().toISOString(),
|
|
33
|
+
finished_at: new Date().toISOString()
|
|
34
|
+
},
|
|
35
|
+
options: { log: false }
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
});
|
|
39
|
+
|
|
12
40
|
Cypress.on('command:start', (command) => {
|
|
13
|
-
|
|
14
|
-
if
|
|
41
|
+
|
|
42
|
+
if (!command || !command.attributes) return;
|
|
43
|
+
if (shouldSkipCommand(command)) {
|
|
15
44
|
return;
|
|
16
45
|
}
|
|
46
|
+
|
|
17
47
|
/* Send command details */
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
48
|
+
eventsQueue.push({
|
|
49
|
+
task: 'test_observability_command',
|
|
50
|
+
data: {
|
|
51
|
+
type: 'COMMAND_START',
|
|
52
|
+
command: {
|
|
53
|
+
attributes: {
|
|
54
|
+
id: command.attributes.id,
|
|
55
|
+
name: command.attributes.name,
|
|
56
|
+
args: command.attributes.args
|
|
57
|
+
},
|
|
58
|
+
state: 'pending',
|
|
59
|
+
started_at: new Date().toISOString(),
|
|
60
|
+
location: testRunStarted ? 'test' : 'hook'
|
|
61
|
+
}
|
|
62
|
+
},
|
|
63
|
+
options: { log: false }
|
|
30
64
|
});
|
|
31
|
-
|
|
32
65
|
/* Send platform details */
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
}
|
|
39
|
-
|
|
66
|
+
let testTitle = '';
|
|
67
|
+
try {
|
|
68
|
+
const runner = Cypress.mocha.getRunner();
|
|
69
|
+
const ctx = runner.suite.ctx;
|
|
70
|
+
testTitle = ctx.currentTest.title || ctx._runnable.title;
|
|
71
|
+
} catch (error) {
|
|
72
|
+
// Silently handle if any property is undefined
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
eventsQueue.push({
|
|
76
|
+
task: 'test_observability_platform_details',
|
|
77
|
+
data: {
|
|
78
|
+
testTitle,
|
|
79
|
+
browser: Cypress.browser,
|
|
80
|
+
platform: Cypress.platform,
|
|
81
|
+
cypressVersion: Cypress.version
|
|
82
|
+
},
|
|
83
|
+
options: { log: false }
|
|
40
84
|
});
|
|
41
85
|
});
|
|
42
86
|
|
|
43
87
|
Cypress.on('command:retry', (command) => {
|
|
44
|
-
if(!command || !command.attributes) return;
|
|
45
|
-
if
|
|
88
|
+
if (!command || !command.attributes) return;
|
|
89
|
+
if (shouldSkipCommand(command)) {
|
|
46
90
|
return;
|
|
47
91
|
}
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
92
|
+
eventsQueue.push({
|
|
93
|
+
task: 'test_observability_command',
|
|
94
|
+
data: {
|
|
95
|
+
type: 'COMMAND_RETRY',
|
|
96
|
+
command: {
|
|
97
|
+
_log: command._log,
|
|
98
|
+
error: {
|
|
99
|
+
message: command && command.error ? command.error.message : null,
|
|
100
|
+
isDefaultAssertionErr: command && command.error ? command.error.isDefaultAssertionErr : null
|
|
101
|
+
},
|
|
102
|
+
location: testRunStarted ? 'test' : 'hook'
|
|
55
103
|
}
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
}).catch((err) => {
|
|
104
|
+
},
|
|
105
|
+
options: { log: false }
|
|
59
106
|
});
|
|
60
107
|
});
|
|
61
108
|
|
|
62
109
|
Cypress.on('command:end', (command) => {
|
|
63
|
-
if(!command || !command.attributes) return;
|
|
64
|
-
if
|
|
110
|
+
if (!command || !command.attributes) return;
|
|
111
|
+
if (shouldSkipCommand(command)) {
|
|
65
112
|
return;
|
|
66
113
|
}
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
'
|
|
71
|
-
|
|
72
|
-
'
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
114
|
+
eventsQueue.push({
|
|
115
|
+
task: 'test_observability_command',
|
|
116
|
+
data: {
|
|
117
|
+
'type': 'COMMAND_END',
|
|
118
|
+
'command': {
|
|
119
|
+
'attributes': {
|
|
120
|
+
'id': command.attributes.id,
|
|
121
|
+
'name': command.attributes.name,
|
|
122
|
+
'args': command.attributes.args
|
|
123
|
+
},
|
|
124
|
+
'state': command.state,
|
|
125
|
+
finished_at: new Date().toISOString(),
|
|
126
|
+
location: testRunStarted ? 'test' : 'hook'
|
|
127
|
+
}
|
|
128
|
+
},
|
|
129
|
+
options: { log: false }
|
|
79
130
|
});
|
|
80
131
|
});
|
|
81
132
|
|
|
82
133
|
Cypress.Commands.overwrite('log', (originalFn, ...args) => {
|
|
83
|
-
if(args.includes('test_observability_log') || args.includes('test_observability_command')) return;
|
|
134
|
+
if (args.includes('test_observability_log') || args.includes('test_observability_command')) return;
|
|
84
135
|
const message = args.reduce((result, logItem) => {
|
|
85
136
|
if (typeof logItem === 'object') {
|
|
86
137
|
return [result, JSON.stringify(logItem)].join(' ');
|
|
@@ -88,71 +139,118 @@ Cypress.Commands.overwrite('log', (originalFn, ...args) => {
|
|
|
88
139
|
|
|
89
140
|
return [result, logItem ? logItem.toString() : ''].join(' ');
|
|
90
141
|
}, '');
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
142
|
+
eventsQueue.push({
|
|
143
|
+
task: 'test_observability_log',
|
|
144
|
+
data: {
|
|
145
|
+
'level': 'info',
|
|
146
|
+
message,
|
|
147
|
+
timestamp: new Date().toISOString()
|
|
148
|
+
},
|
|
149
|
+
options: { log: false }
|
|
96
150
|
});
|
|
97
151
|
originalFn(...args);
|
|
98
152
|
});
|
|
99
153
|
|
|
100
154
|
Cypress.Commands.add('trace', (message, file) => {
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
155
|
+
eventsQueue.push({
|
|
156
|
+
task: 'test_observability_log',
|
|
157
|
+
data: {
|
|
158
|
+
level: 'trace',
|
|
159
|
+
message,
|
|
160
|
+
file,
|
|
161
|
+
},
|
|
162
|
+
options: { log: false }
|
|
107
163
|
});
|
|
108
164
|
});
|
|
109
165
|
|
|
110
166
|
Cypress.Commands.add('logDebug', (message, file) => {
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
167
|
+
eventsQueue.push({
|
|
168
|
+
task: 'test_observability_log',
|
|
169
|
+
data: {
|
|
170
|
+
level: 'debug',
|
|
171
|
+
message,
|
|
172
|
+
file,
|
|
173
|
+
},
|
|
174
|
+
options: { log: false }
|
|
117
175
|
});
|
|
118
176
|
});
|
|
119
177
|
|
|
120
178
|
Cypress.Commands.add('info', (message, file) => {
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
179
|
+
eventsQueue.push({
|
|
180
|
+
task: 'test_observability_log',
|
|
181
|
+
data: {
|
|
182
|
+
level: 'info',
|
|
183
|
+
message,
|
|
184
|
+
file,
|
|
185
|
+
},
|
|
186
|
+
options: { log: false }
|
|
127
187
|
});
|
|
128
188
|
});
|
|
129
189
|
|
|
130
190
|
Cypress.Commands.add('warn', (message, file) => {
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
191
|
+
eventsQueue.push({
|
|
192
|
+
task: 'test_observability_log',
|
|
193
|
+
data: {
|
|
194
|
+
level: 'warn',
|
|
195
|
+
message,
|
|
196
|
+
file,
|
|
197
|
+
},
|
|
198
|
+
options: { log: false }
|
|
137
199
|
});
|
|
138
200
|
});
|
|
139
201
|
|
|
140
202
|
Cypress.Commands.add('error', (message, file) => {
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
203
|
+
eventsQueue.push({
|
|
204
|
+
task: 'test_observability_log',
|
|
205
|
+
data: {
|
|
206
|
+
level: 'error',
|
|
207
|
+
message,
|
|
208
|
+
file,
|
|
209
|
+
},
|
|
210
|
+
options: { log: false }
|
|
147
211
|
});
|
|
148
212
|
});
|
|
149
213
|
|
|
150
214
|
Cypress.Commands.add('fatal', (message, file) => {
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
215
|
+
eventsQueue.push({
|
|
216
|
+
task: 'test_observability_log',
|
|
217
|
+
data: {
|
|
218
|
+
level: 'fatal',
|
|
219
|
+
message,
|
|
220
|
+
file,
|
|
221
|
+
},
|
|
222
|
+
options: { log: false }
|
|
157
223
|
});
|
|
158
224
|
});
|
|
225
|
+
|
|
226
|
+
beforeEach(() => {
|
|
227
|
+
/* browserstack internal helper hook */
|
|
228
|
+
|
|
229
|
+
if (!Cypress.env('BROWSERSTACK_O11Y_LOGS')) {
|
|
230
|
+
return;
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
if (eventsQueue.length > 0) {
|
|
234
|
+
eventsQueue.forEach(event => {
|
|
235
|
+
cy.task(event.task, event.data, event.options);
|
|
236
|
+
});
|
|
237
|
+
}
|
|
238
|
+
eventsQueue = [];
|
|
239
|
+
testRunStarted = true;
|
|
240
|
+
});
|
|
241
|
+
|
|
242
|
+
afterEach(function() {
|
|
243
|
+
/* browserstack internal helper hook */
|
|
244
|
+
if (!Cypress.env('BROWSERSTACK_O11Y_LOGS')) {
|
|
245
|
+
return;
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
if (eventsQueue.length > 0) {
|
|
249
|
+
eventsQueue.forEach(event => {
|
|
250
|
+
cy.task(event.task, event.data, event.options);
|
|
251
|
+
});
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
eventsQueue = [];
|
|
255
|
+
testRunStarted = false;
|
|
256
|
+
});
|
|
@@ -2,10 +2,9 @@
|
|
|
2
2
|
* Sending all the remaining queues for synchronous manner
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
|
-
const
|
|
5
|
+
const requestHandler = require('./requestQueueHandler');
|
|
6
6
|
|
|
7
7
|
const shutdown = async () => {
|
|
8
|
-
const requestHandler = new RequestQueueHandler();
|
|
9
8
|
requestHandler.queue = require(process.argv[2].trim());
|
|
10
9
|
await requestHandler.shutdown();
|
|
11
10
|
}
|
|
@@ -16,6 +16,7 @@ exports.IPC_EVENTS = {
|
|
|
16
16
|
|
|
17
17
|
exports.OBSERVABILITY_ENV_VARS = [
|
|
18
18
|
"BROWSERSTACK_TEST_OBSERVABILITY",
|
|
19
|
+
"BROWSERSTACK_TEST_REPORTING",
|
|
19
20
|
"BROWSERSTACK_AUTOMATION",
|
|
20
21
|
"BS_TESTOPS_BUILD_COMPLETED",
|
|
21
22
|
"BS_TESTOPS_JWT",
|
|
@@ -23,6 +24,7 @@ exports.OBSERVABILITY_ENV_VARS = [
|
|
|
23
24
|
"BS_TESTOPS_ALLOW_SCREENSHOTS",
|
|
24
25
|
"OBSERVABILITY_LAUNCH_SDK_VERSION",
|
|
25
26
|
"BROWSERSTACK_OBSERVABILITY_DEBUG",
|
|
27
|
+
"BROWSERSTACK_TEST_REPORTING_DEBUG",
|
|
26
28
|
"OBS_CRASH_REPORTING_USERNAME",
|
|
27
29
|
"OBS_CRASH_REPORTING_ACCESS_KEY",
|
|
28
30
|
"OBS_CRASH_REPORTING_BS_CONFIG_PATH",
|
|
@@ -34,3 +36,5 @@ exports.TEST_OBSERVABILITY_REPORTER = 'browserstack-cypress-cli/bin/testObservab
|
|
|
34
36
|
exports.TEST_OBSERVABILITY_REPORTER_LOCAL = path.join(__dirname, '..', 'reporter');
|
|
35
37
|
|
|
36
38
|
exports.PENDING_QUEUES_FILE = `pending_queues_${process.pid}.json`;
|
|
39
|
+
|
|
40
|
+
exports.TEST_REPORTING_ANALYTICS = 'TEST REPORTING AND ANALYTICS';
|
|
@@ -27,7 +27,7 @@ const GLOBAL_MODULE_PATH = execSync('npm root -g').toString().trim();
|
|
|
27
27
|
const { name, version } = require('../../../package.json');
|
|
28
28
|
|
|
29
29
|
const { CYPRESS_V10_AND_ABOVE_CONFIG_FILE_EXTENSIONS } = require('../../helpers/constants');
|
|
30
|
-
const { consoleHolder, API_URL, TEST_OBSERVABILITY_REPORTER, TEST_OBSERVABILITY_REPORTER_LOCAL } = require('./constants');
|
|
30
|
+
const { consoleHolder, API_URL, TEST_OBSERVABILITY_REPORTER, TEST_OBSERVABILITY_REPORTER_LOCAL, TEST_REPORTING_ANALYTICS } = require('./constants');
|
|
31
31
|
|
|
32
32
|
const ALLOWED_MODULES = [
|
|
33
33
|
'cypress/package.json',
|
|
@@ -43,13 +43,13 @@ exports.pending_test_uploads = {
|
|
|
43
43
|
exports.debugOnConsole = (text) => {
|
|
44
44
|
if ((process.env.BROWSERSTACK_OBSERVABILITY_DEBUG + '') === "true" ||
|
|
45
45
|
(process.env.BROWSERSTACK_OBSERVABILITY_DEBUG + '') === "1") {
|
|
46
|
-
consoleHolder.log(`[
|
|
46
|
+
consoleHolder.log(`[ ${TEST_REPORTING_ANALYTICS} ] ${text}`);
|
|
47
47
|
}
|
|
48
48
|
}
|
|
49
49
|
|
|
50
50
|
exports.debug = (text, shouldReport = false, throwable = null) => {
|
|
51
51
|
if (process.env.BROWSERSTACK_OBSERVABILITY_DEBUG === "true" || process.env.BROWSERSTACK_OBSERVABILITY_DEBUG === "1") {
|
|
52
|
-
logger.info(`[
|
|
52
|
+
logger.info(`[ ${TEST_REPORTING_ANALYTICS} ] ${text}`);
|
|
53
53
|
}
|
|
54
54
|
if(shouldReport) {
|
|
55
55
|
CrashReporter.getInstance().uploadCrashReport(text, throwable ? throwable && throwable.stack : null);
|
|
@@ -105,7 +105,7 @@ exports.printBuildLink = async (shouldStopSession, exitCode = null) => {
|
|
|
105
105
|
&& process.env.BS_TESTOPS_BUILD_HASHED_ID != "null"
|
|
106
106
|
&& process.env.BS_TESTOPS_BUILD_HASHED_ID != "undefined") {
|
|
107
107
|
console.log();
|
|
108
|
-
logger.info(`Visit https://
|
|
108
|
+
logger.info(`Visit https://automation.browserstack.com/builds/${process.env.BS_TESTOPS_BUILD_HASHED_ID} to view build report, insights, and many more debugging information all at one place!\n`);
|
|
109
109
|
}
|
|
110
110
|
} catch(err) {
|
|
111
111
|
exports.debug('Build Not Found');
|
|
@@ -117,6 +117,7 @@ exports.printBuildLink = async (shouldStopSession, exitCode = null) => {
|
|
|
117
117
|
}
|
|
118
118
|
|
|
119
119
|
const nodeRequest = (type, url, data, config) => {
|
|
120
|
+
const requestQueueHandler = require('./requestQueueHandler');
|
|
120
121
|
return new Promise(async (resolve, reject) => {
|
|
121
122
|
const options = {
|
|
122
123
|
...config,
|
|
@@ -140,8 +141,8 @@ const nodeRequest = (type, url, data, config) => {
|
|
|
140
141
|
options.proxy = false
|
|
141
142
|
options.httpsAgent = new HttpsProxyAgent(process.env.HTTPS_PROXY);
|
|
142
143
|
}
|
|
143
|
-
|
|
144
|
-
if(url ===
|
|
144
|
+
|
|
145
|
+
if(url === requestQueueHandler.screenshotEventUrl) {
|
|
145
146
|
options.agent = httpsScreenshotsKeepAliveAgent;
|
|
146
147
|
}
|
|
147
148
|
axios(options)
|
|
@@ -513,18 +514,16 @@ exports.batchAndPostEvents = async (eventUrl, kind, data) => {
|
|
|
513
514
|
} catch(error) {
|
|
514
515
|
exports.debugOnConsole(`[Request Error] Error in sending request ${util.format(error)}`);
|
|
515
516
|
if (error.response) {
|
|
516
|
-
exports.debug(`EXCEPTION IN ${kind} REQUEST TO
|
|
517
|
+
exports.debug(`EXCEPTION IN ${kind} REQUEST TO ${TEST_REPORTING_ANALYTICS} : ${error.response.status} ${error.response.statusText} ${JSON.stringify(error.response.data)}`, true, error);
|
|
517
518
|
} else {
|
|
518
|
-
exports.debug(`EXCEPTION IN ${kind} REQUEST TO
|
|
519
|
+
exports.debug(`EXCEPTION IN ${kind} REQUEST TO ${TEST_REPORTING_ANALYTICS} : ${error.message || error}`, true, error);
|
|
519
520
|
}
|
|
520
521
|
exports.pending_test_uploads.count = Math.max(0,exports.pending_test_uploads.count - data.length);
|
|
521
522
|
}
|
|
522
523
|
}
|
|
523
524
|
|
|
524
|
-
const RequestQueueHandler = require('./requestQueueHandler');
|
|
525
|
-
exports.requestQueueHandler = new RequestQueueHandler();
|
|
526
|
-
|
|
527
525
|
exports.uploadEventData = async (eventData, run=0) => {
|
|
526
|
+
const requestQueueHandler = require('./requestQueueHandler');
|
|
528
527
|
exports.debugOnConsole(`[uploadEventData] ${eventData.event_type}`);
|
|
529
528
|
const log_tag = {
|
|
530
529
|
['TestRunStarted']: 'Test_Start_Upload',
|
|
@@ -541,7 +540,7 @@ exports.uploadEventData = async (eventData, run=0) => {
|
|
|
541
540
|
|
|
542
541
|
if (process.env.BS_TESTOPS_BUILD_COMPLETED === "true") {
|
|
543
542
|
if(process.env.BS_TESTOPS_JWT == "null") {
|
|
544
|
-
exports.debug(`EXCEPTION IN ${log_tag} REQUEST TO
|
|
543
|
+
exports.debug(`EXCEPTION IN ${log_tag} REQUEST TO ${TEST_REPORTING_ANALYTICS}: missing authentication token`);
|
|
545
544
|
exports.pending_test_uploads.count = Math.max(0,exports.pending_test_uploads.count-1);
|
|
546
545
|
return {
|
|
547
546
|
status: 'error',
|
|
@@ -550,8 +549,8 @@ exports.uploadEventData = async (eventData, run=0) => {
|
|
|
550
549
|
} else {
|
|
551
550
|
let data = eventData, event_api_url = 'api/v1/event';
|
|
552
551
|
|
|
553
|
-
|
|
554
|
-
const { shouldProceed, proceedWithData, proceedWithUrl } =
|
|
552
|
+
requestQueueHandler.start();
|
|
553
|
+
const { shouldProceed, proceedWithData, proceedWithUrl } = requestQueueHandler.add(eventData);
|
|
555
554
|
exports.debugOnConsole(`[Request Queue] ${eventData.event_type} with uuid ${eventData.test_run ? eventData.test_run.uuid : (eventData.hook_run ? eventData.hook_run.uuid : null)} is added`)
|
|
556
555
|
if(!shouldProceed) {
|
|
557
556
|
return;
|
|
@@ -576,7 +575,7 @@ exports.uploadEventData = async (eventData, run=0) => {
|
|
|
576
575
|
if(response.data.error) {
|
|
577
576
|
throw({message: response.data.error});
|
|
578
577
|
} else {
|
|
579
|
-
exports.debug(`${event_api_url !==
|
|
578
|
+
exports.debug(`${event_api_url !== requestQueueHandler.eventUrl ? log_tag : 'Batch-Queue'}[${run}] event successfull!`)
|
|
580
579
|
exports.pending_test_uploads.count = Math.max(0,exports.pending_test_uploads.count - (event_api_url === 'api/v1/event' ? 1 : data.length));
|
|
581
580
|
return {
|
|
582
581
|
status: 'success',
|
|
@@ -586,9 +585,9 @@ exports.uploadEventData = async (eventData, run=0) => {
|
|
|
586
585
|
} catch(error) {
|
|
587
586
|
exports.debugOnConsole(`[Request Error] Error in sending request ${util.format(error)}`);
|
|
588
587
|
if (error.response) {
|
|
589
|
-
exports.debug(`EXCEPTION IN ${event_api_url !==
|
|
588
|
+
exports.debug(`EXCEPTION IN ${event_api_url !== requestQueueHandler.eventUrl ? log_tag : 'Batch-Queue'} REQUEST TO ${TEST_REPORTING_ANALYTICS} : ${error.response.status} ${error.response.statusText} ${JSON.stringify(error.response.data)}`, true, error);
|
|
590
589
|
} else {
|
|
591
|
-
exports.debug(`EXCEPTION IN ${event_api_url !==
|
|
590
|
+
exports.debug(`EXCEPTION IN ${event_api_url !== requestQueueHandler.eventUrl ? log_tag : 'Batch-Queue'} REQUEST TO ${TEST_REPORTING_ANALYTICS} : ${error.message || error}`, true, error);
|
|
592
591
|
}
|
|
593
592
|
exports.pending_test_uploads.count = Math.max(0,exports.pending_test_uploads.count - (event_api_url === 'api/v1/event' ? 1 : data.length));
|
|
594
593
|
return {
|
|
@@ -598,7 +597,7 @@ exports.uploadEventData = async (eventData, run=0) => {
|
|
|
598
597
|
}
|
|
599
598
|
}
|
|
600
599
|
} else if (run >= 5) {
|
|
601
|
-
exports.debug(`EXCEPTION IN ${log_tag} REQUEST TO
|
|
600
|
+
exports.debug(`EXCEPTION IN ${log_tag} REQUEST TO ${TEST_REPORTING_ANALYTICS} : Build Start is not completed and ${log_tag} retry runs exceeded`);
|
|
602
601
|
if(process.env.BS_TESTOPS_JWT != "null") exports.pending_test_uploads.count = Math.max(0,exports.pending_test_uploads.count-1);
|
|
603
602
|
return {
|
|
604
603
|
status: 'error',
|
|
@@ -664,7 +663,7 @@ exports.shouldReRunObservabilityTests = () => {
|
|
|
664
663
|
exports.stopBuildUpstream = async () => {
|
|
665
664
|
if (process.env.BS_TESTOPS_BUILD_COMPLETED === "true") {
|
|
666
665
|
if(process.env.BS_TESTOPS_JWT == "null" || process.env.BS_TESTOPS_BUILD_HASHED_ID == "null") {
|
|
667
|
-
exports.debug(
|
|
666
|
+
exports.debug(`EXCEPTION IN stopBuildUpstream REQUEST TO ${TEST_REPORTING_ANALYTICS} : Missing authentication token`);
|
|
668
667
|
return {
|
|
669
668
|
status: 'error',
|
|
670
669
|
message: 'Token/buildID is undefined, build creation might have failed'
|
|
@@ -694,9 +693,9 @@ exports.stopBuildUpstream = async () => {
|
|
|
694
693
|
}
|
|
695
694
|
} catch(error) {
|
|
696
695
|
if (error.response) {
|
|
697
|
-
exports.debug(`EXCEPTION IN stopBuildUpstream REQUEST TO
|
|
696
|
+
exports.debug(`EXCEPTION IN stopBuildUpstream REQUEST TO ${TEST_REPORTING_ANALYTICS} : ${error.response.status} ${error.response.statusText} ${JSON.stringify(error.response.data)}`, true, error);
|
|
698
697
|
} else {
|
|
699
|
-
exports.debug(`EXCEPTION IN stopBuildUpstream REQUEST TO
|
|
698
|
+
exports.debug(`EXCEPTION IN stopBuildUpstream REQUEST TO ${TEST_REPORTING_ANALYTICS} : ${error.message || error}`, true, error);
|
|
700
699
|
}
|
|
701
700
|
return {
|
|
702
701
|
status: 'error',
|
|
@@ -3,6 +3,12 @@ const { connectIPCClient } = require('./ipcClient');
|
|
|
3
3
|
const { IPC_EVENTS } = require('../helper/constants');
|
|
4
4
|
|
|
5
5
|
const browserstackTestObservabilityPlugin = (on, config, callbacks) => {
|
|
6
|
+
|
|
7
|
+
try {
|
|
8
|
+
config.env.BROWSERSTACK_O11Y_LOGS = 'true';
|
|
9
|
+
process.env.BROWSERSTACK_O11Y_LOGS = 'true';
|
|
10
|
+
} catch (err) {}
|
|
11
|
+
|
|
6
12
|
connectIPCClient(config);
|
|
7
13
|
|
|
8
14
|
on('task', {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
const ipc = require('node-ipc');
|
|
2
2
|
const { consoleHolder } = require('../helper/constants');
|
|
3
|
-
const
|
|
3
|
+
const requestQueueHandler = require('../helper/requestQueueHandler');
|
|
4
4
|
|
|
5
5
|
exports.startIPCServer = (subscribeServerEvents, unsubscribeServerEvents) => {
|
|
6
6
|
if (ipc.server) {
|
|
@@ -12,7 +12,7 @@ const Mocha = requireModule('mocha');
|
|
|
12
12
|
const Runnable = require('mocha/lib/runnable'); // need to handle as this isn't present in older mocha versions
|
|
13
13
|
const { v4: uuidv4 } = require('uuid');
|
|
14
14
|
|
|
15
|
-
const { IPC_EVENTS } = require('../helper/constants');
|
|
15
|
+
const { IPC_EVENTS, TEST_REPORTING_ANALYTICS } = require('../helper/constants');
|
|
16
16
|
const { startIPCServer } = require('../plugin/ipcServer');
|
|
17
17
|
|
|
18
18
|
const HOOK_TYPES_MAP = {
|
|
@@ -52,7 +52,6 @@ const {
|
|
|
52
52
|
mapTestHooks,
|
|
53
53
|
debug,
|
|
54
54
|
isBrowserstackInfra,
|
|
55
|
-
requestQueueHandler,
|
|
56
55
|
getHookSkippedTests,
|
|
57
56
|
getOSDetailsFromSystem,
|
|
58
57
|
findGitConfig,
|
|
@@ -88,6 +87,7 @@ class MyReporter {
|
|
|
88
87
|
})
|
|
89
88
|
|
|
90
89
|
.on(EVENT_HOOK_BEGIN, async (hook) => {
|
|
90
|
+
if (this.isInternalHook(hook)) return;
|
|
91
91
|
debugOnConsole(`[MOCHA EVENT] EVENT_HOOK_BEGIN`);
|
|
92
92
|
if(this.testObservability == true) {
|
|
93
93
|
if(!hook.hookAnalyticsId) {
|
|
@@ -105,6 +105,7 @@ class MyReporter {
|
|
|
105
105
|
})
|
|
106
106
|
|
|
107
107
|
.on(EVENT_HOOK_END, async (hook) => {
|
|
108
|
+
if (this.isInternalHook(hook)) return;
|
|
108
109
|
debugOnConsole(`[MOCHA EVENT] EVENT_HOOK_END`);
|
|
109
110
|
if(this.testObservability == true) {
|
|
110
111
|
if(!this.runStatusMarkedHash[hook.hookAnalyticsId]) {
|
|
@@ -206,6 +207,13 @@ class MyReporter {
|
|
|
206
207
|
});
|
|
207
208
|
}
|
|
208
209
|
|
|
210
|
+
isInternalHook(hook) {
|
|
211
|
+
if (hook && hook.body && hook.body.includes('/* browserstack internal helper hook */')) {
|
|
212
|
+
return true;
|
|
213
|
+
}
|
|
214
|
+
return false;
|
|
215
|
+
}
|
|
216
|
+
|
|
209
217
|
registerListeners() {
|
|
210
218
|
startIPCServer(
|
|
211
219
|
(server) => {
|
|
@@ -247,7 +255,7 @@ class MyReporter {
|
|
|
247
255
|
}
|
|
248
256
|
}
|
|
249
257
|
|
|
250
|
-
uploadTestSteps = async (shouldClearCurrentSteps = true, cypressSteps = null) => {
|
|
258
|
+
uploadTestSteps = async (shouldClearCurrentSteps = true, cypressSteps = null) => {
|
|
251
259
|
const currentTestSteps = cypressSteps ? cypressSteps : JSON.parse(JSON.stringify(this.currentTestSteps));
|
|
252
260
|
/* TODO - Send as test logs */
|
|
253
261
|
const allStepsAsLogs = [];
|
|
@@ -511,14 +519,14 @@ class MyReporter {
|
|
|
511
519
|
});
|
|
512
520
|
}
|
|
513
521
|
} catch(error) {
|
|
514
|
-
debug(`Exception in uploading log data to
|
|
522
|
+
debug(`Exception in uploading log data to ${TEST_REPORTING_ANALYTICS} with error : ${error}`, true, error);
|
|
515
523
|
}
|
|
516
524
|
}
|
|
517
525
|
|
|
518
526
|
cypressConfigListener = async (config) => {
|
|
519
527
|
}
|
|
520
528
|
|
|
521
|
-
cypressCucumberStepListener = async ({log}) => {
|
|
529
|
+
cypressCucumberStepListener = async ({log, started_at, finished_at}) => {
|
|
522
530
|
if(log.name == 'step' && log.consoleProps && log.consoleProps.step && log.consoleProps.step.keyword) {
|
|
523
531
|
this.currentTestCucumberSteps = [
|
|
524
532
|
...this.currentTestCucumberSteps,
|
|
@@ -526,8 +534,8 @@ class MyReporter {
|
|
|
526
534
|
id: log.chainerId,
|
|
527
535
|
keyword: log.consoleProps.step.keyword,
|
|
528
536
|
text: log.consoleProps.step.text,
|
|
529
|
-
started_at: new Date().toISOString(),
|
|
530
|
-
finished_at: new Date().toISOString(),
|
|
537
|
+
started_at: started_at || new Date().toISOString(),
|
|
538
|
+
finished_at: finished_at || new Date().toISOString(),
|
|
531
539
|
duration: 0,
|
|
532
540
|
result: 'passed'
|
|
533
541
|
}
|
|
@@ -537,8 +545,8 @@ class MyReporter {
|
|
|
537
545
|
if(gherkinStep.id == log.chainerId) {
|
|
538
546
|
this.currentTestCucumberSteps[idx] = {
|
|
539
547
|
...gherkinStep,
|
|
540
|
-
finished_at: new Date().toISOString(),
|
|
541
|
-
duration: Date.now() - (new Date(gherkinStep.started_at)).getTime(),
|
|
548
|
+
finished_at: finished_at || new Date().toISOString(),
|
|
549
|
+
duration: (finished_at ? new Date(finished_at).getTime() : Date.now()) - (new Date(gherkinStep.started_at)).getTime(),
|
|
542
550
|
result: log.state,
|
|
543
551
|
failure: log.err?.stack || log.err?.message,
|
|
544
552
|
failure_reason: log.err?.stack || log.err?.message,
|
|
@@ -549,9 +557,9 @@ class MyReporter {
|
|
|
549
557
|
}
|
|
550
558
|
}
|
|
551
559
|
|
|
552
|
-
cypressLogListener = async ({level, message
|
|
560
|
+
cypressLogListener = async ({timestamp, level, message}) => {
|
|
553
561
|
this.appendTestItemLog({
|
|
554
|
-
timestamp: new Date().toISOString(),
|
|
562
|
+
timestamp: timestamp || new Date().toISOString(),
|
|
555
563
|
level: level.toUpperCase(),
|
|
556
564
|
message,
|
|
557
565
|
kind: 'TEST_LOG',
|
|
@@ -612,12 +620,12 @@ class MyReporter {
|
|
|
612
620
|
const currentStepObj = {
|
|
613
621
|
id: command.attributes.id,
|
|
614
622
|
text: 'cy.' + command.attributes.name + '(' + this.getFormattedArgs(command.attributes.args) + ')',
|
|
615
|
-
started_at: new Date().toISOString(),
|
|
623
|
+
started_at: command.started_at || new Date().toISOString(),
|
|
616
624
|
finished_at: null,
|
|
617
625
|
duration: null,
|
|
618
626
|
result: 'pending',
|
|
619
|
-
test_run_uuid:
|
|
620
|
-
hook_run_uuid :
|
|
627
|
+
test_run_uuid: command.location === 'test' ? this.current_test?.testAnalyticsId : null,
|
|
628
|
+
hook_run_uuid : command.location === 'hook' ? this.current_hook?.hookAnalyticsId : null
|
|
621
629
|
};
|
|
622
630
|
if(currentStepObj.hook_run_uuid && currentStepObj.test_run_uuid) delete currentStepObj.test_run_uuid;
|
|
623
631
|
this.currentTestSteps = [
|
|
@@ -630,8 +638,8 @@ class MyReporter {
|
|
|
630
638
|
if(val.id == command.attributes.id) {
|
|
631
639
|
this.currentTestSteps[idx] = {
|
|
632
640
|
...val,
|
|
633
|
-
finished_at: new Date().toISOString(),
|
|
634
|
-
duration: Date.now() - (new Date(val.started_at)).getTime(),
|
|
641
|
+
finished_at: command.finished_at || new Date().toISOString(),
|
|
642
|
+
duration: (command.finished_at ? new Date(command.finished_at).getTime() : Date.now()) - (new Date(val.started_at)).getTime(),
|
|
635
643
|
result: command.state
|
|
636
644
|
};
|
|
637
645
|
stepUpdated = true;
|
|
@@ -647,8 +655,8 @@ class MyReporter {
|
|
|
647
655
|
finished_at: new Date().toISOString(),
|
|
648
656
|
duration: 0,
|
|
649
657
|
result: command.state,
|
|
650
|
-
test_run_uuid:
|
|
651
|
-
hook_run_uuid :
|
|
658
|
+
test_run_uuid: command.location === 'test' ? this.current_test?.testAnalyticsId : null,
|
|
659
|
+
hook_run_uuid : command.location === 'hook' ? this.current_hook?.hookAnalyticsId : null
|
|
652
660
|
};
|
|
653
661
|
if(currentStepObj.hook_run_uuid && currentStepObj.test_run_uuid) delete currentStepObj.test_run_uuid;
|
|
654
662
|
this.currentTestSteps = [
|
package/package.json
CHANGED
package/log/usage.log
DELETED
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
{"level":"info","message":"Sending {\"event_type\":\"cypress_cli_stats\",\"data\":{\"bstack_json\":\"null\",\"run_settings\":\"\",\"os\":\"darwin\",\"os_version\":\"23.6.0\",\"bstack_json_found_in_pwd\":false,\"cypress_config_file_found_in_pwd\":null,\"cli_version\":\"1.32.5\",\"cli_path\":\"/Users/karannagpal/.nvm/versions/node/v16.10.0/lib/node_modules\",\"npm_version\":\"7.24.0\",\"local_cypress_version\":null,\"ci_environment\":null,\"event_timestamp\":\"3/12/2025, 3:47:25 PM\",\"data\":null,\"raw_args\":\"[\\\"run\\\",\\\"--sync\\\",\\\"--config-file\\\",\\\"./browserstack-prod.json\\\",\\\"--cypress-config-file\\\",\\\"./cypress.config.js\\\"]\",\"cli_args\":\"{\\\"_\\\":[\\\"run\\\"],\\\"sync\\\":true,\\\"config-file\\\":\\\"./browserstack-prod.json\\\",\\\"cf\\\":\\\"./browserstack-prod.json\\\",\\\"configFile\\\":\\\"./browserstack-prod.json\\\",\\\"cypress-config-file\\\":\\\"./cypress.config.js\\\",\\\"ccf\\\":\\\"./cypress.config.js\\\",\\\"cypressConfigFile\\\":\\\"./cypress.config.js\\\",\\\"cli-debug\\\":false,\\\"cliDebug\\\":false,\\\"disable-npm-warning\\\":false,\\\"disableNpmWarning\\\":false,\\\"async\\\":false,\\\"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":"2025-03-12T10:17:25.299Z"}
|
|
2
|
-
{"level":"info","message":"{\"statusText\":\"OK\",\"statusCode\":200,\"body\":\"Bravo\"}","timestamp":"2025-03-12T10:17:26.295Z"}
|
|
3
|
-
{"level":"info","message":"Sending {\"event_type\":\"cypress_cli_stats\",\"data\":{\"bstack_json\":\"null\",\"run_settings\":\"\",\"os\":\"darwin\",\"os_version\":\"23.6.0\",\"bstack_json_found_in_pwd\":false,\"cypress_config_file_found_in_pwd\":null,\"cli_version\":\"1.32.5\",\"cli_path\":\"/Users/karannagpal/.nvm/versions/node/v16.10.0/lib/node_modules\",\"npm_version\":\"7.24.0\",\"local_cypress_version\":null,\"ci_environment\":null,\"event_timestamp\":\"3/12/2025, 6:46:06 PM\",\"data\":null,\"raw_args\":\"[\\\"run\\\",\\\"--sync\\\",\\\"--config-file\\\",\\\"./browserstack-prod.json\\\",\\\"--cypress-config-file\\\",\\\"./cypress.config.js\\\"]\",\"cli_args\":\"{\\\"_\\\":[\\\"run\\\"],\\\"sync\\\":true,\\\"config-file\\\":\\\"./browserstack-prod.json\\\",\\\"cf\\\":\\\"./browserstack-prod.json\\\",\\\"configFile\\\":\\\"./browserstack-prod.json\\\",\\\"cypress-config-file\\\":\\\"./cypress.config.js\\\",\\\"ccf\\\":\\\"./cypress.config.js\\\",\\\"cypressConfigFile\\\":\\\"./cypress.config.js\\\",\\\"cli-debug\\\":false,\\\"cliDebug\\\":false,\\\"disable-npm-warning\\\":false,\\\"disableNpmWarning\\\":false,\\\"async\\\":false,\\\"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":"2025-03-12T13:16:06.225Z"}
|
|
4
|
-
{"level":"info","message":"{\"statusText\":\"OK\",\"statusCode\":200,\"body\":\"Bravo\"}","timestamp":"2025-03-12T13:16:07.276Z"}
|