Skip to content

Commit 1498fab

Browse files
authored
Merge pull request #356 from roshan04/cypress_build_tags
Cypress build tags
2 parents ed58e18 + 76edc35 commit 1498fab

File tree

6 files changed

+91
-4
lines changed

6 files changed

+91
-4
lines changed

bin/commands/runs.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,8 @@ module.exports = function run(args, rawArgs) {
9797
// set record feature caps
9898
utils.setRecordCaps(bsConfig, args);
9999

100+
// set build tag caps
101+
utils.setBuildTags(bsConfig, args);
100102
// set node version
101103
utils.setNodeVersion(bsConfig, args);
102104

bin/helpers/constants.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,8 @@ const cliMessages = {
153153
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.",
154154
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",
155155
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.",
156-
NODE_VERSION: "Pass the node version that you want BrowserStack to use to run your Cypress tests on."
156+
NODE_VERSION: "Pass the node version that you want BrowserStack to use to run your Cypress tests on.",
157+
BUILD_TAG: "Add a tag to your build to filter builds based on tag values on the Dashboard."
157158
},
158159
COMMON: {
159160
DISABLE_USAGE_REPORTING: "Disable usage reporting",

bin/helpers/utils.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -444,6 +444,20 @@ exports.setTestEnvs = (bsConfig, args) => {
444444
logger.debug(`Setting env vars = ${bsConfig.run_settings.env}`);
445445
}
446446

447+
exports.setBuildTags = (bsConfig, args) => {
448+
let buildTag = undefined;
449+
if(!this.isUndefined(args["build-tag"])) {
450+
buildTag = args["build-tag"];
451+
} else {
452+
buildTag = bsConfig.run_settings.build_tag;
453+
}
454+
if(!this.isUndefined(buildTag)) {
455+
buildTag = buildTag.toString();
456+
}
457+
bsConfig.run_settings.build_tag = buildTag;
458+
logger.debug(`Setting the build tag = ${bsConfig.run_settings.build_tag}`);
459+
};
460+
447461
exports.setSystemEnvs = (bsConfig) => {
448462
let envKeys = {};
449463

bin/runner.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,11 @@ var argv = yargs
271271
default: undefined,
272272
describe: Constants.cliMessages.RUN.NODE_VERSION,
273273
type: "string"
274+
},
275+
'build-tag': {
276+
default: undefined,
277+
describe: Constants.cliMessages.RUN.BUILD_TAG,
278+
type: "string"
274279
}
275280
})
276281
.help('help')

test/unit/bin/commands/runs.js

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ describe("runs", () => {
122122
setSpecTimeoutStub = sandbox.stub().returns(undefined);
123123
setRecordCapsStub = sandbox.stub().returns(undefined);
124124
setNodeVersionStub = sandbox.stub();
125+
setBuildTagsStub = sandbox.stub();
125126
});
126127

127128
afterEach(() => {
@@ -166,7 +167,8 @@ describe("runs", () => {
166167
setSpecTimeout: setSpecTimeoutStub,
167168
setRecordCaps: setRecordCapsStub,
168169
setDebugMode: setDebugModeStub,
169-
setNodeVersion: setNodeVersionStub
170+
setNodeVersion: setNodeVersionStub,
171+
setBuildTags: setBuildTagsStub
170172
},
171173
'../helpers/capabilityHelper': {
172174
validate: capabilityValidatorStub
@@ -215,6 +217,7 @@ describe("runs", () => {
215217
sinon.assert.calledOnce(getInitialDetailsStub);
216218
sinon.assert.calledOnce(setRecordCapsStub);
217219
sinon.assert.calledOnce(setNodeVersionStub);
220+
sinon.assert.calledOnce(setBuildTagsStub);
218221
sinon.assert.calledOnceWithExactly(
219222
sendUsageReportStub,
220223
bsConfig,
@@ -276,6 +279,7 @@ describe("runs", () => {
276279
setSpecTimeoutStub = sandbox.stub().returns(undefined);
277280
setRecordCapsStub = sandbox.stub().returns(undefined);
278281
setNodeVersionStub = sandbox.stub();
282+
setBuildTagsStub = sandbox.stub();
279283
});
280284

281285
afterEach(() => {
@@ -323,7 +327,8 @@ describe("runs", () => {
323327
setSpecTimeout: setSpecTimeoutStub,
324328
setRecordCaps: setRecordCapsStub,
325329
setDebugMode: setDebugModeStub,
326-
setNodeVersion: setNodeVersionStub
330+
setNodeVersion: setNodeVersionStub,
331+
setBuildTags: setBuildTagsStub
327332
},
328333
'../helpers/capabilityHelper': {
329334
validate: capabilityValidatorStub,
@@ -391,6 +396,7 @@ describe("runs", () => {
391396
sinon.assert.calledOnce(getInitialDetailsStub);
392397
sinon.assert.calledOnce(setRecordCapsStub);
393398
sinon.assert.calledOnce(setNodeVersionStub);
399+
sinon.assert.calledOnce(setBuildTagsStub);
394400
sinon.assert.calledOnceWithExactly(
395401
sendUsageReportStub,
396402
bsConfig,
@@ -454,6 +460,7 @@ describe("runs", () => {
454460
getInitialDetailsStub = sandbox.stub();
455461
setRecordCapsStub = sandbox.stub().returns(undefined);
456462
setNodeVersionStub = sandbox.stub();
463+
setBuildTagsStub = sandbox.stub();
457464
});
458465

459466
afterEach(() => {
@@ -502,7 +509,8 @@ describe("runs", () => {
502509
setSpecTimeout: setSpecTimeoutStub,
503510
setRecordCaps: setRecordCapsStub,
504511
setDebugMode: setDebugModeStub,
505-
setNodeVersion: setNodeVersionStub
512+
setNodeVersion: setNodeVersionStub,
513+
setBuildTags: setBuildTagsStub
506514
},
507515
'../helpers/capabilityHelper': {
508516
validate: capabilityValidatorStub,
@@ -572,6 +580,7 @@ describe("runs", () => {
572580
sinon.assert.calledOnce(getInitialDetailsStub);
573581
sinon.assert.calledOnce(setRecordCapsStub);
574582
sinon.assert.calledOnce(setNodeVersionStub);
583+
sinon.assert.calledOnce(setBuildTagsStub);
575584
sinon.assert.calledOnceWithExactly(
576585
sendUsageReportStub,
577586
bsConfig,
@@ -640,6 +649,7 @@ describe("runs", () => {
640649
getInitialDetailsStub = sandbox.stub();
641650
setRecordCapsStub = sandbox.stub().returns(undefined);
642651
setNodeVersionStub = sandbox.stub();
652+
setBuildTagsStub = sandbox.stub();
643653
});
644654

645655
afterEach(() => {
@@ -690,6 +700,7 @@ describe("runs", () => {
690700
setRecordCaps: setRecordCapsStub,
691701
setDebugMode: setDebugModeStub,
692702
setNodeVersion: setNodeVersionStub,
703+
setBuildTags: setBuildTagsStub
693704
},
694705
'../helpers/capabilityHelper': {
695706
validate: capabilityValidatorStub,
@@ -770,6 +781,7 @@ describe("runs", () => {
770781
sinon.assert.calledOnce(getInitialDetailsStub);
771782
sinon.assert.calledOnce(setRecordCapsStub);
772783
sinon.assert.calledOnce(setNodeVersionStub);
784+
sinon.assert.calledOnce(setBuildTagsStub);
773785

774786
sinon.assert.calledOnceWithExactly(
775787
sendUsageReportStub,
@@ -852,6 +864,7 @@ describe("runs", () => {
852864
getInitialDetailsStub = sandbox.stub();
853865
setRecordCapsStub = sandbox.stub().returns(undefined);
854866
setNodeVersionStub = sandbox.stub();
867+
setBuildTagsStub = sandbox.stub();
855868
});
856869

857870
afterEach(() => {
@@ -910,6 +923,7 @@ describe("runs", () => {
910923
setRecordCaps: setRecordCapsStub,
911924
setDebugMode: setDebugModeStub,
912925
setNodeVersion: setNodeVersionStub,
926+
setBuildTags: setBuildTagsStub
913927
},
914928
'../helpers/capabilityHelper': {
915929
validate: capabilityValidatorStub,
@@ -1006,6 +1020,7 @@ describe("runs", () => {
10061020
sinon.assert.calledOnce(getInitialDetailsStub);
10071021
sinon.assert.calledOnce(setRecordCapsStub);
10081022
sinon.assert.calledOnce(setNodeVersionStub);
1023+
sinon.assert.calledOnce(setBuildTagsStub);
10091024
sinon.assert.match(
10101025
sendUsageReportStub.getCall(0).args,
10111026
[

test/unit/bin/helpers/utils.js

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3379,6 +3379,56 @@ describe('utils', () => {
33793379
});
33803380
});
33813381

3382+
describe('setBuildTags', () => {
3383+
it('should give preference to args', () => {
3384+
let bsConfig = {
3385+
run_settings: {
3386+
build_tag: "abc"
3387+
}
3388+
}
3389+
3390+
let args = {
3391+
"build-tag": "def"
3392+
}
3393+
utils.setBuildTags(bsConfig, args);
3394+
expect(bsConfig.run_settings.build_tag).to.be.eq("def");
3395+
});
3396+
3397+
it('should honour bstack json if args not passed', () => {
3398+
let bsConfig = {
3399+
run_settings: {
3400+
build_tag: "abc"
3401+
}
3402+
}
3403+
3404+
let args = {}
3405+
utils.setBuildTags(bsConfig, args);
3406+
expect(bsConfig.run_settings.build_tag).to.be.eq("abc");
3407+
});
3408+
3409+
it('should convert values to string', () => {
3410+
let bsConfig = {
3411+
run_settings: {
3412+
build_tag: 1234
3413+
}
3414+
}
3415+
3416+
let args = {}
3417+
utils.setBuildTags(bsConfig, args);
3418+
expect(bsConfig.run_settings.build_tag).to.be.eq("1234");
3419+
});
3420+
3421+
it('should set undefined if args and bstack json caps not passed', () => {
3422+
let bsConfig = {
3423+
run_settings: {}
3424+
}
3425+
3426+
let args = {}
3427+
utils.setBuildTags(bsConfig, args);
3428+
expect(bsConfig.run_settings.build_tag).to.be.eq(undefined);
3429+
});
3430+
});
3431+
33823432
describe('getMajorVersion', () => {
33833433
it('should return null if undefined version is sent', () => {
33843434
expect(utils.getMajorVersion()).to.be.eql(null);

0 commit comments

Comments
 (0)