Skip to content

Cypress build tags #356

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 7 commits into from
Jul 27, 2022
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
2 changes: 2 additions & 0 deletions bin/commands/runs.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
3 changes: 2 additions & 1 deletion bin/helpers/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
14 changes: 14 additions & 0 deletions bin/helpers/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {};

Expand Down
5 changes: 5 additions & 0 deletions bin/runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
21 changes: 18 additions & 3 deletions test/unit/bin/commands/runs.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ describe("runs", () => {
setSpecTimeoutStub = sandbox.stub().returns(undefined);
setRecordCapsStub = sandbox.stub().returns(undefined);
setNodeVersionStub = sandbox.stub();
setBuildTagsStub = sandbox.stub();
});

afterEach(() => {
Expand Down Expand Up @@ -166,7 +167,8 @@ describe("runs", () => {
setSpecTimeout: setSpecTimeoutStub,
setRecordCaps: setRecordCapsStub,
setDebugMode: setDebugModeStub,
setNodeVersion: setNodeVersionStub
setNodeVersion: setNodeVersionStub,
setBuildTags: setBuildTagsStub
},
'../helpers/capabilityHelper': {
validate: capabilityValidatorStub
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -276,6 +279,7 @@ describe("runs", () => {
setSpecTimeoutStub = sandbox.stub().returns(undefined);
setRecordCapsStub = sandbox.stub().returns(undefined);
setNodeVersionStub = sandbox.stub();
setBuildTagsStub = sandbox.stub();
});

afterEach(() => {
Expand Down Expand Up @@ -323,7 +327,8 @@ describe("runs", () => {
setSpecTimeout: setSpecTimeoutStub,
setRecordCaps: setRecordCapsStub,
setDebugMode: setDebugModeStub,
setNodeVersion: setNodeVersionStub
setNodeVersion: setNodeVersionStub,
setBuildTags: setBuildTagsStub
},
'../helpers/capabilityHelper': {
validate: capabilityValidatorStub,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -454,6 +460,7 @@ describe("runs", () => {
getInitialDetailsStub = sandbox.stub();
setRecordCapsStub = sandbox.stub().returns(undefined);
setNodeVersionStub = sandbox.stub();
setBuildTagsStub = sandbox.stub();
});

afterEach(() => {
Expand Down Expand Up @@ -502,7 +509,8 @@ describe("runs", () => {
setSpecTimeout: setSpecTimeoutStub,
setRecordCaps: setRecordCapsStub,
setDebugMode: setDebugModeStub,
setNodeVersion: setNodeVersionStub
setNodeVersion: setNodeVersionStub,
setBuildTags: setBuildTagsStub
},
'../helpers/capabilityHelper': {
validate: capabilityValidatorStub,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -640,6 +649,7 @@ describe("runs", () => {
getInitialDetailsStub = sandbox.stub();
setRecordCapsStub = sandbox.stub().returns(undefined);
setNodeVersionStub = sandbox.stub();
setBuildTagsStub = sandbox.stub();
});

afterEach(() => {
Expand Down Expand Up @@ -690,6 +700,7 @@ describe("runs", () => {
setRecordCaps: setRecordCapsStub,
setDebugMode: setDebugModeStub,
setNodeVersion: setNodeVersionStub,
setBuildTags: setBuildTagsStub
},
'../helpers/capabilityHelper': {
validate: capabilityValidatorStub,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -852,6 +864,7 @@ describe("runs", () => {
getInitialDetailsStub = sandbox.stub();
setRecordCapsStub = sandbox.stub().returns(undefined);
setNodeVersionStub = sandbox.stub();
setBuildTagsStub = sandbox.stub();
});

afterEach(() => {
Expand Down Expand Up @@ -910,6 +923,7 @@ describe("runs", () => {
setRecordCaps: setRecordCapsStub,
setDebugMode: setDebugModeStub,
setNodeVersion: setNodeVersionStub,
setBuildTags: setBuildTagsStub
},
'../helpers/capabilityHelper': {
validate: capabilityValidatorStub,
Expand Down Expand Up @@ -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,
[
Expand Down
50 changes: 50 additions & 0 deletions test/unit/bin/helpers/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down