Skip to content

Commit a3da2ff

Browse files
committed
added changes for spec level timeout
1 parent b218868 commit a3da2ff

File tree

5 files changed

+68
-4
lines changed

5 files changed

+68
-4
lines changed

bin/commands/runs.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,9 @@ module.exports = function run(args, rawArgs) {
5353
// set cypress geo location
5454
utils.setGeolocation(bsConfig, args);
5555

56+
// set spec timeout
57+
utils.setSpecTimeout(bsConfig, args);
58+
5659
// accept the specs list from command line if provided
5760
utils.setUserSpecs(bsConfig, args);
5861

bin/helpers/capabilityHelper.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,20 @@ const validate = (bsConfig, args) => {
219219
addCypressZipStartLocation(bsConfig.run_settings);
220220
}
221221

222+
if(!Utils.isUndefined(bsConfig.run_settings.spec_timeout)) {
223+
if(Utils.isPositiveInteger(bsConfig.run_settings.spec_timeout.toString().trim())) {
224+
if(Number(bsConfig.run_settings.spec_timeout) > Constants.SPEC_TIMEOUT_LIMIT) {
225+
reject(Constants.validationMessages.SPEC_TIMEOUT_LIMIT_ERROR)
226+
} else {
227+
logger.info(Constants.userMessages.SPEC_LIMIT_SUCCESS_MESSAGE.replace("<x>", bsConfig.run_settings.spec_timeout));
228+
}
229+
} else {
230+
logger.warn(Constants.userMessages.SPEC_LIMIT_WARNING)
231+
}
232+
} else {
233+
logger.warn(Constants.validationMessages.SPEC_TIMEOUT_NOT_PASSED_ERROR);
234+
}
235+
222236
resolve(cypressJson);
223237
});
224238
}

bin/helpers/constants.js

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,9 @@ const userMessages = {
6262
DOWNLOAD_BUILD_ARTIFACTS_SUCCESS: "Your build artifact(s) have been successfully downloaded in '<user-path>/build_artifacts/<build-id>' directory",
6363
LATEST_SYNTAX_TO_ACTUAL_VERSION_MESSAGE: "Your build will run using Cypress <actualVersion> as you had specified <latestSyntaxVersion>.<frameworkUpgradeMessage> Read more about supported versions here: http://browserstack.com/docs/automate/cypress/supported-versions",
6464
PROCESS_KILL_MESSAGE: "Stopping the CLI and the execution of the build on BrowserStack",
65-
BUILD_FAILED_ERROR: "The above stacktrace has been thrown by Cypress when we tried to run your build. If your test suite requires npm dependencies then please specify them on browserstack.json. Read more at " + chalk.blueBright("https://www.browserstack.com/docs/automate/cypress/npm-packages") + ". Also, we recommend you to try running the build locally using ‘cypress run’ and if it works fine then please reach out to support at " + chalk.blueBright("https://www.browserstack.com/contact#technical-support")
65+
BUILD_FAILED_ERROR: "The above stacktrace has been thrown by Cypress when we tried to run your build. If your test suite requires npm dependencies then please specify them on browserstack.json. Read more at " + chalk.blueBright("https://www.browserstack.com/docs/automate/cypress/npm-packages") + ". Also, we recommend you to try running the build locally using ‘cypress run’ and if it works fine then please reach out to support at " + chalk.blueBright("https://www.browserstack.com/contact#technical-support"),
66+
SPEC_LIMIT_WARNING: "Value for the 'spec_timeout' key not in the 1-120 range. Going ahead with 30 mins as the default spec timeout. Read more about how to specify the option in https://browserstack.com/docs/automate/cypress/spec-timeout ",
67+
SPEC_LIMIT_SUCCESS_MESSAGE: "Spec timeout specified as <x> minutes. If any of your specs exceed the specified time limit, it would be forcibly killed by BrowserStack"
6668
};
6769

6870
const validationMessages = {
@@ -96,7 +98,9 @@ const validationMessages = {
9698
NOT_ALLOWED_GEO_LOCATION_AND_LOCAL_MODE: "IP Geolocation feature is not available in conjunction with BrowserStack Local.",
9799
HOME_DIRECTORY_NOT_FOUND: "Specified home directory could not be found. Please make sure the path of the home directory is correct.",
98100
HOME_DIRECTORY_NOT_A_DIRECTORY: "Specified home directory is not a directory. The home directory can only be a directory and not a file.",
99-
CYPRESS_CONFIG_FILE_NOT_PART_OF_HOME_DIRECTORY: "Could not find cypress.json within the specified home directory. Please make sure cypress.json resides within the home directory."
101+
CYPRESS_CONFIG_FILE_NOT_PART_OF_HOME_DIRECTORY: "Could not find cypress.json within the specified home directory. Please make sure cypress.json resides within the home directory.",
102+
SPEC_TIMEOUT_LIMIT_ERROR: "The maximum allowed value of 'spec_timeout' is 120. Read more on https://browserstack.com/docs/automate/cypress/spec-timeout ",
103+
SPEC_TIMEOUT_NOT_PASSED_ERROR: "'spec_timeout' key not specified. Going ahead with 30 mins as the default spec timeout. Read more about how to specify the option in https://browserstack.com/docs/automate/cypress/spec-timeout "
100104
};
101105

102106
const cliMessages = {
@@ -139,7 +143,8 @@ const cliMessages = {
139143
CONFIG_DESCRIPTION: "Set configuration values. Separate multiple values with a comma. The values set here override any values set in your configuration file.",
140144
REPORTER: "Specify the custom reporter to use",
141145
REPORTER_OPTIONS: "Specify reporter options for custom reporter",
142-
CYPRESS_GEO_LOCATION: "Enterprise feature to simulate website and mobile behavior from different locations."
146+
CYPRESS_GEO_LOCATION: "Enterprise feature to simulate website and mobile behavior from different locations.",
147+
SPEC_TIMEOUT: "Specify the value for assigning timeout to each spec"
143148
},
144149
COMMON: {
145150
DISABLE_USAGE_REPORTING: "Disable usage reporting",
@@ -233,6 +238,8 @@ const REDACTED = "[REDACTED]";
233238

234239
const REDACTED_AUTH =`auth: { "username": ${REDACTED}, "access_key": ${REDACTED} }`;
235240

241+
const SPEC_TIMEOUT_LIMIT = 120 // IN MINS
242+
236243
module.exports = Object.freeze({
237244
syncCLI,
238245
userMessages,
@@ -253,5 +260,6 @@ module.exports = Object.freeze({
253260
ERROR_EXIT_CODE,
254261
AUTH_REGEX,
255262
REDACTED_AUTH,
256-
BUILD_FAILED_EXIT_CODE
263+
BUILD_FAILED_EXIT_CODE,
264+
SPEC_TIMEOUT_LIMIT
257265
});

bin/helpers/utils.js

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,23 @@ exports.setGeolocation = (bsConfig, args) => {
309309
}
310310
}
311311

312+
exports.isSpecTimeoutArgPassed = () => {
313+
return this.searchForOption('--spec-timeout') || this.searchForOption('-st') || this.searchForOption('--st');
314+
}
315+
exports.setSpecTimeout = (bsConfig, args) => {
316+
let specTimeout = null;
317+
if(this.isSpecTimeoutArgPassed()) {
318+
if(!this.isUndefined(args.specTimeout)) {
319+
specTimeout = args.specTimeout;
320+
} else {
321+
specTimeout = 'undefined'
322+
}
323+
} else if (!this.isUndefined(bsConfig.run_settings.spec_timeout)) {
324+
specTimeout = bsConfig.run_settings.spec_timeout;
325+
}
326+
bsConfig.run_settings.spec_timeout = specTimeout;
327+
}
328+
312329
// specs can be passed from bstack configuration file
313330
// specs can be passed via command line args as a string
314331
// command line args takes precedence over config
@@ -389,10 +406,26 @@ exports.fixCommaSeparatedString = (string) => {
389406

390407
exports.isUndefined = value => (value === undefined || value === null);
391408

409+
exports.isPositiveInteger = (str) => {
410+
if (typeof str !== 'string') {
411+
return false;
412+
}
413+
414+
const num = Number(str);
415+
416+
if (Number.isInteger(num) && num > 0) {
417+
return true;
418+
}
419+
420+
return false;
421+
}
422+
392423
exports.isTrueString = value => (!this.isUndefined(value) && value.toString().toLowerCase() === 'true');
393424

394425
exports.isFloat = (value) => Number(value) && Number(value) % 1 !== 0;
395426

427+
exports.isInteger = (value) => Number.isInteger(value);
428+
396429
exports.nonEmptyArray = (value) => {
397430
if(!this.isUndefined(value) && value && value.length) {
398431
return true;

bin/runner.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,12 @@ var argv = yargs
168168
type: "string",
169169
default: undefined
170170
},
171+
'st': {
172+
alias: ['specTimeout'],
173+
default: undefined,
174+
describe: Constants.cliMessages.RUN.SPEC_TIMEOUT,
175+
type: "string"
176+
},
171177
'disable-npm-warning': {
172178
default: false,
173179
description: Constants.cliMessages.COMMON.NO_NPM_WARNING,

0 commit comments

Comments
 (0)