Skip to content

Commit 043e0fb

Browse files
committed
resolved conflicts
2 parents 2104e78 + 699ca7c commit 043e0fb

File tree

9 files changed

+284
-5
lines changed

9 files changed

+284
-5
lines changed

bin/commands/runs.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,9 @@ module.exports = function run(args, rawArgs) {
9494
// set the no-wrap
9595
utils.setNoWrap(bsConfig, args);
9696

97+
// set record feature caps
98+
utils.setRecordCaps(bsConfig, args);
99+
97100
//set browsers
98101
await utils.setBrowsers(bsConfig, args);
99102

bin/helpers/capabilityHelper.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,15 @@ const validate = (bsConfig, args) => {
245245
logger.warn(Constants.validationMessages.SPEC_TIMEOUT_NOT_PASSED_ERROR);
246246
}
247247

248+
if(!Utils.isUndefined(bsConfig.run_settings["record"]) && String(bsConfig.run_settings["record"]) == 'true') {
249+
if(Utils.isUndefined(bsConfig.run_settings.projectId) || bsConfig.run_settings.projectId == "" ) {
250+
logger.warn(Constants.validationMessages.PROJECT_ID_MISSING);
251+
}
252+
if (Utils.isUndefined(bsConfig.run_settings["record-key"]) || bsConfig.run_settings["record-key"] == "" ) {
253+
logger.warn(Constants.validationMessages.RECORD_KEY_MISSING);
254+
}
255+
}
256+
248257
resolve(cypressJson);
249258
});
250259
}

bin/helpers/constants.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,9 @@ const validationMessages = {
102102
HOME_DIRECTORY_NOT_A_DIRECTORY: "Specified home directory is not a directory. The home directory can only be a directory and not a file.",
103103
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.",
104104
SPEC_TIMEOUT_LIMIT_ERROR: "The maximum allowed value of 'spec_timeout' is 120. Read more on https://browserstack.com/docs/automate/cypress/spec-timeout ",
105-
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+
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 ",
106+
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",
107+
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"
106108
};
107109

108110
const cliMessages = {
@@ -146,7 +148,10 @@ const cliMessages = {
146148
REPORTER: "Specify the custom reporter to use",
147149
REPORTER_OPTIONS: "Specify reporter options for custom reporter",
148150
CYPRESS_GEO_LOCATION: "Enterprise feature to simulate website and mobile behavior from different locations.",
149-
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."
151+
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: "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.",
153+
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",
154+
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."
150155
},
151156
COMMON: {
152157
DISABLE_USAGE_REPORTING: "Disable usage reporting",

bin/helpers/usageReporting.js

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ const cp = require("child_process"),
88
const config = require('./config'),
99
fileLogger = require('./logger').fileLogger,
1010
utils = require('./utils');
11-
11+
1212
const { AUTH_REGEX, REDACTED_AUTH, REDACTED, CLI_ARGS_REGEX, RAW_ARGS_REGEX } = require("./constants");
1313

1414
function get_version(package_name) {
@@ -172,6 +172,27 @@ function isUsageReportingEnabled() {
172172
return process.env.DISABLE_USAGE_REPORTING;
173173
}
174174

175+
function redactBsConfig(bsConfig) {
176+
if(typeof bsConfig === 'object' && !utils.isUndefined(bsConfig.run_settings)) {
177+
if(!utils.isUndefined(bsConfig.run_settings["projectId"])) { bsConfig.run_settings["projectId"] = REDACTED }
178+
if(!utils.isUndefined(bsConfig.run_settings["record-key"])) { bsConfig.run_settings["record-key"] = REDACTED }
179+
}
180+
}
181+
182+
function redactArgs(args) {
183+
if(typeof args === 'object' && !utils.isUndefined(args.cli_args)) {
184+
if(!utils.isUndefined(args.cli_args["projectId"])) { args.cli_args["projectId"] = REDACTED }
185+
if(!utils.isUndefined(args.cli_args["project-id"])) { args.cli_args["project-id"] = REDACTED }
186+
if(!utils.isUndefined(args.cli_args["record-key"])) { args.cli_args["record-key"] = REDACTED }
187+
if(!utils.isUndefined(args.cli_args["recordKey"])) { args.cli_args["recordKey"] = REDACTED }
188+
}
189+
}
190+
191+
function redactRecordCaps(bsConfig, args) {
192+
redactBsConfig(bsConfig);
193+
redactArgs(args);
194+
}
195+
175196
function redactKeys(str, regex, redact) {
176197
return str.replace(regex, redact);
177198
}
@@ -183,8 +204,10 @@ function send(args) {
183204
let runSettings = "";
184205
let sanitizedbsConfig = "";
185206
let cli_details = cli_version_and_path(bsConfig);
186-
let data = utils.isUndefined(args.data) ? {} : args.data;
187207

208+
redactRecordCaps(bsConfig, args);
209+
210+
let data = utils.isUndefined(args.data) ? {} : args.data;
188211
if (bsConfig && bsConfig.run_settings) {
189212
runSettings = bsConfig.run_settings;
190213
data.cypress_version = bsConfig.run_settings.cypress_version;

bin/helpers/utils.js

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -336,6 +336,41 @@ exports.setSpecTimeout = (bsConfig, args) => {
336336
logger.debug(`Setting spec timeout = ${specTimeout}`);
337337
}
338338

339+
exports.setRecordFlag = (bsConfig, args) => {
340+
if(!this.isUndefined(args["record"])) {
341+
return true;
342+
}
343+
return bsConfig.run_settings["record"];
344+
}
345+
346+
exports.setRecordKeyFlag = (bsConfig, args) => {
347+
if(!this.isUndefined(args["record-key"])) {
348+
return args["record-key"];
349+
} else if (!this.isUndefined(process.env.CYPRESS_RECORD_KEY)) {
350+
return process.env.CYPRESS_RECORD_KEY;
351+
}
352+
return bsConfig.run_settings["record-key"];
353+
}
354+
355+
exports.setProjectId = (bsConfig, args) => {
356+
if(!this.isUndefined(args["projectId"])) {
357+
return args["projectId"];
358+
} else if(!this.isUndefined(process.env.CYPRESS_PROJECT_ID)) {
359+
return process.env.CYPRESS_PROJECT_ID;
360+
} else if(!this.isUndefined(bsConfig.run_settings["projectId"])) {
361+
return bsConfig.run_settings["projectId"];
362+
} else {
363+
let cypressJson = this.getCypressJSON(bsConfig);
364+
if (!this.isUndefined(cypressJson) && !this.isUndefined(cypressJson["projectId"])) { return cypressJson["projectId"]; }
365+
}
366+
}
367+
368+
exports.setRecordCaps = (bsConfig, args) => {
369+
bsConfig.run_settings["record"] = this.setRecordFlag(bsConfig, args);
370+
bsConfig.run_settings["record-key"] = this.setRecordKeyFlag(bsConfig, args);
371+
bsConfig.run_settings["projectId"] = this.setProjectId(bsConfig, args);
372+
}
373+
339374
// specs can be passed from bstack configuration file
340375
// specs can be passed via command line args as a string
341376
// command line args takes precedence over config

bin/runner.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,20 @@ var argv = yargs
252252
describe: Constants.cliMessages.RUN.REPORTER_OPTIONS,
253253
type: "string"
254254
},
255+
'record': {
256+
describe: Constants.cliMessages.RUN.RECORD,
257+
type: "boolean"
258+
},
259+
'record-key': {
260+
default: undefined,
261+
describe: Constants.cliMessages.RUN.RECORD_KEY,
262+
type: "string"
263+
},
264+
'projectId': {
265+
default: undefined,
266+
describe: Constants.cliMessages.RUN.PROJECT_ID,
267+
type: "string"
268+
}
255269
})
256270
.help('help')
257271
.wrap(null)

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "browserstack-cypress-cli",
3-
"version": "1.13.1",
3+
"version": "1.14.0",
44
"description": "BrowserStack Cypress CLI for Cypress integration with BrowserStack's remote devices.",
55
"main": "index.js",
66
"scripts": {

test/unit/bin/commands/runs.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ describe("runs", () => {
120120
setCLIModeStub = sandbox.stub();
121121
setGeolocationStub = sandbox.stub();
122122
setSpecTimeoutStub = sandbox.stub().returns(undefined);
123+
setRecordCapsStub = sandbox.stub().returns(undefined);
123124
});
124125

125126
afterEach(() => {
@@ -162,6 +163,7 @@ describe("runs", () => {
162163
setCLIMode: setCLIModeStub,
163164
setGeolocation: setGeolocationStub,
164165
setSpecTimeout: setSpecTimeoutStub,
166+
setRecordCaps: setRecordCapsStub,
165167
setDebugMode: setDebugModeStub
166168
},
167169
'../helpers/capabilityHelper': {
@@ -209,6 +211,7 @@ describe("runs", () => {
209211
sinon.assert.calledOnce(setGeolocationStub);
210212
sinon.assert.calledOnce(setSpecTimeoutStub);
211213
sinon.assert.calledOnce(getInitialDetailsStub);
214+
sinon.assert.calledOnce(setRecordCapsStub);
212215
sinon.assert.calledOnceWithExactly(
213216
sendUsageReportStub,
214217
bsConfig,
@@ -268,6 +271,7 @@ describe("runs", () => {
268271
getVideoConfigStub = sandbox.stub();
269272
getInitialDetailsStub = sandbox.stub();
270273
setSpecTimeoutStub = sandbox.stub().returns(undefined);
274+
setRecordCapsStub = sandbox.stub().returns(undefined);
271275
});
272276

273277
afterEach(() => {
@@ -313,6 +317,7 @@ describe("runs", () => {
313317
setGeolocation: setGeolocationStub,
314318
getVideoConfig: getVideoConfigStub,
315319
setSpecTimeout: setSpecTimeoutStub,
320+
setRecordCaps: setRecordCapsStub,
316321
setDebugMode: setDebugModeStub
317322
},
318323
'../helpers/capabilityHelper': {
@@ -379,6 +384,7 @@ describe("runs", () => {
379384
sinon.assert.calledOnce(setGeolocationStub);
380385
sinon.assert.calledOnce(setSpecTimeoutStub);
381386
sinon.assert.calledOnce(getInitialDetailsStub);
387+
sinon.assert.calledOnce(setRecordCapsStub);
382388
sinon.assert.calledOnceWithExactly(
383389
sendUsageReportStub,
384390
bsConfig,
@@ -440,6 +446,7 @@ describe("runs", () => {
440446
getVideoConfigStub = sandbox.stub();
441447
setSpecTimeoutStub = sandbox.stub().returns(undefined);
442448
getInitialDetailsStub = sandbox.stub();
449+
setRecordCapsStub = sandbox.stub().returns(undefined);
443450
});
444451

445452
afterEach(() => {
@@ -486,6 +493,7 @@ describe("runs", () => {
486493
setGeolocation: setGeolocationStub,
487494
getVideoConfig: getVideoConfigStub,
488495
setSpecTimeout: setSpecTimeoutStub,
496+
setRecordCaps: setRecordCapsStub,
489497
setDebugMode: setDebugModeStub
490498
},
491499
'../helpers/capabilityHelper': {
@@ -554,6 +562,7 @@ describe("runs", () => {
554562
sinon.assert.calledOnce(setGeolocationStub);
555563
sinon.assert.calledOnce(setSpecTimeoutStub);
556564
sinon.assert.calledOnce(getInitialDetailsStub);
565+
sinon.assert.calledOnce(setRecordCapsStub);
557566
sinon.assert.calledOnceWithExactly(
558567
sendUsageReportStub,
559568
bsConfig,
@@ -620,6 +629,7 @@ describe("runs", () => {
620629
getVideoConfigStub = sandbox.stub();
621630
setSpecTimeoutStub = sandbox.stub().returns(undefined);
622631
getInitialDetailsStub = sandbox.stub();
632+
setRecordCapsStub = sandbox.stub().returns(undefined);
623633
});
624634

625635
afterEach(() => {
@@ -667,6 +677,7 @@ describe("runs", () => {
667677
setGeolocation: setGeolocationStub,
668678
getVideoConfig: getVideoConfigStub,
669679
setSpecTimeout: setSpecTimeoutStub,
680+
setRecordCaps: setRecordCapsStub,
670681
setDebugMode: setDebugModeStub
671682
},
672683
'../helpers/capabilityHelper': {
@@ -746,6 +757,7 @@ describe("runs", () => {
746757
sinon.assert.calledOnce(setGeolocationStub);
747758
sinon.assert.calledOnce(setSpecTimeoutStub);
748759
sinon.assert.calledOnce(getInitialDetailsStub);
760+
sinon.assert.calledOnce(setRecordCapsStub);
749761
sinon.assert.calledOnceWithExactly(
750762
sendUsageReportStub,
751763
bsConfig,
@@ -825,6 +837,7 @@ describe("runs", () => {
825837
getVideoConfigStub = sandbox.stub();
826838
setSpecTimeoutStub = sandbox.stub().returns(undefined);
827839
getInitialDetailsStub = sandbox.stub();
840+
setRecordCapsStub = sandbox.stub().returns(undefined);
828841
});
829842

830843
afterEach(() => {
@@ -880,6 +893,7 @@ describe("runs", () => {
880893
setGeolocation: setGeolocationStub,
881894
getVideoConfig: getVideoConfigStub,
882895
setSpecTimeout: setSpecTimeoutStub,
896+
setRecordCaps: setRecordCapsStub,
883897
setDebugMode: setDebugModeStub
884898
},
885899
'../helpers/capabilityHelper': {
@@ -975,6 +989,7 @@ describe("runs", () => {
975989
sinon.assert.calledOnce(setSystemEnvsStub);
976990
sinon.assert.calledOnce(setGeolocationStub);
977991
sinon.assert.calledOnce(getInitialDetailsStub);
992+
sinon.assert.calledOnce(setRecordCapsStub);
978993
sinon.assert.match(
979994
sendUsageReportStub.getCall(0).args,
980995
[

0 commit comments

Comments
 (0)