diff --git a/bin/commands/runs.js b/bin/commands/runs.js index 759d10de..e5ac1182 100644 --- a/bin/commands/runs.js +++ b/bin/commands/runs.js @@ -97,6 +97,8 @@ module.exports = function run(args, rawArgs) { // set record feature caps utils.setRecordCaps(bsConfig, args); + // set build tag caps + utils.setBuildTags(bsConfig, args); // set node version utils.setNodeVersion(bsConfig, args); diff --git a/bin/helpers/constants.js b/bin/helpers/constants.js index 8d155232..f03ed4a7 100644 --- a/bin/helpers/constants.js +++ b/bin/helpers/constants.js @@ -153,7 +153,8 @@ const cliMessages = { RECORD: "Pass the --record flag to record your Cypress runs on Cypress.io dashboard. Note: You also need to specify '--record-key' and '--projectId' arguments either in CLI or in browserstack.json.", RECORD_KEY: "You can specify the 'key' that is needed to record your runs on Cypress.io dashboard using the '--record-key' argument. Alternatively, you can also pass it on browserstack.json", PROJECT_ID: "You can pass the 'projectId' of your Cypress.io project where you want to record your runs if specifying the '--record' key. You can also specify this in your cypress.json or in your browserstack.json.", - NODE_VERSION: "Pass the node version that you want BrowserStack to use to run your Cypress tests on." + NODE_VERSION: "Pass the node version that you want BrowserStack to use to run your Cypress tests on.", + BUILD_TAG: "Add a tag to your build to filter builds based on tag values on the Dashboard." }, COMMON: { DISABLE_USAGE_REPORTING: "Disable usage reporting", diff --git a/bin/helpers/utils.js b/bin/helpers/utils.js index ad4ac267..6b94350a 100644 --- a/bin/helpers/utils.js +++ b/bin/helpers/utils.js @@ -444,6 +444,20 @@ exports.setTestEnvs = (bsConfig, args) => { logger.debug(`Setting env vars = ${bsConfig.run_settings.env}`); } +exports.setBuildTags = (bsConfig, args) => { + let buildTag = undefined; + if(!this.isUndefined(args["build-tag"])) { + buildTag = args["build-tag"]; + } else { + buildTag = bsConfig.run_settings.build_tag; + } + if(!this.isUndefined(buildTag)) { + buildTag = buildTag.toString(); + } + bsConfig.run_settings.build_tag = buildTag; + logger.debug(`Setting the build tag = ${bsConfig.run_settings.build_tag}`); +}; + exports.setSystemEnvs = (bsConfig) => { let envKeys = {}; diff --git a/bin/runner.js b/bin/runner.js index f47fbd64..1f93ed01 100755 --- a/bin/runner.js +++ b/bin/runner.js @@ -271,6 +271,11 @@ var argv = yargs default: undefined, describe: Constants.cliMessages.RUN.NODE_VERSION, type: "string" + }, + 'build-tag': { + default: undefined, + describe: Constants.cliMessages.RUN.BUILD_TAG, + type: "string" } }) .help('help') diff --git a/test/unit/bin/commands/runs.js b/test/unit/bin/commands/runs.js index 31107169..e1b6482f 100644 --- a/test/unit/bin/commands/runs.js +++ b/test/unit/bin/commands/runs.js @@ -122,6 +122,7 @@ describe("runs", () => { setSpecTimeoutStub = sandbox.stub().returns(undefined); setRecordCapsStub = sandbox.stub().returns(undefined); setNodeVersionStub = sandbox.stub(); + setBuildTagsStub = sandbox.stub(); }); afterEach(() => { @@ -166,7 +167,8 @@ describe("runs", () => { setSpecTimeout: setSpecTimeoutStub, setRecordCaps: setRecordCapsStub, setDebugMode: setDebugModeStub, - setNodeVersion: setNodeVersionStub + setNodeVersion: setNodeVersionStub, + setBuildTags: setBuildTagsStub }, '../helpers/capabilityHelper': { validate: capabilityValidatorStub @@ -215,6 +217,7 @@ describe("runs", () => { sinon.assert.calledOnce(getInitialDetailsStub); sinon.assert.calledOnce(setRecordCapsStub); sinon.assert.calledOnce(setNodeVersionStub); + sinon.assert.calledOnce(setBuildTagsStub); sinon.assert.calledOnceWithExactly( sendUsageReportStub, bsConfig, @@ -276,6 +279,7 @@ describe("runs", () => { setSpecTimeoutStub = sandbox.stub().returns(undefined); setRecordCapsStub = sandbox.stub().returns(undefined); setNodeVersionStub = sandbox.stub(); + setBuildTagsStub = sandbox.stub(); }); afterEach(() => { @@ -323,7 +327,8 @@ describe("runs", () => { setSpecTimeout: setSpecTimeoutStub, setRecordCaps: setRecordCapsStub, setDebugMode: setDebugModeStub, - setNodeVersion: setNodeVersionStub + setNodeVersion: setNodeVersionStub, + setBuildTags: setBuildTagsStub }, '../helpers/capabilityHelper': { validate: capabilityValidatorStub, @@ -391,6 +396,7 @@ describe("runs", () => { sinon.assert.calledOnce(getInitialDetailsStub); sinon.assert.calledOnce(setRecordCapsStub); sinon.assert.calledOnce(setNodeVersionStub); + sinon.assert.calledOnce(setBuildTagsStub); sinon.assert.calledOnceWithExactly( sendUsageReportStub, bsConfig, @@ -454,6 +460,7 @@ describe("runs", () => { getInitialDetailsStub = sandbox.stub(); setRecordCapsStub = sandbox.stub().returns(undefined); setNodeVersionStub = sandbox.stub(); + setBuildTagsStub = sandbox.stub(); }); afterEach(() => { @@ -502,7 +509,8 @@ describe("runs", () => { setSpecTimeout: setSpecTimeoutStub, setRecordCaps: setRecordCapsStub, setDebugMode: setDebugModeStub, - setNodeVersion: setNodeVersionStub + setNodeVersion: setNodeVersionStub, + setBuildTags: setBuildTagsStub }, '../helpers/capabilityHelper': { validate: capabilityValidatorStub, @@ -572,6 +580,7 @@ describe("runs", () => { sinon.assert.calledOnce(getInitialDetailsStub); sinon.assert.calledOnce(setRecordCapsStub); sinon.assert.calledOnce(setNodeVersionStub); + sinon.assert.calledOnce(setBuildTagsStub); sinon.assert.calledOnceWithExactly( sendUsageReportStub, bsConfig, @@ -640,6 +649,7 @@ describe("runs", () => { getInitialDetailsStub = sandbox.stub(); setRecordCapsStub = sandbox.stub().returns(undefined); setNodeVersionStub = sandbox.stub(); + setBuildTagsStub = sandbox.stub(); }); afterEach(() => { @@ -690,6 +700,7 @@ describe("runs", () => { setRecordCaps: setRecordCapsStub, setDebugMode: setDebugModeStub, setNodeVersion: setNodeVersionStub, + setBuildTags: setBuildTagsStub }, '../helpers/capabilityHelper': { validate: capabilityValidatorStub, @@ -770,6 +781,7 @@ describe("runs", () => { sinon.assert.calledOnce(getInitialDetailsStub); sinon.assert.calledOnce(setRecordCapsStub); sinon.assert.calledOnce(setNodeVersionStub); + sinon.assert.calledOnce(setBuildTagsStub); sinon.assert.calledOnceWithExactly( sendUsageReportStub, @@ -852,6 +864,7 @@ describe("runs", () => { getInitialDetailsStub = sandbox.stub(); setRecordCapsStub = sandbox.stub().returns(undefined); setNodeVersionStub = sandbox.stub(); + setBuildTagsStub = sandbox.stub(); }); afterEach(() => { @@ -910,6 +923,7 @@ describe("runs", () => { setRecordCaps: setRecordCapsStub, setDebugMode: setDebugModeStub, setNodeVersion: setNodeVersionStub, + setBuildTags: setBuildTagsStub }, '../helpers/capabilityHelper': { validate: capabilityValidatorStub, @@ -1006,6 +1020,7 @@ describe("runs", () => { sinon.assert.calledOnce(getInitialDetailsStub); sinon.assert.calledOnce(setRecordCapsStub); sinon.assert.calledOnce(setNodeVersionStub); + sinon.assert.calledOnce(setBuildTagsStub); sinon.assert.match( sendUsageReportStub.getCall(0).args, [ diff --git a/test/unit/bin/helpers/utils.js b/test/unit/bin/helpers/utils.js index 4e2a1968..4321e7bd 100644 --- a/test/unit/bin/helpers/utils.js +++ b/test/unit/bin/helpers/utils.js @@ -3379,6 +3379,56 @@ describe('utils', () => { }); }); + describe('setBuildTags', () => { + it('should give preference to args', () => { + let bsConfig = { + run_settings: { + build_tag: "abc" + } + } + + let args = { + "build-tag": "def" + } + utils.setBuildTags(bsConfig, args); + expect(bsConfig.run_settings.build_tag).to.be.eq("def"); + }); + + it('should honour bstack json if args not passed', () => { + let bsConfig = { + run_settings: { + build_tag: "abc" + } + } + + let args = {} + utils.setBuildTags(bsConfig, args); + expect(bsConfig.run_settings.build_tag).to.be.eq("abc"); + }); + + it('should convert values to string', () => { + let bsConfig = { + run_settings: { + build_tag: 1234 + } + } + + let args = {} + utils.setBuildTags(bsConfig, args); + expect(bsConfig.run_settings.build_tag).to.be.eq("1234"); + }); + + it('should set undefined if args and bstack json caps not passed', () => { + let bsConfig = { + run_settings: {} + } + + let args = {} + utils.setBuildTags(bsConfig, args); + expect(bsConfig.run_settings.build_tag).to.be.eq(undefined); + }); + }); + describe('getMajorVersion', () => { it('should return null if undefined version is sent', () => { expect(utils.getMajorVersion()).to.be.eql(null);