From 3c39e4a0abd7b9718fa5bd447f13da136c431ba7 Mon Sep 17 00:00:00 2001 From: Surya Tripathi Date: Tue, 25 Aug 2020 20:50:05 +0530 Subject: [PATCH 01/13] Adding run command line options: --spec/--specs/-s and --env --- bin/runner.js | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/bin/runner.js b/bin/runner.js index da7c71e4..07c174d2 100755 --- a/bin/runner.js +++ b/bin/runner.js @@ -164,6 +164,17 @@ var argv = yargs describe: Constants.cliMessages.RUN.BUILD_NAME, type: "string", default: undefined + }, + 's': { + alias: ['specs', 'spec'], + describe: Constants.cliMessages.RUN.SPECS_DESCRIPTION, + type: "array", + default: undefined + }, + 'env': { + describe: Constants.cliMessages.RUN.ENV_DESCRIPTION, + type: "array", + default: undefined } }) .help('help') From 0d91e7950348cc84c4306983fb2cf851c7d97147 Mon Sep 17 00:00:00 2001 From: Surya Tripathi Date: Tue, 25 Aug 2020 20:50:40 +0530 Subject: [PATCH 02/13] adding implementation of adding specs and env to run setting when provided --- bin/commands/runs.js | 6 ++++++ bin/helpers/utils.js | 15 +++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/bin/commands/runs.js b/bin/commands/runs.js index e592d0bc..2f88b034 100644 --- a/bin/commands/runs.js +++ b/bin/commands/runs.js @@ -24,6 +24,12 @@ module.exports = function run(args) { // accept the build name from command line if provided utils.setBuildName(bsConfig, args); + // accept the specs list from command line if provided + utils.setUserSpecs(bsConfig, args); + + // accept the env list from command line and set it + utils.setTestEnvs(bsConfig, args); + // Validate browserstack.json values and parallels specified via arguments return capabilityHelper.validate(bsConfig, args).then(function (validated) { logger.info(validated); diff --git a/bin/helpers/utils.js b/bin/helpers/utils.js index dcb5650c..57d749c4 100644 --- a/bin/helpers/utils.js +++ b/bin/helpers/utils.js @@ -95,6 +95,21 @@ exports.setBuildName = (bsConfig, args) => { } } +exports.setUserSpecs = (bsConfig, args) => { + if (!this.isUndefined(args.specs)) { + bsConfig['run_settings']['specs'] = args.specs; + } +} + +// env option must be set only from args +exports.setTestEnvs = (bsConfig, args) => { + if (!this.isUndefined(args.env)) { + bsConfig['run_settings']['env'] = args.env; + } else { + bsConfig['run_settings']['env'] = null; + } +} + exports.isUndefined = value => (value === undefined || value === null); exports.isFloat = value => (Number(value) && Number(value) % 1 !== 0); From 80043c2819d592f11d1694d4503acb2afff8b0d7 Mon Sep 17 00:00:00 2001 From: Surya Tripathi Date: Tue, 25 Aug 2020 20:51:05 +0530 Subject: [PATCH 03/13] Adding description for the new options --- bin/helpers/constants.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/bin/helpers/constants.js b/bin/helpers/constants.js index d1a50ec1..b5925802 100644 --- a/bin/helpers/constants.js +++ b/bin/helpers/constants.js @@ -55,7 +55,9 @@ const cliMessages = { INFO: "Run your tests on BrowserStack.", DESC: "Path to BrowserStack config", CONFIG_DEMAND: "config file is required", - BUILD_NAME: "The build name you want to use to name your test runs" + BUILD_NAME: "The build name you want to use to name your test runs", + SPECS_DESCRIPTION: 'runs specific spec file(s). defaults to "all"', + ENV_DESCRIPTION: "list of env variables to pass for tests" }, COMMON: { DISABLE_USAGE_REPORTING: "Disable usage reporting", From d6006e861dfeb2713104bcfbb48e4d590a2d5c0f Mon Sep 17 00:00:00 2001 From: Surya Tripathi Date: Tue, 25 Aug 2020 20:53:12 +0530 Subject: [PATCH 04/13] adding specs and env to send to API --- bin/helpers/capabilityHelper.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/bin/helpers/capabilityHelper.js b/bin/helpers/capabilityHelper.js index e456e9da..7d27c773 100644 --- a/bin/helpers/capabilityHelper.js +++ b/bin/helpers/capabilityHelper.js @@ -68,6 +68,14 @@ const caps = (bsConfig, zip) => { obj.callbackURL = bsConfig.run_settings.callback_url; obj.projectNotifyURL = bsConfig.run_settings.project_notify_URL; obj.parallels = bsConfig.run_settings.parallels; + + if (!Utils.isUndefined(bsConfig.run_settings.specs)){ + obj.specs = bsConfig.run_settings.specs; + } + + if (!Utils.isUndefined(bsConfig.run_settings.env)){ + obj.env = bsConfig.run_settings.env; + } } if (obj.project) logger.log(`Project name is: ${obj.project}`); From 122379411d0fc32d789c7d37130b30c27b7effc5 Mon Sep 17 00:00:00 2001 From: Surya Tripathi Date: Wed, 26 Aug 2020 18:45:40 +0530 Subject: [PATCH 05/13] Joining the specs array before sending --- bin/helpers/capabilityHelper.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/helpers/capabilityHelper.js b/bin/helpers/capabilityHelper.js index 7d27c773..a81cd320 100644 --- a/bin/helpers/capabilityHelper.js +++ b/bin/helpers/capabilityHelper.js @@ -70,7 +70,7 @@ const caps = (bsConfig, zip) => { obj.parallels = bsConfig.run_settings.parallels; if (!Utils.isUndefined(bsConfig.run_settings.specs)){ - obj.specs = bsConfig.run_settings.specs; + obj.specs = bsConfig.run_settings.specs.join(","); } if (!Utils.isUndefined(bsConfig.run_settings.env)){ From d2539996f5b4077bc9c0d4edaca5dbaedd2435af Mon Sep 17 00:00:00 2001 From: Surya Tripathi Date: Wed, 26 Aug 2020 20:02:10 +0530 Subject: [PATCH 06/13] fixing specs not showing up in params issue --- bin/helpers/utils.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/helpers/utils.js b/bin/helpers/utils.js index 57d749c4..b2b604e3 100644 --- a/bin/helpers/utils.js +++ b/bin/helpers/utils.js @@ -96,7 +96,7 @@ exports.setBuildName = (bsConfig, args) => { } exports.setUserSpecs = (bsConfig, args) => { - if (!this.isUndefined(args.specs)) { + if (!this.isUndefined(args.specs) && args.specs.length > 0 && !this.isUndefined(args.specs[0])) { bsConfig['run_settings']['specs'] = args.specs; } } From 82892ba92bc7e8969bc03bd7335bb2bd69e6cd71 Mon Sep 17 00:00:00 2001 From: Surya Tripathi Date: Fri, 28 Aug 2020 16:11:05 +0530 Subject: [PATCH 07/13] Fixing the specs split and join issue for command line args and config key --- bin/helpers/utils.js | 21 ++++++++++++++++----- bin/runner.js | 4 ++-- 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/bin/helpers/utils.js b/bin/helpers/utils.js index b2b604e3..1d4ed3a3 100644 --- a/bin/helpers/utils.js +++ b/bin/helpers/utils.js @@ -95,18 +95,29 @@ exports.setBuildName = (bsConfig, args) => { } } +// specs can be passed from bstack configuration file +// specs can be passed via command line args as a string +// command line args takes precedence over config exports.setUserSpecs = (bsConfig, args) => { - if (!this.isUndefined(args.specs) && args.specs.length > 0 && !this.isUndefined(args.specs[0])) { - bsConfig['run_settings']['specs'] = args.specs; + let bsConfigSpecs = bsConfig.run_settings.specs; + + if (!this.isUndefined(args.specs)) { + bsConfig.run_settings.specs = args.specs.split(/\s{0,},\s+/).join(','); + } else if (!this.isUndefined(bsConfigSpecs) && Array.isArray(bsConfigSpecs)) { + bsConfig.run_settings.specs = bsConfigSpecs.join(','); + } else if (!this.isUndefined(bsConfigSpecs) && typeof(bsConfigSpecs) == "string") { + bsConfig.run_settings.specs = bsConfigSpecs.split(/\s{0,},\s+/).join(','); + } else { + bsConfig.run_settings.specs = null; } } -// env option must be set only from args +// env option must be set only from command line args as a string exports.setTestEnvs = (bsConfig, args) => { if (!this.isUndefined(args.env)) { - bsConfig['run_settings']['env'] = args.env; + bsConfig.run_settings.env = args.env.split(/\s{0,},\s+/).join(','); } else { - bsConfig['run_settings']['env'] = null; + bsConfig.run_settings.env = null; } } diff --git a/bin/runner.js b/bin/runner.js index 07c174d2..1c1b7e34 100755 --- a/bin/runner.js +++ b/bin/runner.js @@ -168,12 +168,12 @@ var argv = yargs 's': { alias: ['specs', 'spec'], describe: Constants.cliMessages.RUN.SPECS_DESCRIPTION, - type: "array", + type: "string", default: undefined }, 'env': { describe: Constants.cliMessages.RUN.ENV_DESCRIPTION, - type: "array", + type: "string", default: undefined } }) From 6337eadf094be9fc0a3a1130a308f263fd48c20c Mon Sep 17 00:00:00 2001 From: Surya Tripathi Date: Fri, 28 Aug 2020 16:11:24 +0530 Subject: [PATCH 08/13] No need to join in specs now --- bin/helpers/capabilityHelper.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/helpers/capabilityHelper.js b/bin/helpers/capabilityHelper.js index a81cd320..7d27c773 100644 --- a/bin/helpers/capabilityHelper.js +++ b/bin/helpers/capabilityHelper.js @@ -70,7 +70,7 @@ const caps = (bsConfig, zip) => { obj.parallels = bsConfig.run_settings.parallels; if (!Utils.isUndefined(bsConfig.run_settings.specs)){ - obj.specs = bsConfig.run_settings.specs.join(","); + obj.specs = bsConfig.run_settings.specs; } if (!Utils.isUndefined(bsConfig.run_settings.env)){ From 644ff64f10363e750e2eba68a413d2369f707276 Mon Sep 17 00:00:00 2001 From: Surya Tripathi Date: Fri, 28 Aug 2020 19:15:24 +0530 Subject: [PATCH 09/13] adding specs and env stubs --- test/unit/bin/commands/runs.js | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/test/unit/bin/commands/runs.js b/test/unit/bin/commands/runs.js index be3e679e..108f9016 100644 --- a/test/unit/bin/commands/runs.js +++ b/test/unit/bin/commands/runs.js @@ -82,6 +82,8 @@ describe("runs", () => { setUsernameStub = sandbox.stub(); setAccessKeyStub = sandbox.stub(); setBuildNameStub = sandbox.stub(); + setUserSpecsStub = sandbox.stub(); + setTestEnvsStub = sandbox.stub(); getConfigPathStub = sandbox.stub(); setUsageReportingFlagStub = sandbox.stub().returns(undefined); sendUsageReportStub = sandbox.stub().callsFake(function () { @@ -153,6 +155,8 @@ describe("runs", () => { setAccessKeyStub = sandbox.stub(); getConfigPathStub = sandbox.stub(); setBuildNameStub = sandbox.stub(); + setUserSpecsStub = sandbox.stub(); + setTestEnvsStub = sandbox.stub(); validateBstackJsonStub = sandbox.stub(); setUsageReportingFlagStub = sandbox.stub().returns(undefined); sendUsageReportStub = sandbox.stub().callsFake(function () { @@ -234,6 +238,8 @@ describe("runs", () => { setUsernameStub = sandbox.stub(); setAccessKeyStub = sandbox.stub(); setBuildNameStub = sandbox.stub(); + setUserSpecsStub = sandbox.stub(); + setTestEnvsStub = sandbox.stub(); getConfigPathStub = sandbox.stub(); setUsageReportingFlagStub = sandbox.stub().returns(undefined); sendUsageReportStub = sandbox.stub().callsFake(function () { @@ -324,6 +330,8 @@ describe("runs", () => { setUsernameStub = sandbox.stub(); setAccessKeyStub = sandbox.stub(); setBuildNameStub = sandbox.stub(); + setUserSpecsStub = sandbox.stub(); + setTestEnvsStub = sandbox.stub(); getConfigPathStub = sandbox.stub(); setUsageReportingFlagStub = sandbox.stub().returns(undefined); sendUsageReportStub = sandbox.stub().callsFake(function () { @@ -425,6 +433,8 @@ describe("runs", () => { setUsernameStub = sandbox.stub(); setAccessKeyStub = sandbox.stub(); setBuildNameStub = sandbox.stub(); + setUserSpecsStub = sandbox.stub(); + setTestEnvsStub = sandbox.stub(); getConfigPathStub = sandbox.stub(); setUsageReportingFlagStub = sandbox.stub().returns(undefined); sendUsageReportStub = sandbox.stub().callsFake(function () { From d054634843377d5be1133466001489902561ad62 Mon Sep 17 00:00:00 2001 From: Surya Tripathi Date: Fri, 28 Aug 2020 19:44:02 +0530 Subject: [PATCH 10/13] Adding tests for runs.js and capabilityHelper.js --- test/unit/bin/commands/runs.js | 10 ++ test/unit/bin/helpers/capabilityHelper.js | 130 ++++++++++++++++++++++ 2 files changed, 140 insertions(+) diff --git a/test/unit/bin/commands/runs.js b/test/unit/bin/commands/runs.js index 108f9016..1222eab3 100644 --- a/test/unit/bin/commands/runs.js +++ b/test/unit/bin/commands/runs.js @@ -112,6 +112,8 @@ describe("runs", () => { setUsername: setUsernameStub, setAccessKey: setAccessKeyStub, setBuildName: setBuildNameStub, + setUserSpecs: setUserSpecsStub, + setTestEnvs: setTestEnvsStub, getConfigPath: getConfigPathStub }, "../helpers/capabilityHelper": { @@ -185,6 +187,8 @@ describe("runs", () => { setUsername: setUsernameStub, setAccessKey: setAccessKeyStub, setBuildName: setBuildNameStub, + setUserSpecs: setUserSpecsStub, + setTestEnvs: setTestEnvsStub, setUsageReportingFlag: setUsageReportingFlagStub, getConfigPath: getConfigPathStub }, @@ -269,6 +273,8 @@ describe("runs", () => { setUsername: setUsernameStub, setAccessKey: setAccessKeyStub, setBuildName: setBuildNameStub, + setUserSpecs: setUserSpecsStub, + setTestEnvs: setTestEnvsStub, setUsageReportingFlag: setUsageReportingFlagStub, getConfigPath: getConfigPathStub }, @@ -362,6 +368,8 @@ describe("runs", () => { setUsername: setUsernameStub, setAccessKey: setAccessKeyStub, setBuildName: setBuildNameStub, + setUserSpecs: setUserSpecsStub, + setTestEnvs: setTestEnvsStub, setUsageReportingFlag: setUsageReportingFlagStub, getConfigPath: getConfigPathStub }, @@ -466,6 +474,8 @@ describe("runs", () => { setUsername: setUsernameStub, setAccessKey: setAccessKeyStub, setBuildName: setBuildNameStub, + setUserSpecs: setUserSpecsStub, + setTestEnvs: setTestEnvsStub, setUsageReportingFlag: setUsageReportingFlagStub, setParallels: setParallelsStub, getConfigPath: getConfigPathStub diff --git a/test/unit/bin/helpers/capabilityHelper.js b/test/unit/bin/helpers/capabilityHelper.js index c9a991e9..8800d1b2 100644 --- a/test/unit/bin/helpers/capabilityHelper.js +++ b/test/unit/bin/helpers/capabilityHelper.js @@ -249,6 +249,136 @@ describe("capabilityHelper.js", () => { chai.assert.fail("Promise error"); }); }); + + context("specs and env from run_setting", () => { + it("sets specs list is present", () => { + let specsList = "spec1,spec2"; + let zip_url = "bs://"; + let bsConfig = { + auth: { + username: "random", + access_key: "random", + }, + browsers: [ + { + browser: "chrome", + os: "Windows 10", + versions: ["78", "77"], + }, + ], + run_settings: { + specs: specsList + }, + }; + + return capabilityHelper + .caps(bsConfig, { zip_url: zip_url }) + .then(function (data) { + let parsed_data = JSON.parse(data); + chai.assert.equal(parsed_data.specs, specsList); + chai.assert.equal(parsed_data.env, undefined); + }) + .catch((error) => { + chai.assert.fail("Promise error"); + }); + }); + + it("sets env list is present", () => { + let envList = "env1=value1,env2=value2"; + let zip_url = "bs://"; + let bsConfig = { + auth: { + username: "random", + access_key: "random", + }, + browsers: [ + { + browser: "chrome", + os: "Windows 10", + versions: ["78", "77"], + }, + ], + run_settings: { + env: envList + }, + }; + + return capabilityHelper + .caps(bsConfig, { zip_url: zip_url }) + .then(function (data) { + let parsed_data = JSON.parse(data); + chai.assert.equal(parsed_data.env, envList); + chai.assert.equal(parsed_data.specs, undefined); + }) + .catch((error) => { + chai.assert.fail("Promise error"); + }); + }); + + it("sets both specs and env list is present", () => { + let specsList = "spec1,spec2"; + let envList = "env1=value1,env2=value2"; + let zip_url = "bs://"; + let bsConfig = { + auth: { + username: "random", + access_key: "random", + }, + browsers: [ + { + browser: "chrome", + os: "Windows 10", + versions: ["78", "77"], + }, + ], + run_settings: { + specs: specsList, + env: envList + }, + }; + + return capabilityHelper + .caps(bsConfig, { zip_url: zip_url }) + .then(function (data) { + let parsed_data = JSON.parse(data); + chai.assert.equal(parsed_data.specs, specsList); + chai.assert.equal(parsed_data.env, envList); + }) + .catch((error) => { + chai.assert.fail("Promise error"); + }); + }); + + it("both specs and env list is not present", () => { + let zip_url = "bs://"; + let bsConfig = { + auth: { + username: "random", + access_key: "random", + }, + browsers: [ + { + browser: "chrome", + os: "Windows 10", + versions: ["78", "77"], + }, + ], + run_settings: { + }, + }; + + return capabilityHelper + .caps(bsConfig, { zip_url: zip_url }) + .then(function (data) { + let parsed_data = JSON.parse(data); + chai.assert.equal(parsed_data.specs, undefined); + chai.assert.equal(parsed_data.env, undefined); + }) + .catch((error) => { + chai.assert.fail("Promise error"); + }); + }); + }); }); describe("validate", () => { From 961eb70b7347802f7cad51a6192c92b6ec21df39 Mon Sep 17 00:00:00 2001 From: Surya Tripathi Date: Fri, 28 Aug 2020 20:07:47 +0530 Subject: [PATCH 11/13] Adding specs for missing util functions --- test/unit/bin/helpers/utils.js | 185 +++++++++++++++++++++++++++++++++ 1 file changed, 185 insertions(+) diff --git a/test/unit/bin/helpers/utils.js b/test/unit/bin/helpers/utils.js index 47559a66..02a44ddf 100644 --- a/test/unit/bin/helpers/utils.js +++ b/test/unit/bin/helpers/utils.js @@ -236,4 +236,189 @@ describe("utils", () => { sinon.assert.calledOnce(sendUsageReportStub); }); }); + + describe("setBuildName", () => { + it("sets the build name from args list", () => { + let argBuildName = "argBuildName"; + let bsConfig = { + run_settings: { + build_name: "build_name" + } + }; + let args = { + 'build-name': argBuildName + }; + + utils.setBuildName(bsConfig, args); + expect(bsConfig.run_settings.build_name).to.be.eq(argBuildName); + }); + }); + + describe("setUsername", () => { + it("sets the username from args list", () => { + let argUserName = "argUserName"; + let bsConfig = { + auth: { + username: "username" + } + }; + let args = { + username: argUserName + }; + + utils.setUsername(bsConfig, args); + expect(bsConfig.auth.username).to.be.eq(argUserName); + }); + }); + + describe("setAccessKey", () => { + it("sets the access key from args list", () => { + let argAccessKey = "argAccessKey"; + let bsConfig = { + auth: { + access_key: "access_key" + } + }; + let args = { + key: argAccessKey + }; + + utils.setAccessKey(bsConfig, args); + expect(bsConfig.auth.access_key).to.be.eq(argAccessKey); + }); + }); + + describe("setUserSpecs", () => { + it("sets the specs from args list without space after comma with single space in given list", () => { + let argsSpecs = "spec3, spec4"; + let bsConfig = { + run_settings: { + specs: "spec1, spec2" + } + }; + let args = { + specs: argsSpecs + }; + + utils.setUserSpecs(bsConfig, args); + expect(bsConfig.run_settings.specs).to.be.eq('spec3,spec4'); + }); + + it("sets the specs from args list without space after comma with spaces in given list", () => { + let argsSpecs = "spec3 , spec4"; + let bsConfig = { + run_settings: { + specs: "spec1, spec2" + } + }; + let args = { + specs: argsSpecs + }; + + utils.setUserSpecs(bsConfig, args); + expect(bsConfig.run_settings.specs).to.be.eq('spec3,spec4'); + }); + + it("sets the specs list from specs key without space after comma with once space after comma in given list", () => { + let bsConfig = { + run_settings: { + specs: "spec1, spec2" + } + }; + let args = { + specs: null + }; + + utils.setUserSpecs(bsConfig, args); + expect(bsConfig.run_settings.specs).to.be.eq('spec1,spec2'); + }); + + it("sets the specs list from specs key without space after comma with extra space in given list", () => { + let bsConfig = { + run_settings: { + specs: "spec1 , spec2" + } + }; + let args = { + specs: null + }; + + utils.setUserSpecs(bsConfig, args); + expect(bsConfig.run_settings.specs).to.be.eq('spec1,spec2'); + }); + + it("sets the specs list from specs key array without space with comma", () => { + let bsConfig = { + run_settings: { + specs: ["spec1", "spec2"] + } + }; + let args = { + specs: null + }; + + utils.setUserSpecs(bsConfig, args); + expect(bsConfig.run_settings.specs).to.be.eq('spec1,spec2'); + }); + + it("does not set the specs list if no specs key specified", () => { + let bsConfig = { + run_settings: { + } + }; + let args = { + specs: null + }; + + utils.setUserSpecs(bsConfig, args); + expect(bsConfig.run_settings.specs).to.be.eq(null); + }); + }); + + describe("setTestEnvs", () => { + it("sets env only from args", () => { + let argsEnv = "env3=value3, env4=value4"; + let bsConfig = { + run_settings: { + env: "env1=value1, env2=value2" + } + }; + let args = { + env: argsEnv + }; + + utils.setTestEnvs(bsConfig, args); + expect(bsConfig.run_settings.env).to.be.eq('env3=value3,env4=value4'); + }); + + it("sets env from args without spaces in it", () => { + let argsEnv = "env3=value3 , env4=value4"; + let bsConfig = { + run_settings: { + env: "env1=value1 , env2=value2" + } + }; + let args = { + env: argsEnv + }; + + utils.setTestEnvs(bsConfig, args); + expect(bsConfig.run_settings.env).to.be.eq('env3=value3,env4=value4'); + }); + + it("does not set env if not specified in args", () => { + let argsEnv = "env3=value3 , env4=value4"; + let bsConfig = { + run_settings: { + env: "env1=value1 , env2=value2" + } + }; + let args = { + env: null + }; + + utils.setTestEnvs(bsConfig, args); + expect(bsConfig.run_settings.env).to.be.eq(null); + }); + }); }); From 391e88aa39a457e8af0a73a2496d6fa97fa40ecd Mon Sep 17 00:00:00 2001 From: Surya Tripathi Date: Mon, 31 Aug 2020 15:51:19 +0530 Subject: [PATCH 12/13] Moved split and join string to function in util and added its specs --- bin/helpers/utils.js | 10 +++++++--- test/unit/bin/helpers/utils.js | 20 ++++++++++++++++++++ 2 files changed, 27 insertions(+), 3 deletions(-) diff --git a/bin/helpers/utils.js b/bin/helpers/utils.js index 1d4ed3a3..b5538191 100644 --- a/bin/helpers/utils.js +++ b/bin/helpers/utils.js @@ -102,11 +102,11 @@ exports.setUserSpecs = (bsConfig, args) => { let bsConfigSpecs = bsConfig.run_settings.specs; if (!this.isUndefined(args.specs)) { - bsConfig.run_settings.specs = args.specs.split(/\s{0,},\s+/).join(','); + bsConfig.run_settings.specs = this.fixCommaSeparatedString(args.specs); } else if (!this.isUndefined(bsConfigSpecs) && Array.isArray(bsConfigSpecs)) { bsConfig.run_settings.specs = bsConfigSpecs.join(','); } else if (!this.isUndefined(bsConfigSpecs) && typeof(bsConfigSpecs) == "string") { - bsConfig.run_settings.specs = bsConfigSpecs.split(/\s{0,},\s+/).join(','); + bsConfig.run_settings.specs = this.fixCommaSeparatedString(bsConfigSpecs); } else { bsConfig.run_settings.specs = null; } @@ -115,12 +115,16 @@ exports.setUserSpecs = (bsConfig, args) => { // env option must be set only from command line args as a string exports.setTestEnvs = (bsConfig, args) => { if (!this.isUndefined(args.env)) { - bsConfig.run_settings.env = args.env.split(/\s{0,},\s+/).join(','); + bsConfig.run_settings.env = this.fixCommaSeparatedString(args.env); } else { bsConfig.run_settings.env = null; } } +exports.fixCommaSeparatedString = (string) => { + return string.split(/\s{0,},\s+/).join(','); +} + exports.isUndefined = value => (value === undefined || value === null); exports.isFloat = value => (Number(value) && Number(value) % 1 !== 0); diff --git a/test/unit/bin/helpers/utils.js b/test/unit/bin/helpers/utils.js index 02a44ddf..06905a16 100644 --- a/test/unit/bin/helpers/utils.js +++ b/test/unit/bin/helpers/utils.js @@ -421,4 +421,24 @@ describe("utils", () => { expect(bsConfig.run_settings.env).to.be.eq(null); }); }); + + describe("fixCommaSeparatedString", () => { + it("string with spaces after comma", () => { + let commaString = "string1, string2"; + let result = utils.fixCommaSeparatedString(commaString); + expect(result).to.be.eq('string1,string2'); + }); + + it("string with spaces around comma", () => { + let commaString = "string1 , string2"; + let result = utils.fixCommaSeparatedString(commaString); + expect(result).to.be.eq('string1,string2'); + }); + + it("string with 2 spaces around comma", () => { + let commaString = "string1 , string2"; + let result = utils.fixCommaSeparatedString(commaString); + expect(result).to.be.eq('string1,string2'); + }); + }); }); From 3500d6e8143bf70923a0365066ff6c3463ed5717 Mon Sep 17 00:00:00 2001 From: Surya Tripathi Date: Wed, 2 Sep 2020 19:39:34 +0530 Subject: [PATCH 13/13] Updated the specs and env description --- bin/helpers/constants.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bin/helpers/constants.js b/bin/helpers/constants.js index 5dd2656d..92ecd1b2 100644 --- a/bin/helpers/constants.js +++ b/bin/helpers/constants.js @@ -61,8 +61,8 @@ const cliMessages = { DESC: "Path to BrowserStack config", CONFIG_DEMAND: "config file is required", BUILD_NAME: "The build name you want to use to name your test runs", - SPECS_DESCRIPTION: 'runs specific spec file(s). defaults to "all"', - ENV_DESCRIPTION: "list of env variables to pass for tests" + SPECS_DESCRIPTION: 'Specify the spec files to run', + ENV_DESCRIPTION: "Specify the environment variables for your spec files" }, COMMON: { DISABLE_USAGE_REPORTING: "Disable usage reporting",