Skip to content

specs and env options #46

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 17 commits into from
Sep 9, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions bin/commands/runs.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,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);

//accept the local from env variable if provided
utils.setLocal(bsConfig);

Expand Down
8 changes: 8 additions & 0 deletions bin/helpers/capabilityHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,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.parallels === Constants.constants.DEFAULT_PARALLEL_MESSAGE) obj.parallels = undefined
Expand Down
4 changes: 3 additions & 1 deletion bin/helpers/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,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: 'Specify the spec files to run',
ENV_DESCRIPTION: "Specify the environment variables for your spec files"
},
COMMON: {
DISABLE_USAGE_REPORTING: "Disable usage reporting",
Expand Down
30 changes: 30 additions & 0 deletions bin/helpers/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,36 @@ 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) => {
let bsConfigSpecs = bsConfig.run_settings.specs;

if (!this.isUndefined(args.specs)) {
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 = this.fixCommaSeparatedString(bsConfigSpecs);
} else {
bsConfig.run_settings.specs = null;
}
}

// 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 = 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);
Expand Down
11 changes: 11 additions & 0 deletions bin/runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,17 @@ var argv = yargs
type: "string",
default: undefined
},
's': {
alias: ['specs', 'spec'],
describe: Constants.cliMessages.RUN.SPECS_DESCRIPTION,
type: "string",
default: undefined
Comment on lines +170 to +172
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

confirm the cli messages and default values once

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will update the message values.

},
'env': {
describe: Constants.cliMessages.RUN.ENV_DESCRIPTION,
type: "string",
default: undefined
},
'disable-npm-warning': {
default: false,
description: Constants.cliMessages.COMMON.NO_NPM_WARNING,
Expand Down
20 changes: 20 additions & 0 deletions test/unit/bin/commands/runs.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,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 () {
Expand Down Expand Up @@ -116,6 +118,8 @@ describe("runs", () => {
setUsername: setUsernameStub,
setAccessKey: setAccessKeyStub,
setBuildName: setBuildNameStub,
setUserSpecs: setUserSpecsStub,
setTestEnvs: setTestEnvsStub,
getConfigPath: getConfigPathStub,
setLocal: setLocalStub,
setLocalIdentifier: setLocalIdentifierStub,
Expand Down Expand Up @@ -165,6 +169,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 () {
Expand Down Expand Up @@ -196,6 +202,8 @@ describe("runs", () => {
setUsername: setUsernameStub,
setAccessKey: setAccessKeyStub,
setBuildName: setBuildNameStub,
setUserSpecs: setUserSpecsStub,
setTestEnvs: setTestEnvsStub,
setUsageReportingFlag: setUsageReportingFlagStub,
getConfigPath: getConfigPathStub,
setLocal: setLocalStub,
Expand Down Expand Up @@ -255,6 +263,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 () {
Expand Down Expand Up @@ -287,6 +297,8 @@ describe("runs", () => {
setUsername: setUsernameStub,
setAccessKey: setAccessKeyStub,
setBuildName: setBuildNameStub,
setUserSpecs: setUserSpecsStub,
setTestEnvs: setTestEnvsStub,
setUsageReportingFlag: setUsageReportingFlagStub,
getConfigPath: getConfigPathStub,
setLocal: setLocalStub,
Expand Down Expand Up @@ -353,6 +365,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 () {
Expand Down Expand Up @@ -386,6 +400,8 @@ describe("runs", () => {
setUsername: setUsernameStub,
setAccessKey: setAccessKeyStub,
setBuildName: setBuildNameStub,
setUserSpecs: setUserSpecsStub,
setTestEnvs: setTestEnvsStub,
setUsageReportingFlag: setUsageReportingFlagStub,
getConfigPath: getConfigPathStub,
setLocal: setLocalStub,
Expand Down Expand Up @@ -463,6 +479,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 () {
Expand Down Expand Up @@ -499,6 +517,8 @@ describe("runs", () => {
setUsername: setUsernameStub,
setAccessKey: setAccessKeyStub,
setBuildName: setBuildNameStub,
setUserSpecs: setUserSpecsStub,
setTestEnvs: setTestEnvsStub,
setUsageReportingFlag: setUsageReportingFlagStub,
setParallels: setParallelsStub,
getConfigPath: getConfigPathStub,
Expand Down
130 changes: 130 additions & 0 deletions test/unit/bin/helpers/capabilityHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -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", () => {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no test where specs list is an Array or passed args is of Array type

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As call to util.setUserSpecs and util.setTestEnvsare made in runs.js and then final state(String) is passed into capabilityHelper. Hence, capabilityHelper always receives string.

specs for array conditions are covered in the util.js itself: https://github.com/browserstack/browserstack-cypress-cli/pull/46/files/961eb70b7347802f7cad51a6192c92b6ec21df39#diff-175b2b2ef3763bf0f62fe44137aa5d34R350

let specsList = "spec1,spec2";
let zip_url = "bs://<random>";
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://<random>";
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://<random>";
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://<random>";
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", () => {
Expand Down
Loading