Skip to content

Commit 1e87572

Browse files
committed
qa fixes
1 parent f447548 commit 1e87572

File tree

5 files changed

+50
-51
lines changed

5 files changed

+50
-51
lines changed

bin/commands/runs.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ const { getStackTraceUrl } = require('../helpers/sync/syncSpecsLogs');
2626
const {
2727
launchTestSession,
2828
setTestObservabilityFlags,
29-
runCypressTestsLocally
29+
runCypressTestsLocally,
30+
printBuildLink
3031
} = require('../testObservability/helper/helper');
3132

3233
module.exports = function run(args, rawArgs) {
@@ -316,7 +317,10 @@ module.exports = function run(args, rawArgs) {
316317

317318
logger.info(message);
318319
logger.info(dashboardLink);
319-
if(!args.sync) logger.info(Constants.userMessages.EXIT_SYNC_CLI_MESSAGE.replace("<build-id>",data.build_id));
320+
if(!args.sync) {
321+
logger.info(Constants.userMessages.EXIT_SYNC_CLI_MESSAGE.replace("<build-id>",data.build_id));
322+
printBuildLink(false);
323+
}
320324
let dataToSend = {
321325
time_components: getTimeComponents(),
322326
unique_id: utils.generateUniqueHash(),

bin/commands/stop.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@ const config = require("../helpers/config"),
55
logger = require("../helpers/logger").winstonLogger,
66
Constants = require("../helpers/constants"),
77
utils = require("../helpers/utils"),
8-
getInitialDetails = require('../helpers/getInitialDetails').getInitialDetails,
9-
{ printBuildLink } = require('../testObservability/helper/helper');
8+
getInitialDetails = require('../helpers/getInitialDetails').getInitialDetails;
109

1110
module.exports = function stop(args, rawArgs) {
1211
let bsConfigPath = utils.getConfigPath(args.cf);
@@ -31,8 +30,6 @@ module.exports = function stop(args, rawArgs) {
3130

3231
await utils.stopBrowserStackBuild(bsConfig, args, buildId, rawArgs, buildReportData);
3332

34-
await printBuildLink();
35-
3633
}).catch(function (err) {
3734
logger.error(err);
3835
utils.setUsageReportingFlag(null, args.disableUsageReporting);

bin/helpers/utils.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1143,7 +1143,11 @@ exports.handleSyncExit = (exitCode, dashboard_url) => {
11431143
syncCliLogger.info(Constants.userMessages.BUILD_REPORT_MESSAGE);
11441144
syncCliLogger.info(dashboard_url);
11451145
}
1146-
process.exit(exitCode);
1146+
if(isTestObservabilitySession()) {
1147+
printBuildLink(true, exitCode);
1148+
} else {
1149+
process.exit(exitCode);
1150+
}
11471151
}
11481152

11491153
exports.getNetworkErrorMessage = (dashboard_url) => {
@@ -1408,7 +1412,7 @@ async function processExitHandler(exitData){
14081412
logger.warn(Constants.userMessages.PROCESS_KILL_MESSAGE);
14091413
await this.stopBrowserStackBuild(exitData.bsConfig, exitData.args, exitData.buildId, null, exitData.buildReportData);
14101414
await this.stopLocalBinary(exitData.bsConfig, exitData.bsLocalInstance, exitData.args, null, exitData.buildReportData);
1411-
await printBuildLink();
1415+
await printBuildLink(true);
14121416
process.exit(0);
14131417
}
14141418

bin/testObservability/cypress/index.js

Lines changed: 11 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,9 @@ Cypress.on('log:added', (log) => {
1010
});
1111

1212
Cypress.on('command:start', (command) => {
13-
if(
14-
command?.attributes?.name == 'log' ||
15-
(command?.attributes?.name == 'task' &&
16-
(
17-
command?.attributes?.args?.includes('test_observability_command') ||
18-
command?.attributes?.args?.includes('test_observability_log')
19-
)
20-
)
21-
) {
22-
return;
13+
if(!command || !command.attributes) return;
14+
if(command.attributes.name == 'log' || (command.attributes.name == 'task' && (command.attributes.args.includes('test_observability_command') || command.attributes.args.includes('test_observability_log')))) {
15+
return;
2316
}
2417
/* Send command details */
2518
cy.now('task', 'test_observability_command', {
@@ -48,24 +41,17 @@ Cypress.on('command:start', (command) => {
4841
});
4942

5043
Cypress.on('command:retry', (command) => {
51-
if(
52-
command?.attributes?.name == 'log' ||
53-
(command?.attributes?.name == 'task' &&
54-
(
55-
command?.attributes?.args?.includes('test_observability_command') ||
56-
command?.attributes?.args?.includes('test_observability_log')
57-
)
58-
)
59-
) {
60-
return;
44+
if(!command || !command.attributes) return;
45+
if(command.attributes.name == 'log' || (command.attributes.name == 'task' && (command.attributes.args.includes('test_observability_command') || command.attributes.args.includes('test_observability_log')))) {
46+
return;
6147
}
6248
cy.now('task', 'test_observability_command', {
6349
type: 'COMMAND_RETRY',
6450
command: {
6551
_log: command._log,
6652
error: {
67-
message: command?.error?.message,
68-
isDefaultAssertionErr: command?.error?.isDefaultAssertionErr
53+
message: command && command.error ? command.error.message : null,
54+
isDefaultAssertionErr: command && command.error ? command.error.isDefaultAssertionErr : null
6955
}
7056
}
7157
}, {log: false}).then((res) => {
@@ -74,16 +60,9 @@ Cypress.on('command:retry', (command) => {
7460
});
7561

7662
Cypress.on('command:end', (command) => {
77-
if(
78-
command?.attributes?.name == 'log' ||
79-
(command?.attributes?.name == 'task' &&
80-
(
81-
command?.attributes?.args?.includes('test_observability_command') ||
82-
command?.attributes?.args?.includes('test_observability_log')
83-
)
84-
)
85-
) {
86-
return;
63+
if(!command || !command.attributes) return;
64+
if(command.attributes.name == 'log' || (command.attributes.name == 'task' && (command.attributes.args.includes('test_observability_command') || command.attributes.args.includes('test_observability_log')))) {
65+
return;
8766
}
8867
cy.now('task', 'test_observability_command', {
8968
'type': 'COMMAND_END',

bin/testObservability/helper/helper.js

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -78,11 +78,13 @@ const supportFileCleanup = () => {
7878
});
7979
}
8080

81-
exports.printBuildLink = async () => {
81+
exports.printBuildLink = async (shouldStopSession, exitCode = null) => {
8282
if(!this.isTestObservabilitySession()) return;
8383
try {
84-
supportFileCleanup();
85-
await this.stopBuildUpstream();
84+
if(shouldStopSession) {
85+
supportFileCleanup();
86+
await this.stopBuildUpstream();
87+
}
8688
try {
8789
if(process.env.BS_TESTOPS_BUILD_HASHED_ID
8890
&& process.env.BS_TESTOPS_BUILD_HASHED_ID != "null"
@@ -96,6 +98,7 @@ exports.printBuildLink = async () => {
9698
} catch(err) {
9799
exports.debug(`Error while stopping build with error : ${err}`, true, err);
98100
}
101+
if(exitCode) process.exit(exitCode);
99102
}
100103

101104
const nodeRequest = (type, url, data, config) => {
@@ -748,16 +751,28 @@ exports.isTestObservabilitySupportedCypressVersion = (cypress_config_filename) =
748751
exports.setTestObservabilityFlags = (bsConfig) => {
749752
/* testObservability */
750753
let isTestObservabilitySession = true;
751-
if(!utils.isUndefined(bsConfig["testObservability"])) isTestObservabilitySession = ( bsConfig["testObservability"] == true || bsConfig["testObservability"] == 1 );
752-
if(!utils.isUndefined(process.env.BROWSERSTACK_TEST_OBSERVABILITY)) isTestObservabilitySession = ( process.env.BROWSERSTACK_TEST_OBSERVABILITY == "true" || process.env.BROWSERSTACK_TEST_OBSERVABILITY == "1" );
753-
if(process.argv.includes('--disable-test-observability')) isTestObservabilitySession = false;
754-
isTestObservabilitySession = isTestObservabilitySession && this.isTestObservabilitySupportedCypressVersion(bsConfig.run_settings.cypress_config_file);
754+
try {
755+
if(!utils.isUndefined(bsConfig["testObservability"])) isTestObservabilitySession = ( bsConfig["testObservability"] == true || bsConfig["testObservability"] == 1 );
756+
if(!utils.isUndefined(process.env.BROWSERSTACK_TEST_OBSERVABILITY)) isTestObservabilitySession = ( process.env.BROWSERSTACK_TEST_OBSERVABILITY == "true" || process.env.BROWSERSTACK_TEST_OBSERVABILITY == "1" );
757+
if(process.argv.includes('--disable-test-observability')) isTestObservabilitySession = false;
758+
isTestObservabilitySession = isTestObservabilitySession && this.isTestObservabilitySupportedCypressVersion(bsConfig.run_settings.cypress_config_file);
759+
} catch(e) {
760+
isTestObservabilitySession = false;
761+
exports.debug(`EXCEPTION while parsing testObservability capability with error ${e}`);
762+
}
763+
755764

756765
/* browserstackAutomation */
757766
let isBrowserstackInfra = true;
758-
if(!utils.isUndefined(bsConfig["browserstackAutomation"])) isBrowserstackInfra = ( bsConfig["browserstackAutomation"] == true || bsConfig["browserstackAutomation"] == 1 );
759-
if(!utils.isUndefined(process.env.BROWSERSTACK_AUTOMATION)) isBrowserstackInfra = ( process.env.BROWSERSTACK_AUTOMATION == "true" || process.env.BROWSERSTACK_AUTOMATION == "1" );
760-
if(process.argv.includes('--disable-browserstack-automation')) isBrowserstackInfra = false;
767+
try {
768+
if(!utils.isUndefined(bsConfig["browserstackAutomation"])) isBrowserstackInfra = ( bsConfig["browserstackAutomation"] == true || bsConfig["browserstackAutomation"] == 1 );
769+
if(!utils.isUndefined(process.env.BROWSERSTACK_AUTOMATION)) isBrowserstackInfra = ( process.env.BROWSERSTACK_AUTOMATION == "true" || process.env.BROWSERSTACK_AUTOMATION == "1" );
770+
if(process.argv.includes('--disable-browserstack-automation')) isBrowserstackInfra = false;
771+
} catch(e) {
772+
isBrowserstackInfra = true;
773+
exports.debug(`EXCEPTION while parsing browserstackAutomation capability with error ${e}`);
774+
}
775+
761776

762777
process.env.BROWSERSTACK_TEST_OBSERVABILITY = isTestObservabilitySession;
763778
process.env.BROWSERSTACK_AUTOMATION = isBrowserstackInfra;
@@ -961,7 +976,7 @@ exports.runCypressTestsLocally = (bsConfig, args, rawArgs) => {
961976
);
962977
cypressProcess.on('close', async (code) => {
963978
logger.info(`Cypress process exited with code ${code}`);
964-
await this.printBuildLink();
979+
await this.printBuildLink(true);
965980
});
966981

967982
cypressProcess.on('error', (err) => {

0 commit comments

Comments
 (0)