Skip to content

Commit c352cad

Browse files
committed
HST-2201: fix: spec path issue when running cli on windows
1 parent 55684cb commit c352cad

File tree

1 file changed

+24
-22
lines changed

1 file changed

+24
-22
lines changed

Diff for: bin/helpers/utils.js

+24-22
Original file line numberDiff line numberDiff line change
@@ -330,8 +330,8 @@ exports.setCypressConfigFilename = (bsConfig, args) => {
330330

331331
exports.setCypressTestSuiteType = (bsConfig) => {
332332
for (const possibleCypressFileName of Constants.CYPRESS_CONFIG_FILE_NAMES) {
333-
if (bsConfig.run_settings.cypressConfigFilePath &&
334-
typeof(bsConfig.run_settings.cypressConfigFilePath) === 'string' &&
333+
if (bsConfig.run_settings.cypressConfigFilePath &&
334+
typeof(bsConfig.run_settings.cypressConfigFilePath) === 'string' &&
335335
(path.extname(bsConfig.run_settings.cypressConfigFilePath) == path.extname(possibleCypressFileName) || bsConfig.run_settings.cypressConfigFilePath.endsWith(possibleCypressFileName))) {
336336
bsConfig.run_settings.cypressTestSuiteType = Constants.CYPRESS_CONFIG_FILE_MAPPING[possibleCypressFileName].type;
337337
break;
@@ -347,11 +347,11 @@ exports.setCypressTestSuiteType = (bsConfig) => {
347347

348348
exports.setCypressNpmDependency = (bsConfig) => {
349349
const runSettings = bsConfig.run_settings;
350-
if (runSettings.npm_dependencies !== undefined &&
350+
if (runSettings.npm_dependencies !== undefined &&
351351
Object.keys(runSettings.npm_dependencies).length !== 0 &&
352352
typeof runSettings.npm_dependencies === 'object') {
353353
if (!("cypress" in runSettings.npm_dependencies) && runSettings.cypressTestSuiteType === Constants.CYPRESS_V10_AND_ABOVE_TYPE) {
354-
logger.warn("Missing cypress not found in npm_dependencies");
354+
logger.warn("Missing cypress not found in npm_dependencies");
355355
if("cypress_version" in runSettings){
356356
runSettings.npm_dependencies.cypress = `^${runSettings.cypress_version.toString().split(".")[0]}`;
357357
} else if (runSettings.cypressTestSuiteType === Constants.CYPRESS_V10_AND_ABOVE_TYPE) {
@@ -386,13 +386,13 @@ exports.setGeolocation = (bsConfig, args) => {
386386
}
387387

388388
exports.isSpecTimeoutArgPassed = () => {
389-
return this.searchForOption('--spec-timeout') || this.searchForOption('-t');
389+
return this.searchForOption('--spec-timeout') || this.searchForOption('-t');
390390
}
391391
exports.setSpecTimeout = (bsConfig, args) => {
392392
let specTimeout = null;
393393
if(this.isSpecTimeoutArgPassed()) {
394-
if(!this.isUndefined(args.specTimeout)) {
395-
specTimeout = args.specTimeout;
394+
if(!this.isUndefined(args.specTimeout)) {
395+
specTimeout = args.specTimeout;
396396
} else {
397397
specTimeout = 'undefined'
398398
}
@@ -410,7 +410,7 @@ exports.setTimezone = (bsConfig, args) => {
410410
let newTimezone;
411411
if(this.isNotUndefined(timezone)) {
412412
if(this.isValidTimezone(timezone)){
413-
newTimezone = timezone;
413+
newTimezone = timezone;
414414
} else {
415415
logger.error(`Invalid timezone = ${timezone}`);
416416
syncCliLogger.info(chalk.red(Constants.userMessages.INVALID_TIMEZONE));
@@ -443,11 +443,11 @@ exports.setProjectId = (bsConfig, args, cypressConfigFile) => {
443443
} else if(!this.isUndefined(process.env.CYPRESS_PROJECT_ID)) {
444444
return process.env.CYPRESS_PROJECT_ID;
445445
} else if(!this.isUndefined(bsConfig.run_settings["projectId"])) {
446-
return bsConfig.run_settings["projectId"];
446+
return bsConfig.run_settings["projectId"];
447447
} else {
448448
// ignore reading cypressconfig if enforce_settings is passed
449449
if (this.isUndefinedOrFalse(bsConfig.run_settings.enforce_settings) && !this.isUndefined(cypressConfigFile) && !this.isUndefined(cypressConfigFile["projectId"])) {
450-
return cypressConfigFile["projectId"];
450+
return cypressConfigFile["projectId"];
451451
}
452452
}
453453
}
@@ -497,7 +497,7 @@ exports.setUserSpecs = (bsConfig, args) => {
497497
bsConfig.run_settings.specs = process.env.BROWSERSTACK_RERUN_TESTS;
498498
return;
499499
}
500-
500+
501501
let bsConfigSpecs = bsConfig.run_settings.specs;
502502

503503
if (!this.isUndefined(args.specs)) {
@@ -1167,7 +1167,7 @@ exports.getNumberOfSpecFiles = (bsConfig, args, cypressConfig, turboScaleSession
11671167
let files
11681168
if (globSearchPattern) {
11691169
let fileMatchedWithBstackSpecPattern = glob.sync(globSearchPattern, {
1170-
cwd: bsConfig.run_settings.cypressProjectDir, matchBase: true, ignore: ignoreFiles
1170+
cwd: bsConfig.run_settings.cypressProjectDir, matchBase: true, ignore: ignoreFiles
11711171
});
11721172
fileMatchedWithBstackSpecPattern = fileMatchedWithBstackSpecPattern.map((file) => path.resolve(bsConfig.run_settings.cypressProjectDir, file))
11731173

@@ -1184,12 +1184,14 @@ exports.getNumberOfSpecFiles = (bsConfig, args, cypressConfig, turboScaleSession
11841184
const directory = path.join(path.dirname(configFilePath), '/');
11851185
// remove unwanted path prefix for turboscale
11861186
files = files.map((x) => { return path.join('', x.split(directory)[1]) })
1187-
// setting specs for turboScale as we don't have patched API for turboscale so we will rely on info from CLI
1188-
bsConfig.run_settings.specs = files;
11891187
} else {
11901188
files = files.map((x) => { return path.join(testFolderPath, x.split(testFolderPath)[1]) })
1191-
bsConfig.run_settings.specs = files;
11921189
}
1190+
1191+
// sanitize spec list as CLI might be running on windows
1192+
files = files.map((x) => { return x.replaceAll("\\", "/") })
1193+
// setting specs for turboScale as we don't have patched API for turboscale so we will rely on info from CLI
1194+
bsConfig.run_settings.specs = files;
11931195
}
11941196
return files;
11951197
};
@@ -1453,12 +1455,12 @@ exports.setEnforceSettingsConfig = (bsConfig, args) => {
14531455
/**
14541456
* Splits a string by a specified splitChar.
14551457
* If leftLimiter and rightLimiter are specified then string won't be splitted if the splitChar is within the range
1456-
*
1458+
*
14571459
* @param {String} str - the string that needs to be splitted
14581460
* @param {String} splitChar - the split string/char from which the string will be splited
14591461
* @param {String} [leftLimiter] - the starting string/char of the range
14601462
* @param {String} [rightLimiter] - the ending string/char of the range
1461-
*
1463+
*
14621464
* @example Example usage of splitStringByCharButIgnoreIfWithinARange.
14631465
* // returns ["folder/A/B", "folder/{C,D}/E"]
14641466
* utils.splitStringByCharButIgnoreIfWithinARange("folder/A/B,folder/{C,D}/E", ",", "{", "}");
@@ -1567,7 +1569,7 @@ exports.formatRequest = (err, resp, body) => {
15671569

15681570
exports.setDebugMode = (args) => {
15691571
if(args.cliDebug || String(process.env.DEBUG).toLowerCase() === 'true'){
1570-
args.cliDebug ?
1572+
args.cliDebug ?
15711573
logger.info("CLI is running with the --cli-debug argument. Running CLI in the debug mode...") :
15721574
logger.info("DEBUG environment variable set to 'true'. Running CLI in the debug mode...") ;
15731575
transports.loggerConsole.level = 'debug';
@@ -1580,7 +1582,7 @@ exports.setDebugMode = (args) => {
15801582

15811583
exports.stopBrowserStackBuild = async (bsConfig, args, buildId, rawArgs, buildReportData = null) => {
15821584
let that = this;
1583-
1585+
15841586
let url = config.buildStopUrl + buildId;
15851587
let options = {
15861588
url: url,
@@ -1607,10 +1609,10 @@ exports.stopBrowserStackBuild = async (bsConfig, args, buildId, rawArgs, buildRe
16071609
let messageType = null;
16081610
let errorCode = null;
16091611
let build = null;
1610-
1612+
16111613
try {
16121614
const response = await axios.post(options.url, {}, axiosConfig);
1613-
1615+
16141616
build = response.data;
16151617
if (response.status == 299) {
16161618
messageType = Constants.messageTypes.INFO;
@@ -1780,7 +1782,7 @@ exports.getMajorVersion = (version) => {
17801782
} catch(error) {
17811783
logger.debug(`Some Error occurred while fetching major version of ${version}. Returning null. Error Details: ${error}`)
17821784
return null;
1783-
}
1785+
}
17841786
}
17851787

17861788
const base64UrlDecode = (str) => {

0 commit comments

Comments
 (0)