Skip to content

Improved support of config options in cli #159

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 6 commits into from
Sep 30, 2021
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
7 changes: 6 additions & 1 deletion bin/commands/runs.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ module.exports = function run(args) {
markBlockEnd('deleteOldResults');

markBlockStart('validateBstackJson');
return utils.validateBstackJson(bsConfigPath).then(function (bsConfig) {
return utils.validateBstackJson(bsConfigPath).then(async function (bsConfig) {
markBlockEnd('validateBstackJson');
markBlockStart('setConfig');
utils.setUsageReportingFlag(bsConfig, args.disableUsageReporting);
Expand Down Expand Up @@ -69,6 +69,11 @@ module.exports = function run(args) {
// set the no-wrap
utils.setNoWrap(bsConfig, args);

//set browsers
await utils.setBrowsers(bsConfig, args);

//set config (--config)
utils.setConfig(bsConfig, args);
// set other cypress configs e.g. reporter and reporter-options
utils.setOtherConfigs(bsConfig, args);
markBlockEnd('setConfig');
Expand Down
3 changes: 1 addition & 2 deletions bin/helpers/capabilityHelper.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
const logger = require("./logger").winstonLogger,
Constants = require("./constants"),
Utils = require("./utils"),
fs = require('fs'),
path = require('path');
fs = require('fs');

const caps = (bsConfig, zip) => {
return new Promise(function (resolve, reject) {
Expand Down
5 changes: 4 additions & 1 deletion bin/helpers/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,8 @@ const validationMessages = {
INVALID_CLI_LOCAL_IDENTIFIER: "When using --local-identifier, a value needs to be supplied. \n--local-identifier <String>.\nFor more info, check out https://www.browserstack.com/docs/automate/cypress/cli-reference",
INVALID_LOCAL_MODE: "When using --local-mode, a value needs to be supplied. \n--local-mode (\"always-on\" | \"on-demand\").\nFor more info, check out https://www.browserstack.com/docs/automate/cypress/cli-reference",
INVALID_LOCAL_CONFIG_FILE: "Using --local-config-file requires an input of the form /path/to/config-file.yml.\nFor more info, check out https://www.browserstack.com/docs/automate/cypress/cli-reference",
INVALID_LOCAL_IDENTIFIER: "Invalid value specified for local_identifier. For more info, check out https://www.browserstack.com/docs/automate/cypress/cli-reference"
INVALID_LOCAL_IDENTIFIER: "Invalid value specified for local_identifier. For more info, check out https://www.browserstack.com/docs/automate/cypress/cli-reference",
INVALID_BROWSER_ARGS: "Aborting as an unacceptable value was passed for --browser. Read more at https://www.browserstack.com/docs/automate/cypress/cli-reference"
};

const cliMessages = {
Expand Down Expand Up @@ -110,6 +111,8 @@ const cliMessages = {
LOCAL_IDENTIFIER: "Accepted values: String - assign an identifier to your Local process instance",
LOCAL_CONFIG_FILE: "Accepted values: String - path to local config-file to your Local process instance. Learn more at https://www.browserstack.com/local-testing/binary-params",
SYNC_NO_WRAP: "Wrap the spec names in --sync mode in case of smaller terminal window size pass --no-wrap",
BROWSER_DESCRIPTION: "Specify the browsers you need to run your tests on.",
CONFIG_DESCRIPTION: "Set configuration values. Separate multiple values with a comma. The values set here override any values set in your configuration file.",
REPORTER: "Specify the custom reporter to use",
REPORTER_OPTIONS: "Specify reporter options for custom reporter",
},
Expand Down
30 changes: 30 additions & 0 deletions bin/helpers/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -754,6 +754,36 @@ exports.deleteBaseUrlFromError = (err) => {
return err.replace(/To test ([\s\S]*)on BrowserStack/g, 'To test on BrowserStack');
}

exports.setBrowsers = async (bsConfig, args) => {
return new Promise((resolve, reject) => {
if(!this.isUndefined(args.browser)){
try{
bsConfig["browsers"] = []
let browsersList = args.browser.split(',')
browsersList.forEach((browser)=>{
let browserHash = {}
let osBrowserDetails = browser.split(':')
browserHash['os'] = osBrowserDetails[1].trim()
let browserDetails = osBrowserDetails[0].split('@')
browserHash['browser'] = browserDetails[0].trim()
browserHash['versions'] = []
browserHash['versions'].push(this.isUndefined(browserDetails[1]) ? "latest" : browserDetails[1].trim())
bsConfig["browsers"].push(browserHash)
});
} catch(err){
reject(Constants.validationMessages.INVALID_BROWSER_ARGS)
}
}
resolve()
});
}

exports.setConfig = (bsConfig, args) => {
if (!this.isUndefined(args.config)) {
bsConfig["run_settings"]["config"] = args.config
}
}

// blindly send other passed configs with run_settings and handle at backend
exports.setOtherConfigs = (bsConfig, args) => {
if (!this.isUndefined(args.reporter)) {
Expand Down
15 changes: 13 additions & 2 deletions bin/runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,13 +130,13 @@ var argv = yargs
demand: Constants.cliMessages.RUN.CYPRESS_CONFIG_DEMAND
},
'p': {
alias: 'parallels',
alias: ['parallels', 'parallel'],
describe: Constants.cliMessages.RUN.PARALLEL_DESC,
type: "number",
default: undefined
},
'b': {
alias: 'build-name',
alias: ['build-name', 'ci-build-id'],
describe: Constants.cliMessages.RUN.BUILD_NAME,
type: "string",
default: undefined
Expand Down Expand Up @@ -199,6 +199,17 @@ var argv = yargs
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,
Expand Down
31 changes: 26 additions & 5 deletions test/unit/bin/commands/runs.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const chai = require("chai"),
const Constants = require("../../../../bin/helpers/constants"),
logger = require("../../../../bin/helpers/logger").winstonLogger,
testObjects = require("../../support/fixtures/testObjects");

const proxyquire = require("proxyquire").noCallThru();

chai.use(chaiAsPromised);
Expand Down Expand Up @@ -107,6 +107,8 @@ describe("runs", () => {
setDefaultsStub = sandbox.stub();
setLocalModeStub = sandbox.stub();
setLocalConfigFileStub = sandbox.stub();
setBrowsersStub = sandbox.stub();
setConfigStub = sandbox.stub();
});

afterEach(() => {
Expand Down Expand Up @@ -143,7 +145,9 @@ describe("runs", () => {
isJSONInvalid: isJSONInvalidStub,
setLocalMode: setLocalModeStub,
setLocalConfigFile: setLocalConfigFileStub,
setSystemEnvs: setSystemEnvsStub
setSystemEnvs: setSystemEnvsStub,
setBrowsers: setBrowsersStub,
setConfig: setConfigStub
},
'../helpers/capabilityHelper': {
validate: capabilityValidatorStub
Expand Down Expand Up @@ -176,6 +180,7 @@ describe("runs", () => {
sinon.assert.calledOnce(setLocalConfigFileStub);
sinon.assert.calledOnce(setHeadedStub);
sinon.assert.calledOnce(setNoWrapStub);
sinon.assert.calledOnce(setConfigStub);
sinon.assert.calledOnce(setOtherConfigsStub);
sinon.assert.calledOnce(capabilityValidatorStub);
sinon.assert.calledOnce(getErrorCodeFromMsgStub);
Expand Down Expand Up @@ -228,6 +233,8 @@ describe("runs", () => {
getNumberOfSpecFilesStub = sandbox.stub().returns([]);
setDefaultsStub = sandbox.stub();
setLocalConfigFileStub = sandbox.stub();
setBrowsersStub = sandbox.stub();
setConfigStub = sandbox.stub();
});

afterEach(() => {
Expand Down Expand Up @@ -265,7 +272,9 @@ describe("runs", () => {
setDefaults: setDefaultsStub,
getNumberOfSpecFiles: getNumberOfSpecFilesStub,
setLocalConfigFile: setLocalConfigFileStub,
setSystemEnvs: setSystemEnvsStub
setSystemEnvs: setSystemEnvsStub,
setBrowsers: setBrowsersStub,
setConfig: setConfigStub
},
'../helpers/capabilityHelper': {
validate: capabilityValidatorStub,
Expand Down Expand Up @@ -364,6 +373,8 @@ describe("runs", () => {
getNumberOfSpecFilesStub = sandbox.stub().returns([]);
setDefaultsStub = sandbox.stub();
setLocalConfigFileStub = sandbox.stub();
setConfigStub = sandbox.stub();
setBrowsersStub = sandbox.stub();
});

afterEach(() => {
Expand Down Expand Up @@ -401,7 +412,9 @@ describe("runs", () => {
deleteResults: deleteResultsStub,
getNumberOfSpecFiles: getNumberOfSpecFilesStub,
setDefaults: setDefaultsStub,
setLocalConfigFile: setLocalConfigFileStub
setLocalConfigFile: setLocalConfigFileStub,
setBrowsers: setBrowsersStub,
setConfig: setConfigStub
},
'../helpers/capabilityHelper': {
validate: capabilityValidatorStub,
Expand Down Expand Up @@ -505,6 +518,8 @@ describe("runs", () => {
setDefaultsStub = sandbox.stub();
stopLocalBinaryStub = sandbox.stub();
setLocalConfigFileStub = sandbox.stub();
setConfigStub = sandbox.stub();
setBrowsersStub = sandbox.stub();
});

afterEach(() => {
Expand Down Expand Up @@ -543,7 +558,9 @@ describe("runs", () => {
getNumberOfSpecFiles: getNumberOfSpecFilesStub,
setDefaults: setDefaultsStub,
stopLocalBinary: stopLocalBinaryStub,
setLocalConfigFile: setLocalConfigFileStub
setLocalConfigFile: setLocalConfigFileStub,
setBrowsers: setBrowsersStub,
setConfig: setConfigStub
},
'../helpers/capabilityHelper': {
validate: capabilityValidatorStub,
Expand Down Expand Up @@ -663,6 +680,8 @@ describe("runs", () => {
initTimeComponentsStub = sandbox.stub();
markBlockStartStub = sandbox.stub();
markBlockEndStub = sandbox.stub();
setConfigStub = sandbox.stub();
setBrowsersStub = sandbox.stub();
stopLocalBinaryStub = sandbox.stub();
nonEmptyArrayStub = sandbox.stub();
});
Expand Down Expand Up @@ -707,6 +726,8 @@ describe("runs", () => {
isUndefined: isUndefinedStub,
getNumberOfSpecFiles: getNumberOfSpecFilesStub,
setLocalConfigFile: setLocalConfigFileStub,
setBrowsers: setBrowsersStub,
setConfig: setConfigStub,
stopLocalBinary: stopLocalBinaryStub,
nonEmptyArray: nonEmptyArrayStub,
},
Expand Down
16 changes: 16 additions & 0 deletions test/unit/bin/helpers/fileHelpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,22 @@ describe("fileHelpers", () => {
expect(dataMock).to.eql(1);
});

it("callback fn is executed after file write", () => {
let dataMock = 0;

let callbackStub = sandbox.stub().callsFake(() => {
dataMock = 1;
});

const fileExtraStub = sinon.stub(fs,'writeFile');
fileExtraStub.yields(true);
fileHelpers.write({path: "./random_path", file: "random"}, "writing successful", {}, callbackStub);

sinon.assert.calledOnce(callbackStub);
sinon.assert.calledOnce(fileExtraStub);
expect(dataMock).to.eql(1);
});

it("callback fn is executed after fileExists returns error", () => {
let dataMock = undefined;

Expand Down
Loading