Skip to content

Commit 5b94ffb

Browse files
Merge pull request #989 from browserstack/SDK-3571-olly-artifact-changes
Sdk 3571 olly artifact changes
2 parents 4da13ba + 3de7ad1 commit 5b94ffb

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');
@@ -513,9 +513,9 @@ exports.batchAndPostEvents = async (eventUrl, kind, data) => {
513513
} catch(error) {
514514
exports.debugOnConsole(`[Request Error] Error in sending request ${util.format(error)}`);
515515
if (error.response) {
516-
exports.debug(`EXCEPTION IN ${kind} REQUEST TO TEST OBSERVABILITY : ${error.response.status} ${error.response.statusText} ${JSON.stringify(error.response.data)}`, true, error);
516+
exports.debug(`EXCEPTION IN ${kind} REQUEST TO ${TEST_REPORTING_ANALYTICS} : ${error.response.status} ${error.response.statusText} ${JSON.stringify(error.response.data)}`, true, error);
517517
} else {
518-
exports.debug(`EXCEPTION IN ${kind} REQUEST TO TEST OBSERVABILITY : ${error.message || error}`, true, error);
518+
exports.debug(`EXCEPTION IN ${kind} REQUEST TO ${TEST_REPORTING_ANALYTICS} : ${error.message || error}`, true, error);
519519
}
520520
exports.pending_test_uploads.count = Math.max(0,exports.pending_test_uploads.count - data.length);
521521
}
@@ -541,7 +541,7 @@ exports.uploadEventData = async (eventData, run=0) => {
541541

542542
if (process.env.BS_TESTOPS_BUILD_COMPLETED === "true") {
543543
if(process.env.BS_TESTOPS_JWT == "null") {
544-
exports.debug(`EXCEPTION IN ${log_tag} REQUEST TO TEST OBSERVABILITY : missing authentication token`);
544+
exports.debug(`EXCEPTION IN ${log_tag} REQUEST TO ${TEST_REPORTING_ANALYTICS}: missing authentication token`);
545545
exports.pending_test_uploads.count = Math.max(0,exports.pending_test_uploads.count-1);
546546
return {
547547
status: 'error',
@@ -586,9 +586,9 @@ exports.uploadEventData = async (eventData, run=0) => {
586586
} catch(error) {
587587
exports.debugOnConsole(`[Request Error] Error in sending request ${util.format(error)}`);
588588
if (error.response) {
589-
exports.debug(`EXCEPTION IN ${event_api_url !== exports.requestQueueHandler.eventUrl ? log_tag : 'Batch-Queue'} REQUEST TO TEST OBSERVABILITY : ${error.response.status} ${error.response.statusText} ${JSON.stringify(error.response.data)}`, true, error);
589+
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);
590590
} else {
591-
exports.debug(`EXCEPTION IN ${event_api_url !== exports.requestQueueHandler.eventUrl ? log_tag : 'Batch-Queue'} REQUEST TO TEST OBSERVABILITY : ${error.message || error}`, true, error);
591+
exports.debug(`EXCEPTION IN ${event_api_url !== exports.requestQueueHandler.eventUrl ? log_tag : 'Batch-Queue'} REQUEST TO ${TEST_REPORTING_ANALYTICS} : ${error.message || error}`, true, error);
592592
}
593593
exports.pending_test_uploads.count = Math.max(0,exports.pending_test_uploads.count - (event_api_url === 'api/v1/event' ? 1 : data.length));
594594
return {
@@ -598,7 +598,7 @@ exports.uploadEventData = async (eventData, run=0) => {
598598
}
599599
}
600600
} else if (run >= 5) {
601-
exports.debug(`EXCEPTION IN ${log_tag} REQUEST TO TEST OBSERVABILITY : Build Start is not completed and ${log_tag} retry runs exceeded`);
601+
exports.debug(`EXCEPTION IN ${log_tag} REQUEST TO ${TEST_REPORTING_ANALYTICS} : Build Start is not completed and ${log_tag} retry runs exceeded`);
602602
if(process.env.BS_TESTOPS_JWT != "null") exports.pending_test_uploads.count = Math.max(0,exports.pending_test_uploads.count-1);
603603
return {
604604
status: 'error',
@@ -664,7 +664,7 @@ exports.shouldReRunObservabilityTests = () => {
664664
exports.stopBuildUpstream = async () => {
665665
if (process.env.BS_TESTOPS_BUILD_COMPLETED === "true") {
666666
if(process.env.BS_TESTOPS_JWT == "null" || process.env.BS_TESTOPS_BUILD_HASHED_ID == "null") {
667-
exports.debug('EXCEPTION IN stopBuildUpstream REQUEST TO TEST OBSERVABILITY : Missing authentication token');
667+
exports.debug(`EXCEPTION IN stopBuildUpstream REQUEST TO ${TEST_REPORTING_ANALYTICS} : Missing authentication token`);
668668
return {
669669
status: 'error',
670670
message: 'Token/buildID is undefined, build creation might have failed'
@@ -694,9 +694,9 @@ exports.stopBuildUpstream = async () => {
694694
}
695695
} catch(error) {
696696
if (error.response) {
697-
exports.debug(`EXCEPTION IN stopBuildUpstream REQUEST TO TEST OBSERVABILITY : ${error.response.status} ${error.response.statusText} ${JSON.stringify(error.response.data)}`, true, error);
697+
exports.debug(`EXCEPTION IN stopBuildUpstream REQUEST TO ${TEST_REPORTING_ANALYTICS} : ${error.response.status} ${error.response.statusText} ${JSON.stringify(error.response.data)}`, true, error);
698698
} else {
699-
exports.debug(`EXCEPTION IN stopBuildUpstream REQUEST TO TEST OBSERVABILITY : ${error.message || error}`, true, error);
699+
exports.debug(`EXCEPTION IN stopBuildUpstream REQUEST TO ${TEST_REPORTING_ANALYTICS} : ${error.message || error}`, true, error);
700700
}
701701
return {
702702
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 = {
@@ -511,7 +511,7 @@ class MyReporter {
511511
});
512512
}
513513
} catch(error) {
514-
debug(`Exception in uploading log data to Observability with error : ${error}`, true, error);
514+
debug(`Exception in uploading log data to ${TEST_REPORTING_ANALYTICS} with error : ${error}`, true, error);
515515
}
516516
}
517517

0 commit comments

Comments
 (0)