Skip to content

Commit efaeef2

Browse files
committed
updated rspecs
1 parent 82399ad commit efaeef2

File tree

6 files changed

+193
-19
lines changed

6 files changed

+193
-19
lines changed

bin/helpers/capabilityHelper.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -241,12 +241,12 @@ const validate = (bsConfig, args) => {
241241
logger.warn(Constants.validationMessages.SPEC_TIMEOUT_NOT_PASSED_ERROR);
242242
}
243243

244-
if(Utils.isUndefined(bsConfig.run_settings.projectId)) {
245-
reject(Constants.validationMessages.PROJECT_ID_MISSING);
246-
} else if (Utils.isUndefined(bsConfig.run_settings["record"]) || bsConfig.run_settings["record"].toString() == "false") {
247-
logger.warn(Constants.validationMessages.RECORD_MISSING);
248-
} else if (Utils.isUndefined(bsConfig.run_settings["record-key"])) {
249-
logger.warn(Constants.validationMessages.RECORD_KEY_MISSING);
244+
if(!Utils.isUndefined(bsConfig.run_settings["record"])) {
245+
if(Utils.isUndefined(bsConfig.run_settings.projectId)) {
246+
logger.warn(Constants.validationMessages.PROJECT_ID_MISSING);
247+
} else if (Utils.isUndefined(bsConfig.run_settings["record-key"])) {
248+
logger.warn(Constants.validationMessages.RECORD_KEY_MISSING);
249+
}
250250
}
251251

252252
resolve(cypressJson);

bin/helpers/constants.js

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -102,9 +102,8 @@ const validationMessages = {
102102
CYPRESS_CONFIG_FILE_NOT_PART_OF_HOME_DIRECTORY: "Could not find cypress.json within the specified home directory. Please make sure cypress.json resides within the home directory.",
103103
SPEC_TIMEOUT_LIMIT_ERROR: "The maximum allowed value of 'spec_timeout' is 120. Read more on https://browserstack.com/docs/automate/cypress/spec-timeout ",
104104
SPEC_TIMEOUT_NOT_PASSED_ERROR: "'spec_timeout' key not specified. Going ahead with 30 mins as the default spec timeout. Read more about how to specify the option in https://browserstack.com/docs/automate/cypress/spec-timeout ",
105-
PROJECT_ID_MISSING: "You passed the --record flag but this project has not been setup to record. This project is missing the 'projectId' inside of 'cypress.json'. We cannot uniquely identify this project without this id. You need to setup this project to record. This will generate a unique 'projectId'. Alternatively if you omit the --record flag this project will run without recording. https://on.cypress.io/recording-project-runs",
106-
RECORD_KEY_MISSING: "You have specified '--record' flag but you've not provided the '--record-key' and we could not find any value in 'CYPRESS_RECORD_KEY' environment variable. Your record functionality on cypress.io dashboard might not work as it needs the key and projectId",
107-
RECORD_MISSING: "You have not specified '--record' flag. Your record functionality on cypress.io dashboard might not work."
105+
PROJECT_ID_MISSING: "You have specified '--record' flag but you've not provided the 'projectId' in cypress.json or in browserstack.json. Your record functionality on cypress.io dashboard might not work as it needs both the key and the projectId",
106+
RECORD_KEY_MISSING: "You have specified '--record' flag but you've not provided the '--record-key' and we could not find any value in 'CYPRESS_RECORD_KEY' environment variable. Your record functionality on cypress.io dashboard might not work as it needs the key and projectId"
108107
};
109108

110109
const cliMessages = {
@@ -149,9 +148,9 @@ const cliMessages = {
149148
REPORTER_OPTIONS: "Specify reporter options for custom reporter",
150149
CYPRESS_GEO_LOCATION: "Enterprise feature to simulate website and mobile behavior from different locations.",
151150
SPEC_TIMEOUT: "Specify a value for a hard timeout for each spec execution in the 1-120 mins range. Read https://browserstack.com/docs/automate/cypress/spec-timeout for more details.",
152-
RECORD: "Run your tests with record functionality on cypress.io dashboard",
153-
RECORD_KEY: "Specify a value for record key.",
154-
PROJECT_ID: "Specify a value for project id."
151+
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.",
152+
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",
153+
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."
155154
},
156155
COMMON: {
157156
DISABLE_USAGE_REPORTING: "Disable usage reporting",

bin/helpers/utils.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -346,11 +346,12 @@ exports.setRecordKeyFlag = (bsConfig, args) => {
346346
exports.setProjectId = (bsConfig, args) => {
347347
if(!this.isUndefined(args["projectId"])) {
348348
return args["projectId"];
349+
} else if(!this.isUndefined(bsConfig.run_settings["projectId"])) {
350+
return bsConfig.run_settings["projectId"];
349351
} else {
350352
let cypressJson = this.getCypressJSON(bsConfig);
351353
if (!this.isUndefined(cypressJson) && !this.isUndefined(cypressJson["projectId"])) { return cypressJson["projectId"]; }
352354
}
353-
return bsConfig.run_settings["projectId"];
354355
}
355356

356357
exports.setRecordCaps = (bsConfig, args) => {

bin/runner.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,6 @@ var argv = yargs
244244
type: "string"
245245
},
246246
'record': {
247-
default: false,
248247
describe: Constants.cliMessages.RUN.RECORD,
249248
type: "boolean"
250249
},

test/unit/bin/commands/runs.js

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ describe("runs", () => {
117117
setCLIModeStub = sandbox.stub();
118118
setGeolocationStub = sandbox.stub();
119119
setSpecTimeoutStub = sandbox.stub().returns(undefined);
120+
setRecordCapsStub = sandbox.stub().returns(undefined);
120121
});
121122

122123
afterEach(() => {
@@ -158,7 +159,8 @@ describe("runs", () => {
158159
setConfig: setConfigStub,
159160
setCLIMode: setCLIModeStub,
160161
setGeolocation: setGeolocationStub,
161-
setSpecTimeout: setSpecTimeoutStub
162+
setSpecTimeout: setSpecTimeoutStub,
163+
setRecordCaps: setRecordCapsStub
162164
},
163165
'../helpers/capabilityHelper': {
164166
validate: capabilityValidatorStub
@@ -200,6 +202,7 @@ describe("runs", () => {
200202
sinon.assert.calledOnce(setUsageReportingFlagStub);
201203
sinon.assert.calledOnce(setGeolocationStub);
202204
sinon.assert.calledOnce(setSpecTimeoutStub);
205+
sinon.assert.calledOnce(setRecordCapsStub);
203206
sinon.assert.calledOnceWithExactly(
204207
sendUsageReportStub,
205208
bsConfig,
@@ -258,6 +261,7 @@ describe("runs", () => {
258261
setGeolocationStub = sandbox.stub();
259262
getVideoConfigStub = sandbox.stub();
260263
setSpecTimeoutStub = sandbox.stub().returns(undefined);
264+
setRecordCapsStub = sandbox.stub().returns(undefined);
261265
});
262266

263267
afterEach(() => {
@@ -302,7 +306,8 @@ describe("runs", () => {
302306
setCLIMode: setCLIModeStub,
303307
setGeolocation: setGeolocationStub,
304308
getVideoConfig: getVideoConfigStub,
305-
setSpecTimeout: setSpecTimeoutStub
309+
setSpecTimeout: setSpecTimeoutStub,
310+
setRecordCaps: setRecordCapsStub
306311
},
307312
'../helpers/capabilityHelper': {
308313
validate: capabilityValidatorStub,
@@ -363,6 +368,7 @@ describe("runs", () => {
363368
sinon.assert.calledOnce(setSystemEnvsStub);
364369
sinon.assert.calledOnce(setGeolocationStub);
365370
sinon.assert.calledOnce(setSpecTimeoutStub);
371+
sinon.assert.calledOnce(setRecordCapsStub);
366372
sinon.assert.calledOnceWithExactly(
367373
sendUsageReportStub,
368374
bsConfig,
@@ -423,6 +429,7 @@ describe("runs", () => {
423429
setGeolocationStub = sandbox.stub();
424430
getVideoConfigStub = sandbox.stub();
425431
setSpecTimeoutStub = sandbox.stub().returns(undefined);
432+
setRecordCapsStub = sandbox.stub().returns(undefined);
426433
});
427434

428435
afterEach(() => {
@@ -468,7 +475,8 @@ describe("runs", () => {
468475
fetchZipSize: fetchZipSizeStub,
469476
setGeolocation: setGeolocationStub,
470477
getVideoConfig: getVideoConfigStub,
471-
setSpecTimeout: setSpecTimeoutStub
478+
setSpecTimeout: setSpecTimeoutStub,
479+
setRecordCaps: setRecordCapsStub
472480
},
473481
'../helpers/capabilityHelper': {
474482
validate: capabilityValidatorStub,
@@ -531,6 +539,7 @@ describe("runs", () => {
531539
sinon.assert.calledOnce(setSystemEnvsStub);
532540
sinon.assert.calledOnce(setGeolocationStub);
533541
sinon.assert.calledOnce(setSpecTimeoutStub);
542+
sinon.assert.calledOnce(setRecordCapsStub);
534543
sinon.assert.calledOnceWithExactly(
535544
sendUsageReportStub,
536545
bsConfig,
@@ -596,6 +605,7 @@ describe("runs", () => {
596605
setGeolocationStub = sandbox.stub();
597606
getVideoConfigStub = sandbox.stub();
598607
setSpecTimeoutStub = sandbox.stub().returns(undefined);
608+
setRecordCapsStub = sandbox.stub().returns(undefined);
599609
});
600610

601611
afterEach(() => {
@@ -642,7 +652,8 @@ describe("runs", () => {
642652
fetchZipSize: fetchZipSizeStub,
643653
setGeolocation: setGeolocationStub,
644654
getVideoConfig: getVideoConfigStub,
645-
setSpecTimeout: setSpecTimeoutStub
655+
setSpecTimeout: setSpecTimeoutStub,
656+
setRecordCaps: setRecordCapsStub
646657
},
647658
'../helpers/capabilityHelper': {
648659
validate: capabilityValidatorStub,
@@ -716,6 +727,7 @@ describe("runs", () => {
716727
sinon.assert.calledOnce(setSystemEnvsStub);
717728
sinon.assert.calledOnce(setGeolocationStub);
718729
sinon.assert.calledOnce(setSpecTimeoutStub);
730+
sinon.assert.calledOnce(setRecordCapsStub);
719731

720732
sinon.assert.calledOnceWithExactly(
721733
sendUsageReportStub,
@@ -795,6 +807,7 @@ describe("runs", () => {
795807
setGeolocationStub = sandbox.stub();
796808
getVideoConfigStub = sandbox.stub();
797809
setSpecTimeoutStub = sandbox.stub().returns(undefined);
810+
setRecordCapsStub = sandbox.stub().returns(undefined);
798811
});
799812

800813
afterEach(() => {
@@ -849,7 +862,8 @@ describe("runs", () => {
849862
fetchZipSize: fetchZipSizeStub,
850863
setGeolocation: setGeolocationStub,
851864
getVideoConfig: getVideoConfigStub,
852-
setSpecTimeout: setSpecTimeoutStub
865+
setSpecTimeout: setSpecTimeoutStub,
866+
setRecordCaps: setRecordCapsStub
853867
},
854868
'../helpers/capabilityHelper': {
855869
validate: capabilityValidatorStub,
@@ -939,6 +953,7 @@ describe("runs", () => {
939953
sinon.assert.calledOnce(setDefaultsStub);
940954
sinon.assert.calledOnce(setSystemEnvsStub);
941955
sinon.assert.calledOnce(setGeolocationStub);
956+
sinon.assert.calledOnce(setRecordCapsStub);
942957
sinon.assert.match(
943958
sendUsageReportStub.getCall(0).args,
944959
[

test/unit/bin/helpers/utils.js

Lines changed: 160 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2947,6 +2947,166 @@ describe('utils', () => {
29472947
});
29482948
});
29492949

2950+
2951+
describe("#setRecordKeyFlag", () => {
2952+
it("the value of args record-key is given preference", () => {
2953+
let bsConfig = {
2954+
run_settings: {
2955+
"record-key": "abc"
2956+
}
2957+
}
2958+
let args = {
2959+
"record-key": "def"
2960+
}
2961+
process.env.CYPRESS_RECORD_KEY = "ghi"
2962+
expect(utils.setRecordKeyFlag(bsConfig, args)).to.eq("def")
2963+
delete process.env.CYPRESS_RECORD_KEY;
2964+
});
2965+
2966+
it("prioritizes env vars over bsconfig", () => {
2967+
let bsConfig = {
2968+
run_settings: {
2969+
"record-key": "abc"
2970+
}
2971+
};
2972+
let args = {}
2973+
process.env.CYPRESS_RECORD_KEY = "ghi"
2974+
expect(utils.setRecordKeyFlag(bsConfig, args)).to.eq("ghi")
2975+
delete process.env.CYPRESS_RECORD_KEY;
2976+
});
2977+
2978+
it("set bsconfig values if env is not set and args flag is not passed", () => {
2979+
let bsConfig = {
2980+
run_settings: {
2981+
"record-key": "abc"
2982+
}
2983+
}
2984+
let args = {}
2985+
expect(utils.setRecordKeyFlag(bsConfig, args)).to.eq("abc")
2986+
});
2987+
2988+
it("returns undefined is nothing is specified", () => {
2989+
let bsConfig = { run_settings: {} };
2990+
let args = {};
2991+
expect(utils.setRecordKeyFlag(bsConfig, args)).to.eq(undefined)
2992+
});
2993+
});
2994+
2995+
describe("#setRecordFlag", () => {
2996+
it("returns true if record set in args", () => {
2997+
let bsConfig = {
2998+
run_settings: {}
2999+
};
3000+
let args = {
3001+
record: true
3002+
};
3003+
expect(utils.setRecordFlag(bsConfig, args)).to.eq(true);
3004+
});
3005+
3006+
it("returns true if not passed in args but set in bsConfig", () => {
3007+
let bsConfig = {
3008+
run_settings: {
3009+
record: true
3010+
}
3011+
};
3012+
let args = {};
3013+
expect(utils.setRecordFlag(bsConfig, args)).to.eq(true);
3014+
});
3015+
3016+
it("returns undefined when not set in args and the bsConfig", () => {
3017+
let bsConfig = {
3018+
run_settings: {}
3019+
};
3020+
let args = {};
3021+
expect(utils.setRecordFlag(bsConfig, args)).to.eq(undefined);
3022+
});
3023+
});
3024+
3025+
describe("#setProjectId", () => {
3026+
let getCypressJSONStub;
3027+
beforeEach(() => {
3028+
getCypressJSONStub = sinon.stub(utils, 'getCypressJSON');
3029+
});
3030+
3031+
afterEach(() => {
3032+
getCypressJSONStub.restore();
3033+
});
3034+
3035+
it("prioritizes projectId passed in the args", () => {
3036+
let bsConfig = {
3037+
run_settings: {
3038+
projectId: "abc"
3039+
}
3040+
}
3041+
let args = {
3042+
projectId: "def"
3043+
}
3044+
getCypressJSONStub.returns({ projectId: "ghi" })
3045+
expect(utils.setProjectId(bsConfig, args)).to.eq("def")
3046+
});
3047+
3048+
it("prioritizes projectId passed in the bsConfig if args not passed", () => {
3049+
let bsConfig = {
3050+
run_settings: {
3051+
projectId: "abc"
3052+
}
3053+
}
3054+
let args = {};
3055+
getCypressJSONStub.returns({ projectId: "ghi" })
3056+
expect(utils.setProjectId(bsConfig, args)).to.eq("abc")
3057+
});
3058+
3059+
it("prioritizes projectId passed in cypress json when no args and bsConfig is passed", () => {
3060+
let bsConfig = {
3061+
run_settings: {}
3062+
}
3063+
let args = {}
3064+
getCypressJSONStub.returns({ projectId: "ghi" })
3065+
expect(utils.setProjectId(bsConfig, args)).to.eq("ghi")
3066+
});
3067+
3068+
it("returns undefined when nothing is passed", () => {
3069+
let bsConfig = {
3070+
run_settings: {}
3071+
}
3072+
let args = {}
3073+
getCypressJSONStub.returns({})
3074+
expect(utils.setProjectId(bsConfig, args)).to.eq(undefined)
3075+
});
3076+
});
3077+
3078+
describe("#setRecordCaps", () => {
3079+
let setRecordFlagStub, setRecordKeyFlagStub, setProjectIdStub;
3080+
beforeEach(() => {
3081+
setRecordFlagStub = sinon.stub(utils, 'setRecordFlag');
3082+
setRecordKeyFlagStub = sinon.stub(utils, 'setRecordKeyFlag');
3083+
setProjectIdStub = sinon.stub(utils, 'setProjectId');
3084+
});
3085+
3086+
afterEach(() => {
3087+
setRecordFlagStub.restore();
3088+
setRecordKeyFlagStub.restore();
3089+
setProjectIdStub.restore();
3090+
});
3091+
3092+
it("sets the bsConfig runsetting params to values passed by the setRecordFlag, setRecordKeyFlag and setProjectId", () => {
3093+
setRecordFlagStub.returns(true);
3094+
setRecordKeyFlagStub.returns("def");
3095+
setProjectIdStub.returns("ghi");
3096+
let bsConfig = {
3097+
run_settings: {}
3098+
};
3099+
let args = {};
3100+
let expectedRespone = {
3101+
"record": true,
3102+
"record-key": "def",
3103+
"projectId": "ghi"
3104+
};
3105+
utils.setRecordCaps(bsConfig, args);
3106+
expect(JSON.stringify(bsConfig.run_settings)).to.eq(JSON.stringify(expectedRespone));
3107+
})
3108+
})
3109+
29503110
describe("setSpecTimeout", () => {
29513111
let isSpecTimeoutArgPassedStub;
29523112
beforeEach(() => {

0 commit comments

Comments
 (0)