diff --git a/bin/helpers/constants.js b/bin/helpers/constants.js index 9e27de32..702441d1 100644 --- a/bin/helpers/constants.js +++ b/bin/helpers/constants.js @@ -139,7 +139,7 @@ const validationMessages = { EMPTY_SPECS_IN_BROWSERSTACK_JSON: "specs is required when enforce_settings is true in run_settings of browserstack.json", VALIDATED: "browserstack.json file is validated", - NOT_VALID: "browerstack.json is not valid", + NOT_VALID: "browserstack.json is not valid", NOT_VALID_JSON: "browerstack.json is not a valid json", INVALID_EXTENSION: "Invalid files, please remove these files and try again.", INVALID_PARALLELS_CONFIGURATION: diff --git a/bin/helpers/runnerArgs.js b/bin/helpers/runnerArgs.js new file mode 100644 index 00000000..287f45dc --- /dev/null +++ b/bin/helpers/runnerArgs.js @@ -0,0 +1,203 @@ +const Constants = require('./constants'); + +const usernameOptions = { + 'u': { + alias: 'username', + describe: Constants.cliMessages.COMMON.USERNAME, + type: "string", + default: undefined + }, +} + +const accessKeyOptions = { + 'k': { + alias: 'key', + describe: Constants.cliMessages.COMMON.ACCESS_KEY, + type: "string", + default: undefined + }, +} + +const configFileOptions = { + 'cf': { + alias: 'config-file', + describe: Constants.cliMessages.COMMON.CONFIG_FILE_PATH, + default: 'browserstack.json', + type: 'string', + nargs: 1, + demand: true, + demand: Constants.cliMessages.COMMON.CONFIG_DEMAND + }, +} + +const debugModeOptions = { + 'cli-debug': { + default: false, + describe: Constants.cliMessages.COMMON.DEBUG, + type: "boolean" + }, +} + +exports.disableUsageReportingOptions = { + 'disable-usage-reporting': { + default: undefined, + description: Constants.cliMessages.COMMON.DISABLE_USAGE_REPORTING, + type: "boolean" + }, +} + +exports.commonBuildOptions = { + ...configFileOptions, + ...this.disableUsageReportingOptions, + ...usernameOptions, + ...accessKeyOptions, + ...debugModeOptions, +} + +exports.runOptions = { + ...this.commonBuildOptions, + 'ccf': { + alias: 'cypress-config-file', + describe: Constants.cliMessages.RUN.CYPRESS_DESC, + default: './cypress.json', + type: 'string', + nargs: 1, + demand: true, + demand: Constants.cliMessages.RUN.CYPRESS_CONFIG_DEMAND + }, + 'gl': { + alias: 'geolocation', + describe: Constants.cliMessages.RUN.CYPRESS_GEO_LOCATION, + default: undefined, + type: 'string' + }, + 'p': { + alias: ['parallels', 'parallel'], + describe: Constants.cliMessages.RUN.PARALLEL_DESC, + type: "number", + default: undefined + }, + 'b': { + alias: ['build-name', 'ci-build-id'], + describe: Constants.cliMessages.RUN.BUILD_NAME, + type: "string", + default: undefined + }, + 'e': { + alias: 'exclude', + describe: Constants.cliMessages.RUN.EXCLUDE, + type: "string", + default: undefined + }, + 's': { + alias: ['specs', 'spec'], + describe: Constants.cliMessages.RUN.SPECS_DESCRIPTION, + type: "string", + default: undefined + }, + 'env': { + describe: Constants.cliMessages.RUN.ENV_DESCRIPTION, + type: "string", + default: undefined + }, + 't': { + alias: ['specTimeout'], + default: undefined, + describe: Constants.cliMessages.RUN.SPEC_TIMEOUT, + type: "string" + }, + 'disable-npm-warning': { + default: false, + description: Constants.cliMessages.COMMON.NO_NPM_WARNING, + type: "boolean" + }, + 'sync': { + default: true, + describe: Constants.cliMessages.RUN.SYNC_DESCRIPTION, + type: "boolean" + }, + 'async': { + default: false, + describe: Constants.cliMessages.RUN.ASYNC_DESCRIPTION, + type: "boolean" + }, + 'force-upload': { + default: false, + describe: Constants.cliMessages.COMMON.FORCE_UPLOAD, + type: "boolean" + }, + 'headed': { + default: false, + describe: Constants.cliMessages.RUN.HEADED, + type: "boolean" + }, + 'local': { + describe: Constants.cliMessages.RUN.LOCAL, + type: "boolean" + }, + 'local-identifier': { + describe: Constants.cliMessages.RUN.LOCAL_IDENTIFIER, + type: "string" + }, + 'local-mode': { + describe: Constants.cliMessages.RUN.LOCAL_MODE, + type: "string" + }, + 'local-config-file': { + describe: Constants.cliMessages.RUN.LOCAL_CONFIG_FILE, + type: "string" + }, + 'no-wrap': { + default: false, + describe: Constants.cliMessages.RUN.SYNC_NO_WRAP, + type: "boolean" + }, + 'browser': { + describe: Constants.cliMessages.RUN.BROWSER_DESCRIPTION, + type: "string", + default: undefined + }, + 'c': { + alias: 'config', + describe: Constants.cliMessages.RUN.CONFIG_DESCRIPTION, + type: "string", + default: undefined + }, + 'r': { + alias: 'reporter', + default: undefined, + describe: Constants.cliMessages.RUN.REPORTER, + type: "string" + }, + 'o': { + alias: 'reporter-options', + default: undefined, + describe: Constants.cliMessages.RUN.REPORTER_OPTIONS, + type: "string" + }, + 'record': { + describe: Constants.cliMessages.RUN.RECORD, + type: "boolean" + }, + 'record-key': { + default: undefined, + describe: Constants.cliMessages.RUN.RECORD_KEY, + type: "string" + }, + 'projectId': { + default: undefined, + describe: Constants.cliMessages.RUN.PROJECT_ID, + type: "string" + }, + 'nv': { + alias: ['node-version', 'nodeVersion'], + default: undefined, + describe: Constants.cliMessages.RUN.NODE_VERSION, + type: "string" + }, + 'build-tag': { + default: undefined, + describe: Constants.cliMessages.RUN.BUILD_TAG, + type: "string" + } +} diff --git a/bin/runner.js b/bin/runner.js index 1f93ed01..6a320ca9 100755 --- a/bin/runner.js +++ b/bin/runner.js @@ -2,63 +2,10 @@ 'use strict'; const yargs = require('yargs'), logger = require("./helpers/logger").winstonLogger, - Constants = require('./helpers/constants'); + Constants = require('./helpers/constants'), + { disableUsageReportingOptions, commonBuildOptions, runOptions } = require('./helpers/runnerArgs'); -const disableUsageReportingOptions = { - 'disable-usage-reporting': { - default: undefined, - description: Constants.cliMessages.COMMON.DISABLE_USAGE_REPORTING, - type: "boolean" - }, -} - -const usernameOptions = { - 'u': { - alias: 'username', - describe: Constants.cliMessages.COMMON.USERNAME, - type: "string", - default: undefined - }, -} - -const accessKeyOptions = { - 'k': { - alias: 'key', - describe: Constants.cliMessages.COMMON.ACCESS_KEY, - type: "string", - default: undefined - }, -} - -const configFileOptions = { - 'cf': { - alias: 'config-file', - describe: Constants.cliMessages.COMMON.CONFIG_FILE_PATH, - default: 'browserstack.json', - type: 'string', - nargs: 1, - demand: true, - demand: Constants.cliMessages.COMMON.CONFIG_DEMAND - }, -} - -const debugModeOptions = { - 'cli-debug': { - default: false, - describe: Constants.cliMessages.COMMON.DEBUG, - type: "boolean" - }, -} - -const commonBuildOptions = { - ...configFileOptions, - ...disableUsageReportingOptions, - ...usernameOptions, - ...accessKeyOptions, - ...debugModeOptions, -} - function checkCommands(yargs, argv, numRequired) { if (argv._.length < numRequired) { yargs.showHelp() @@ -132,151 +79,7 @@ var argv = yargs argv = yargs .usage('usage: $0 run ') .options({ - ...commonBuildOptions, - 'ccf': { - alias: 'cypress-config-file', - describe: Constants.cliMessages.RUN.CYPRESS_DESC, - default: './cypress.json', - type: 'string', - nargs: 1, - demand: true, - demand: Constants.cliMessages.RUN.CYPRESS_CONFIG_DEMAND - }, - 'gl': { - alias: 'geolocation', - describe: Constants.cliMessages.RUN.CYPRESS_GEO_LOCATION, - default: undefined, - type: 'string' - }, - 'p': { - alias: ['parallels', 'parallel'], - describe: Constants.cliMessages.RUN.PARALLEL_DESC, - type: "number", - default: undefined - }, - 'b': { - alias: ['build-name', 'ci-build-id'], - describe: Constants.cliMessages.RUN.BUILD_NAME, - type: "string", - default: undefined - }, - 'e': { - alias: 'exclude', - describe: Constants.cliMessages.RUN.EXCLUDE, - type: "string", - default: undefined - }, - 's': { - alias: ['specs', 'spec'], - describe: Constants.cliMessages.RUN.SPECS_DESCRIPTION, - type: "string", - default: undefined - }, - 'env': { - describe: Constants.cliMessages.RUN.ENV_DESCRIPTION, - type: "string", - default: undefined - }, - 't': { - alias: ['specTimeout'], - default: undefined, - describe: Constants.cliMessages.RUN.SPEC_TIMEOUT, - type: "string" - }, - 'disable-npm-warning': { - default: false, - description: Constants.cliMessages.COMMON.NO_NPM_WARNING, - type: "boolean" - }, - 'sync': { - default: true, - describe: Constants.cliMessages.RUN.SYNC_DESCRIPTION, - type: "boolean" - }, - 'async': { - default: false, - describe: Constants.cliMessages.RUN.ASYNC_DESCRIPTION, - type: "boolean" - }, - 'force-upload': { - default: false, - describe: Constants.cliMessages.COMMON.FORCE_UPLOAD, - type: "boolean" - }, - 'headed': { - default: false, - describe: Constants.cliMessages.RUN.HEADED, - type: "boolean" - }, - 'local': { - describe: Constants.cliMessages.RUN.LOCAL, - type: "boolean" - }, - 'local-identifier': { - describe: Constants.cliMessages.RUN.LOCAL_IDENTIFIER, - type: "string" - }, - 'local-mode': { - describe: Constants.cliMessages.RUN.LOCAL_MODE, - type: "string" - }, - 'local-config-file': { - describe: Constants.cliMessages.RUN.LOCAL_CONFIG_FILE, - type: "string" - }, - 'no-wrap': { - default: false, - describe: Constants.cliMessages.RUN.SYNC_NO_WRAP, - type: "boolean" - }, - 'browser': { - describe: Constants.cliMessages.RUN.BROWSER_DESCRIPTION, - type: "string", - default: undefined - }, - 'c': { - alias: 'config', - describe: Constants.cliMessages.RUN.CONFIG_DESCRIPTION, - type: "string", - default: undefined - }, - 'r': { - alias: 'reporter', - default: undefined, - describe: Constants.cliMessages.RUN.REPORTER, - type: "string" - }, - 'o': { - alias: 'reporter-options', - default: undefined, - describe: Constants.cliMessages.RUN.REPORTER_OPTIONS, - type: "string" - }, - 'record': { - describe: Constants.cliMessages.RUN.RECORD, - type: "boolean" - }, - 'record-key': { - default: undefined, - describe: Constants.cliMessages.RUN.RECORD_KEY, - type: "string" - }, - 'projectId': { - default: undefined, - describe: Constants.cliMessages.RUN.PROJECT_ID, - type: "string" - }, - 'nv': { - alias: ['node-version', 'nodeVersion'], - default: undefined, - describe: Constants.cliMessages.RUN.NODE_VERSION, - type: "string" - }, - 'build-tag': { - default: undefined, - describe: Constants.cliMessages.RUN.BUILD_TAG, - type: "string" - } + ...runOptions, }) .help('help') .wrap(null) diff --git a/bin/testObservability/helper/helper.js b/bin/testObservability/helper/helper.js index 33e6cfd9..c1b499dd 100644 --- a/bin/testObservability/helper/helper.js +++ b/bin/testObservability/helper/helper.js @@ -9,6 +9,7 @@ const { promisify } = require('util'); const gitconfig = require('gitconfiglocal'); const { spawn, execSync } = require('child_process'); const glob = require('glob'); +const { runOptions } = require('../../helpers/runnerArgs') const pGitconfig = promisify(gitconfig); @@ -769,13 +770,45 @@ const getLocalSessionReporter = () => { } const cleanupTestObservabilityFlags = (rawArgs) => { - const newRawArgs = []; - for(let idx=0; idx { + const curr = runOptions[key]; + if (curr.alias) { + const aliases = Array.isArray(curr.alias) ? curr.alias : [curr.alias] + for (const alias of aliases) { + acc[alias] = curr; + } + } + return acc; + }, {}) + + const cliArgs = { + ...runOptions, + ...aliasMap + } + + // these flags are present in cypress too, but in some the same cli and + // cypress flags have different meaning. In that case, we assume user has + // given cypress related args + const retain = ['c', 'p', 'b', 'o', 's', 'specs', 'spec'] + + for (let i = 0;i < rawArgs.length;i++) { + const arg = rawArgs[i]; + if (arg.startsWith('-')) { + const argName = arg.length > 1 && arg[1] == '-' ? arg.slice(2) : arg.slice(1); + // If this flag belongs to cli, we omit it and its value + if (cliArgs[argName] && !retain.includes(argName)) { + const nextArg = i + 1 < rawArgs.length ? rawArgs[i+1] : '' + // if the flag is bound to have a value, we ignore it + if (cliArgs[argName].type && cliArgs[argName].type !== 'boolean' && !nextArg.startsWith('-')) { + i++; + } + continue; + } } + newArgs.push(rawArgs[i]); } - return newRawArgs; + return newArgs; } exports.runCypressTestsLocally = (bsConfig, args, rawArgs) => {