Skip to content

Commit f99dd89

Browse files
committed
Merge remote-tracking branch 'upstream/master' into fix_cypress_v13_approach_2
2 parents 8b736fc + 5b94ffb commit f99dd89

File tree

7 files changed

+57
-23
lines changed

7 files changed

+57
-23
lines changed

bin/commands/runs.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ const { isTurboScaleSession, getTurboScaleGridDetails, patchCypressConfigFileCon
4040

4141

4242
module.exports = function run(args, rawArgs) {
43-
43+
utils.normalizeTestReportingEnvVars();
4444
markBlockStart('preBuild');
4545
// set debug mode (--cli-debug)
4646
utils.setDebugMode(args);
@@ -112,7 +112,7 @@ module.exports = function run(args, rawArgs) {
112112
// set build tag caps
113113
utils.setBuildTags(bsConfig, args);
114114

115-
// Send build start to Observability
115+
// Send build start to TEST REPORTING AND ANALYTICS
116116
if(isTestObservabilitySession) {
117117
await launchTestSession(bsConfig, bsConfigPath);
118118
utils.setO11yProcessHooks(null, bsConfig, args, null, buildReportData);

bin/helpers/helper.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,11 @@ const { readCypressConfigFile } = require('./readCypressConfigUtil');
1919
const { MAX_GIT_META_DATA_SIZE_IN_BYTES, GIT_META_DATA_TRUNCATED } = require('./constants')
2020
const CrashReporter = require('../testObservability/crashReporter');
2121
const HttpsProxyAgent = require('https-proxy-agent');
22+
const { TEST_REPORTING_ANALYTICS } = require("../testObservability/helper/constants");
2223

2324
exports.debug = (text, shouldReport = false, throwable = null) => {
2425
if (process.env.BROWSERSTACK_OBSERVABILITY_DEBUG === "true" || process.env.BROWSERSTACK_OBSERVABILITY_DEBUG === "1") {
25-
logger.info(`[ OBSERVABILITY ] ${text}`);
26+
logger.info(`[ ${TEST_REPORTING_ANALYTICS} ] ${text}`);
2627
}
2728
if(shouldReport) {
2829
CrashReporter.getInstance().uploadCrashReport(text, throwable ? throwable && throwable.stack : null);

bin/helpers/utils.js

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ exports.validateBstackJson = (bsConfigPath) => {
3333
try {
3434
logger.info(`Reading config from ${bsConfigPath}`);
3535
let bsConfig = require(bsConfigPath);
36+
bsConfig = exports.normalizeTestReportingConfig(bsConfig);
3637
resolve(bsConfig);
3738
} catch (e) {
3839
reject(
@@ -492,7 +493,6 @@ exports.setNodeVersion = (bsConfig, args) => {
492493
// specs can be passed via command line args as a string
493494
// command line args takes precedence over config
494495
exports.setUserSpecs = (bsConfig, args) => {
495-
496496
if(o11yHelpers.isBrowserstackInfra() && o11yHelpers.isTestObservabilitySession() && o11yHelpers.shouldReRunObservabilityTests()) {
497497
bsConfig.run_settings.specs = process.env.BROWSERSTACK_RERUN_TESTS;
498498
return;
@@ -1499,7 +1499,6 @@ exports.splitStringByCharButIgnoreIfWithinARange = (str, splitChar, leftLimiter,
14991499

15001500
// blindly send other passed configs with run_settings and handle at backend
15011501
exports.setOtherConfigs = (bsConfig, args) => {
1502-
15031502
if(o11yHelpers.isTestObservabilitySession() && process.env.BS_TESTOPS_JWT) {
15041503
bsConfig["run_settings"]["reporter"] = TEST_OBSERVABILITY_REPORTER;
15051504
return;
@@ -1519,7 +1518,15 @@ exports.setOtherConfigs = (bsConfig, args) => {
15191518
exports.readBsConfigJSON = (bsConfigPath) => {
15201519
try {
15211520
fs.accessSync(bsConfigPath, fs.constants.R_OK);
1522-
return fs.readFileSync(bsConfigPath, 'utf-8');
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+
}
15231530
} catch (err) {
15241531
return null;
15251532
}
@@ -1804,3 +1811,25 @@ exports.decodeJWTToken = (token) => {
18041811
return undefined;
18051812
}
18061813
}
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+
}

bin/testObservability/crashReporter/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ const HttpsProxyAgent = require('https-proxy-agent');
77
const logger = require("../../helpers/logger").winstonLogger;
88
const utils = require('../../helpers/utils');
99

10-
const { API_URL, consoleHolder } = require('../helper/constants');
10+
const { API_URL, consoleHolder, TEST_REPORTING_ANALYTICS } = require('../helper/constants');
1111

1212
/* Below global methods are added here to remove cyclic dependency with helper.js, refactor later */
1313
const httpsKeepAliveAgent = new https.Agent({
@@ -19,7 +19,7 @@ const httpsKeepAliveAgent = new https.Agent({
1919

2020
const debug = (text) => {
2121
if (process.env.BROWSERSTACK_OBSERVABILITY_DEBUG === "true" || process.env.BROWSERSTACK_OBSERVABILITY_DEBUG === "1") {
22-
logger.info(`[ OBSERVABILITY ] ${text}`);
22+
logger.info(`[ ${TEST_REPORTING_ANALYTICS} ] ${text}`);
2323
}
2424
}
2525

bin/testObservability/helper/constants.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,15 @@ exports.IPC_EVENTS = {
1616

1717
exports.OBSERVABILITY_ENV_VARS = [
1818
"BROWSERSTACK_TEST_OBSERVABILITY",
19+
"BROWSERSTACK_TEST_REPORTING",
1920
"BROWSERSTACK_AUTOMATION",
2021
"BS_TESTOPS_BUILD_COMPLETED",
2122
"BS_TESTOPS_JWT",
2223
"BS_TESTOPS_BUILD_HASHED_ID",
2324
"BS_TESTOPS_ALLOW_SCREENSHOTS",
2425
"OBSERVABILITY_LAUNCH_SDK_VERSION",
2526
"BROWSERSTACK_OBSERVABILITY_DEBUG",
27+
"BROWSERSTACK_TEST_REPORTING_DEBUG",
2628
"OBS_CRASH_REPORTING_USERNAME",
2729
"OBS_CRASH_REPORTING_ACCESS_KEY",
2830
"OBS_CRASH_REPORTING_BS_CONFIG_PATH",
@@ -34,3 +36,5 @@ exports.TEST_OBSERVABILITY_REPORTER = 'browserstack-cypress-cli/bin/testObservab
3436
exports.TEST_OBSERVABILITY_REPORTER_LOCAL = path.join(__dirname, '..', 'reporter');
3537

3638
exports.PENDING_QUEUES_FILE = `pending_queues_${process.pid}.json`;
39+
40+
exports.TEST_REPORTING_ANALYTICS = 'TEST REPORTING AND ANALYTICS';

bin/testObservability/helper/helper.js

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ const GLOBAL_MODULE_PATH = execSync('npm root -g').toString().trim();
2727
const { name, version } = require('../../../package.json');
2828

2929
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');
3131

3232
const ALLOWED_MODULES = [
3333
'cypress/package.json',
@@ -43,13 +43,13 @@ exports.pending_test_uploads = {
4343
exports.debugOnConsole = (text) => {
4444
if ((process.env.BROWSERSTACK_OBSERVABILITY_DEBUG + '') === "true" ||
4545
(process.env.BROWSERSTACK_OBSERVABILITY_DEBUG + '') === "1") {
46-
consoleHolder.log(`[ OBSERVABILITY ] ${text}`);
46+
consoleHolder.log(`[ ${TEST_REPORTING_ANALYTICS} ] ${text}`);
4747
}
4848
}
4949

5050
exports.debug = (text, shouldReport = false, throwable = null) => {
5151
if (process.env.BROWSERSTACK_OBSERVABILITY_DEBUG === "true" || process.env.BROWSERSTACK_OBSERVABILITY_DEBUG === "1") {
52-
logger.info(`[ OBSERVABILITY ] ${text}`);
52+
logger.info(`[ ${TEST_REPORTING_ANALYTICS} ] ${text}`);
5353
}
5454
if(shouldReport) {
5555
CrashReporter.getInstance().uploadCrashReport(text, throwable ? throwable && throwable.stack : null);
@@ -105,7 +105,7 @@ exports.printBuildLink = async (shouldStopSession, exitCode = null) => {
105105
&& process.env.BS_TESTOPS_BUILD_HASHED_ID != "null"
106106
&& process.env.BS_TESTOPS_BUILD_HASHED_ID != "undefined") {
107107
console.log();
108-
logger.info(`Visit https://observability.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`);
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`);
109109
}
110110
} catch(err) {
111111
exports.debug('Build Not Found');
@@ -514,9 +514,9 @@ exports.batchAndPostEvents = async (eventUrl, kind, data) => {
514514
} catch(error) {
515515
exports.debugOnConsole(`[Request Error] Error in sending request ${util.format(error)}`);
516516
if (error.response) {
517-
exports.debug(`EXCEPTION IN ${kind} REQUEST TO TEST OBSERVABILITY : ${error.response.status} ${error.response.statusText} ${JSON.stringify(error.response.data)}`, true, error);
517+
exports.debug(`EXCEPTION IN ${kind} REQUEST TO ${TEST_REPORTING_ANALYTICS} : ${error.response.status} ${error.response.statusText} ${JSON.stringify(error.response.data)}`, true, error);
518518
} else {
519-
exports.debug(`EXCEPTION IN ${kind} REQUEST TO TEST OBSERVABILITY : ${error.message || error}`, true, error);
519+
exports.debug(`EXCEPTION IN ${kind} REQUEST TO ${TEST_REPORTING_ANALYTICS} : ${error.message || error}`, true, error);
520520
}
521521
exports.pending_test_uploads.count = Math.max(0,exports.pending_test_uploads.count - data.length);
522522
}
@@ -540,7 +540,7 @@ exports.uploadEventData = async (eventData, run=0) => {
540540

541541
if (process.env.BS_TESTOPS_BUILD_COMPLETED === "true") {
542542
if(process.env.BS_TESTOPS_JWT == "null") {
543-
exports.debug(`EXCEPTION IN ${log_tag} REQUEST TO TEST OBSERVABILITY : missing authentication token`);
543+
exports.debug(`EXCEPTION IN ${log_tag} REQUEST TO ${TEST_REPORTING_ANALYTICS}: missing authentication token`);
544544
exports.pending_test_uploads.count = Math.max(0,exports.pending_test_uploads.count-1);
545545
return {
546546
status: 'error',
@@ -585,9 +585,9 @@ exports.uploadEventData = async (eventData, run=0) => {
585585
} catch(error) {
586586
exports.debugOnConsole(`[Request Error] Error in sending request ${util.format(error)}`);
587587
if (error.response) {
588-
exports.debug(`EXCEPTION IN ${event_api_url !== requestQueueHandler.eventUrl ? log_tag : 'Batch-Queue'} REQUEST TO TEST OBSERVABILITY : ${error.response.status} ${error.response.statusText} ${JSON.stringify(error.response.data)}`, true, error);
588+
exports.debug(`EXCEPTION IN ${event_api_url !== exports.requestQueueHandler.eventUrl ? log_tag : 'Batch-Queue'} REQUEST TO ${TEST_REPORTING_ANALYTICS} : ${error.response.status} ${error.response.statusText} ${JSON.stringify(error.response.data)}`, true, error);
589589
} else {
590-
exports.debug(`EXCEPTION IN ${event_api_url !== requestQueueHandler.eventUrl ? log_tag : 'Batch-Queue'} REQUEST TO TEST OBSERVABILITY : ${error.message || error}`, true, error);
590+
exports.debug(`EXCEPTION IN ${event_api_url !== exports.requestQueueHandler.eventUrl ? log_tag : 'Batch-Queue'} REQUEST TO ${TEST_REPORTING_ANALYTICS} : ${error.message || error}`, true, error);
591591
}
592592
exports.pending_test_uploads.count = Math.max(0,exports.pending_test_uploads.count - (event_api_url === 'api/v1/event' ? 1 : data.length));
593593
return {
@@ -597,7 +597,7 @@ exports.uploadEventData = async (eventData, run=0) => {
597597
}
598598
}
599599
} else if (run >= 5) {
600-
exports.debug(`EXCEPTION IN ${log_tag} REQUEST TO TEST OBSERVABILITY : Build Start is not completed and ${log_tag} retry runs exceeded`);
600+
exports.debug(`EXCEPTION IN ${log_tag} REQUEST TO ${TEST_REPORTING_ANALYTICS} : Build Start is not completed and ${log_tag} retry runs exceeded`);
601601
if(process.env.BS_TESTOPS_JWT != "null") exports.pending_test_uploads.count = Math.max(0,exports.pending_test_uploads.count-1);
602602
return {
603603
status: 'error',
@@ -663,7 +663,7 @@ exports.shouldReRunObservabilityTests = () => {
663663
exports.stopBuildUpstream = async () => {
664664
if (process.env.BS_TESTOPS_BUILD_COMPLETED === "true") {
665665
if(process.env.BS_TESTOPS_JWT == "null" || process.env.BS_TESTOPS_BUILD_HASHED_ID == "null") {
666-
exports.debug('EXCEPTION IN stopBuildUpstream REQUEST TO TEST OBSERVABILITY : Missing authentication token');
666+
exports.debug(`EXCEPTION IN stopBuildUpstream REQUEST TO ${TEST_REPORTING_ANALYTICS} : Missing authentication token`);
667667
return {
668668
status: 'error',
669669
message: 'Token/buildID is undefined, build creation might have failed'
@@ -693,9 +693,9 @@ exports.stopBuildUpstream = async () => {
693693
}
694694
} catch(error) {
695695
if (error.response) {
696-
exports.debug(`EXCEPTION IN stopBuildUpstream REQUEST TO TEST OBSERVABILITY : ${error.response.status} ${error.response.statusText} ${JSON.stringify(error.response.data)}`, true, error);
696+
exports.debug(`EXCEPTION IN stopBuildUpstream REQUEST TO ${TEST_REPORTING_ANALYTICS} : ${error.response.status} ${error.response.statusText} ${JSON.stringify(error.response.data)}`, true, error);
697697
} else {
698-
exports.debug(`EXCEPTION IN stopBuildUpstream REQUEST TO TEST OBSERVABILITY : ${error.message || error}`, true, error);
698+
exports.debug(`EXCEPTION IN stopBuildUpstream REQUEST TO ${TEST_REPORTING_ANALYTICS} : ${error.message || error}`, true, error);
699699
}
700700
return {
701701
status: 'error',

bin/testObservability/reporter/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ const Mocha = requireModule('mocha');
1212
const Runnable = require('mocha/lib/runnable'); // need to handle as this isn't present in older mocha versions
1313
const { v4: uuidv4 } = require('uuid');
1414

15-
const { IPC_EVENTS } = require('../helper/constants');
15+
const { IPC_EVENTS, TEST_REPORTING_ANALYTICS } = require('../helper/constants');
1616
const { startIPCServer } = require('../plugin/ipcServer');
1717

1818
const HOOK_TYPES_MAP = {
@@ -519,7 +519,7 @@ class MyReporter {
519519
});
520520
}
521521
} catch(error) {
522-
debug(`Exception in uploading log data to Observability with error : ${error}`, true, error);
522+
debug(`Exception in uploading log data to ${TEST_REPORTING_ANALYTICS} with error : ${error}`, true, error);
523523
}
524524
}
525525

0 commit comments

Comments
 (0)