Skip to content

Commit e09cbce

Browse files
feat: Integrate orchestration data retrieval into test observability and refactor getBuildStartData method (#43)
* feat: Implement Nightwatch Test Orchestration Module - Added helpers.js for utility functions related to test orchestration. - Created index.js to serve as the main entry point for the orchestration module. - Introduced orchestrationUtils.js for managing orchestration settings and operations. - Developed requestUtils.js for handling API requests to the BrowserStack orchestration API. - Implemented testOrchestrationHandler.js to manage test orchestration operations. - Added testOrchestrationIntegration.js for integrating orchestration with Nightwatch. - Created testOrderingServer.js to handle communication with the BrowserStack server for test ordering. - Updated requestHelper.js to improve error handling for API requests. * feat: Enhance test file collection and orchestration logic with improved glob pattern matching * feat: Refactor test orchestration logic to apply specific feature path for cucumber tests * feat: Update cucumber feature path for API tests in Nightwatch globals * feat: Update cucumber feature path handling to use ordered files * feat: Add framework name to build data payload in OrchestrationUtils * feat: Remove unused helper functions and debug logs from orchestration files * feat: Update framework name comment in build data payload and enhance error logging in RequestUtils * feat: Remove unused orchestration files and refactor helper functions for improved Git metadata handling * style: eslint update * feat: Remove framework name from build data payload in OrchestrationUtils * feat: Enhance build details extraction by adding observability options * feat: Add test observability options to project and build name retrieval * feat: Enhance test orchestration by adding observability session check and improve git metadata handling * feat: Add test observability session check to build data collection in orchestration * feat: Refactor test orchestration logic to improve readability and maintainability * feat: Validate smart selection mode in run smart selection settings * fix: Corrected base branch retrieval by updating the string replacement for origin reference * refactor: Change log level from info to debug for test orchestration messages * feat: Integrate orchestration data retrieval into test observability and refactor getBuildStartData method * fix: Correct syntax by adding missing semicolon in testObservability.js * fix: Update test_orchestration data retrieval to use parent settings * fix: Enhance feature branch validation in OrchestrationUtils * fix: Correct base branch retrieval by adjusting symbolic ref path * fix: Validate repository URL to ensure it is not empty or whitespace * fix: Enhance feature branch retrieval by adding null and type checks * fix: eslint fix
1 parent 0bfd4ff commit e09cbce

File tree

3 files changed

+21
-11
lines changed

3 files changed

+21
-11
lines changed

src/testObservability.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ const {makeRequest} = require('./utils/requestHelper');
88
const CrashReporter = require('./utils/crashReporter');
99
const Logger = require('./utils/logger');
1010
const {API_URL, TAKE_SCREENSHOT_REGEX} = require('./utils/constants');
11+
const OrchestrationUtils = require('./testorchestration/orchestrationUtils');
1112
const hooksMap = {};
1213

1314
class TestObservability {
@@ -111,7 +112,8 @@ class TestObservability {
111112
frameworkName: helper.getFrameworkName(this._testRunner),
112113
frameworkVersion: helper.getPackageVersion('nightwatch'),
113114
sdkVersion: helper.getAgentVersion()
114-
}
115+
},
116+
test_orchestration: this.getTestOrchestrationBuildStartData(this._parentSettings)
115117
};
116118

117119
const config = {
@@ -151,6 +153,11 @@ class TestObservability {
151153
process.env.BROWSERSTACK_TEST_REPORTING = false;
152154
}
153155
}
156+
getTestOrchestrationBuildStartData(settings) {
157+
const orchestrationUtils = OrchestrationUtils.getInstance(settings);
158+
159+
return orchestrationUtils.getBuildStartData();
160+
}
154161

155162
async stopBuildUpstream () {
156163
if (!process.env.BS_TESTOPS_BUILD_COMPLETED) {

src/testorchestration/orchestrationUtils.js

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ const path = require('path');
22
const fs = require('fs');
33
const {tmpdir} = require('os');
44
const Logger = require('../utils/logger');
5-
const {getHostInfo} = require('../utils/helper');
65
const RequestUtils = require('./requestUtils');
76
const helper = require('../utils/helper');
87
// Constants
@@ -307,12 +306,16 @@ class OrchestrationUtils {
307306

308307
const getFeatureBranch = (name, repoInfo) => {
309308
// 1. Check in environment variable map
310-
if (featureBranchEnvMap[name]) {
311-
return featureBranchEnvMap[name];
309+
if (featureBranchEnvMap && featureBranchEnvMap[name]) {
310+
const val = featureBranchEnvMap[name];
311+
312+
return typeof val === 'string' ? val.trim() : val;
312313
}
313314
// 2. Check in repo_info
314-
if (repoInfo.featureBranch) {
315-
return repoInfo.featureBranch;
315+
if (repoInfo && repoInfo.featureBranch) {
316+
const val = repoInfo.featureBranch;
317+
318+
return typeof val === 'string' ? val.trim() : val;
316319
}
317320

318321
return null;
@@ -327,7 +330,7 @@ class OrchestrationUtils {
327330
continue;
328331
}
329332

330-
if (!repoInfo.url) {
333+
if (!repoInfo.url || String(repoInfo.url).trim() === '') {
331334
this.logger.warn(`Repository URL is missing for source '${name}': ${JSON.stringify(repoInfo)}`);
332335
continue;
333336
}
@@ -348,7 +351,7 @@ class OrchestrationUtils {
348351
repoInfoCopy.name = name;
349352
repoInfoCopy.featureBranch = getFeatureBranch(name, repoInfo);
350353

351-
if (!repoInfoCopy.featureBranch) {
354+
if (!repoInfoCopy.featureBranch || repoInfoCopy.featureBranch === '') {
352355
this.logger.warn(`Feature branch not specified for source '${name}': ${JSON.stringify(repoInfo)}`);
353356
continue;
354357
}
@@ -414,7 +417,7 @@ class OrchestrationUtils {
414417
/**
415418
* Get build start data
416419
*/
417-
getBuildStartData(config) {
420+
getBuildStartData() {
418421
const testOrchestrationData = {};
419422

420423
testOrchestrationData['run_smart_selection'] = {
@@ -442,7 +445,7 @@ class OrchestrationUtils {
442445
buildRunIdentifier: this.getBuildIdentifier(),
443446
nodeIndex: parseInt(process.env.BROWSERSTACK_NODE_INDEX || '0', 10),
444447
totalNodes: parseInt(process.env.BROWSERSTACK_TOTAL_NODE_COUNT || '1', 10),
445-
hostInfo: getHostInfo()
448+
hostInfo: helper.getHostInfo()
446449
};
447450

448451
this.logger.debug(`[collectBuildData] Sending build data payload: ${JSON.stringify(payload)}`);

src/utils/helper.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1057,7 +1057,7 @@ function getBaseBranch() {
10571057
try {
10581058
const originHeadOutput = execSync('git symbolic-ref refs/remotes/origin/HEAD').toString().trim();
10591059
if (originHeadOutput.startsWith('refs/remotes/origin/')) {
1060-
return originHeadOutput.replace('refs/remotes/origin/', '');
1060+
return originHeadOutput.replace('refs/remotes/', '');
10611061
}
10621062
} catch (e) {
10631063
// Symbolic ref might not exist

0 commit comments

Comments
 (0)