Skip to content

Commit fab5b00

Browse files
Spec addition
1 parent 6c20b8b commit fab5b00

File tree

6 files changed

+126
-9
lines changed

6 files changed

+126
-9
lines changed

bin/helpers/constants.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,8 @@ const userMessages = {
7474
"Skipping Cypress Config Install as the enforce_settings has been passed.",
7575
SKIP_UPLOADING_TESTS:
7676
"Skipping zip upload since BrowserStack already has your test suite that has not changed since the last run.",
77+
SKIP_NPM_INSTALL:
78+
"Skipping NPM Install as the enforce_settings has been passed.",
7779
SKIP_UPLOADING_NPM_PACKAGES:
7880
"Skipping the upload of node_modules since BrowserStack has already cached your npm dependencies that have not changed since the last run.",
7981
LOCAL_TRUE: "you will now be able to test localhost / private URLs",
@@ -137,7 +139,7 @@ const validationMessages = {
137139
EMPTY_CYPRESS_CONFIG_FILE:
138140
"cypress_config_file is not set in run_settings. See https://www.browserstack.com/docs/automate/cypress/configuration-file to learn more.",
139141
EMPTY_SPECS_IN_BROWSERSTACK_JSON:
140-
"No specs have been provided in run_settings. It is required to be passed on browserstack.json if enforce_settings is set.",
142+
"specs is required when enforce_settings is true in run_settings of browserstack.json",
141143
VALIDATED: "browserstack.json file is validated",
142144
NOT_VALID: "browerstack.json is not valid",
143145
NOT_VALID_JSON: "browerstack.json is not a valid json",

bin/helpers/packageInstaller.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,8 @@ const packageSetupAndInstaller = (bsConfig, packageDir, instrumentBlocks) => {
134134
packagesInstalled: false
135135
};
136136
if (bsConfig && bsConfig.run_settings && bsConfig.run_settings.enforce_settings && bsConfig.run_settings.enforce_settings.toString() === 'true' ) {
137-
logger.info(Constants.userMessages.SKIP_NPM_INSTALL);
137+
logger.info("Enforce_settings is enabled in run_settings");
138+
logger.debug(Constants.userMessages.SKIP_NPM_INSTALL);
138139
return resolve(obj);
139140
}
140141
logger.info(Constants.userMessages.NPM_INSTALL);

bin/helpers/utils.js

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -434,7 +434,8 @@ exports.setProjectId = (bsConfig, args, cypressConfigFile) => {
434434
} else if(!this.isUndefined(bsConfig.run_settings["projectId"])) {
435435
return bsConfig.run_settings["projectId"];
436436
} else {
437-
if (!this.isUndefined(cypressConfigFile) && !this.isUndefined(cypressConfigFile["projectId"])) {
437+
// ignore reading cypressconfig if enforce_settings is passed
438+
if (this.isUndefinedOrFalse(bsConfig.run_settings.enforce_settings) && !this.isUndefined(cypressConfigFile) && !this.isUndefined(cypressConfigFile["projectId"])) {
438439
return cypressConfigFile["projectId"];
439440
}
440441
}
@@ -1298,11 +1299,19 @@ exports.setEnforceSettingsConfig = (bsConfig) => {
12981299
config_args = this.isUndefined(config_args) ? video_args : config_args + ',' + video_args;
12991300
logger.debug(`Setting video_args for enforce_settings to ${video_args}`);
13001301
}
1301-
if ( this.isUndefined(config_args) || !config_args.includes("baseUrl") ) {
1302-
let base_url_args = (!this.isUndefined(bsConfig) && !this.isUndefined(bsConfig.run_settings) && !this.isUndefined(bsConfig.run_settings.config)) ? "baseUrl='"+bsConfig.run_settings.baseUrl+"'" : "baseUrl=''";
1302+
if ( (!this.isUndefined(bsConfig) && !this.isUndefined(bsConfig.run_settings) && !this.isUndefined(bsConfig.run_settings.baseUrl)) && (this.isUndefined(config_args) || !config_args.includes("baseUrl")) ) {
1303+
let base_url_args = 'baseUrl='+bsConfig.run_settings.baseUrl;
13031304
config_args = this.isUndefined(config_args) ? base_url_args : config_args + ',' + base_url_args;
13041305
logger.debug(`Setting base_url_args for enforce_settings to ${base_url_args}`);
13051306
}
1307+
// set specs in config of specpattern to override cypress config
1308+
if(!this.isUndefined(bsConfig) && !this.isUndefined(bsConfig.run_settings) && !this.isUndefined(bsConfig.run_settings.specs)) {
1309+
let spec_pattern_args = "specPattern='"+bsConfig.run_settings.specs+"'";
1310+
if( bsConfig.run_settings.cypressTestSuiteType !== Constants.CYPRESS_V10_AND_ABOVE_TYPE) {
1311+
spec_pattern_args = "testFiles='"+bsConfig.run_settings.specs+"'";
1312+
}
1313+
config_args = this.isUndefined(config_args) ? spec_pattern_args : config_args + ',' + spec_pattern_args;
1314+
}
13061315
if ( !this.isUndefined(config_args) ) bsConfig["run_settings"]["config"] = config_args;
13071316
logger.debug(`Setting conifg_args for enforce_settings to ${config_args}`);
13081317
}
@@ -1526,10 +1535,12 @@ exports.getVideoConfig = (cypressConfig, bsConfig = {}) => {
15261535
videoUploadOnPasses: true
15271536
}
15281537
// Reading from bsconfig first to give precedance and cypress config will be empty in case of enforce_settings
1529-
if (!this.isUndefined(bsConfig.run_settings.video)) conf.video = bsConfig.run_settings.video;
1530-
if (!this.isUndefined(bsConfig.run_settings.videoUploadOnPasses)) conf.videoUploadOnPasses = bsConfig.run_settings.videoUploadOnPasses;
1531-
if (!this.isUndefined(cypressConfig.video)) conf.video = cypressConfig.video;
1532-
if (!this.isUndefined(cypressConfig.videoUploadOnPasses)) conf.videoUploadOnPasses = cypressConfig.videoUploadOnPasses;
1538+
if (!this.isUndefined(bsConfig.run_settings) && !this.isUndefined(bsConfig.run_settings.video)) conf.video = bsConfig.run_settings.video;
1539+
if (!this.isUndefined(bsConfig.run_settings) && !this.isUndefined(bsConfig.run_settings.videoUploadOnPasses)) conf.videoUploadOnPasses = bsConfig.run_settings.videoUploadOnPasses;
1540+
if ( this.isUndefined(bsConfig.run_settings) || this.isUndefined(bsConfig.run_settings.enforce_settings) ) {
1541+
if (!this.isUndefined(cypressConfig.video)) conf.video = cypressConfig.video;
1542+
if (!this.isUndefined(cypressConfig.videoUploadOnPasses)) conf.videoUploadOnPasses = cypressConfig.videoUploadOnPasses;
1543+
}
15331544

15341545
logger.debug(`Setting video = ${conf.video}`);
15351546
logger.debug(`Setting videoUploadOnPasses = ${conf.videoUploadOnPasses}`);

test/unit/bin/commands/runs.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -713,6 +713,8 @@ describe("runs", () => {
713713
stopLocalBinaryStub = sandbox.stub();
714714
setLocalConfigFileStub = sandbox.stub();
715715
setConfigStub = sandbox.stub();
716+
setEnforceSettingsConfigStub = sandbox.stub();
717+
isUndefinedOrFalseStub = sandbox.stub();
716718
setBrowsersStub = sandbox.stub();
717719
setCLIModeStub = sandbox.stub();
718720
fetchZipSizeStub = sandbox.stub();
@@ -773,6 +775,8 @@ describe("runs", () => {
773775
setLocalConfigFile: setLocalConfigFileStub,
774776
setBrowsers: setBrowsersStub,
775777
setConfig: setConfigStub,
778+
setEnforceSettingsConfig: setEnforceSettingsConfigStub,
779+
isUndefinedOrFalse: isUndefinedOrFalseStub,
776780
setCLIMode: setCLIModeStub,
777781
fetchZipSize: fetchZipSizeStub,
778782
setGeolocation: setGeolocationStub,
@@ -882,6 +886,7 @@ describe("runs", () => {
882886
sinon.assert.calledTwice(fetchZipSizeStub);
883887
sinon.assert.calledOnce(fetchFolderSizeStub);
884888
sinon.assert.calledOnce(zipUploadStub);
889+
sinon.assert.calledOnce(isUndefinedOrFalseStub);
885890
sinon.assert.calledOnce(createBuildStub);
886891
sinon.assert.calledOnce(stopLocalBinaryStub);
887892
sinon.assert.calledOnceWithExactly(
@@ -939,6 +944,7 @@ describe("runs", () => {
939944
deleteResultsStub = sandbox.stub();
940945
setDefaultsStub = sandbox.stub();
941946
isUndefinedStub = sandbox.stub();
947+
isUndefinedOrFalseStub = sandbox.stub();
942948
setLocalStub = sandbox.stub();
943949
setLocalModeStub = sandbox.stub();
944950
setupLocalTestingStub = sandbox.stub();
@@ -954,6 +960,7 @@ describe("runs", () => {
954960
markBlockStartStub = sandbox.stub();
955961
markBlockEndStub = sandbox.stub();
956962
setConfigStub = sandbox.stub();
963+
setEnforceSettingsConfigStub = sandbox.stub();
957964
setBrowsersStub = sandbox.stub();
958965
stopLocalBinaryStub = sandbox.stub();
959966
nonEmptyArrayStub = sandbox.stub();
@@ -1021,6 +1028,8 @@ describe("runs", () => {
10211028
setLocalConfigFile: setLocalConfigFileStub,
10221029
setBrowsers: setBrowsersStub,
10231030
setConfig: setConfigStub,
1031+
setEnforceSettingsConfig: setEnforceSettingsConfigStub,
1032+
isUndefinedOrFalse: isUndefinedOrFalseStub,
10241033
stopLocalBinary: stopLocalBinaryStub,
10251034
nonEmptyArray: nonEmptyArrayStub,
10261035
checkError: checkErrorStub,
@@ -1150,6 +1159,7 @@ describe("runs", () => {
11501159
sinon.assert.calledTwice(fetchZipSizeStub);
11511160
sinon.assert.calledOnce(fetchFolderSizeStub);
11521161
sinon.assert.calledOnce(zipUploadStub);
1162+
sinon.assert.calledOnce(isUndefinedOrFalseStub);
11531163
sinon.assert.calledOnce(createBuildStub);
11541164
sinon.assert.calledOnce(setProcessHooksStub);
11551165
sinon.assert.calledOnce(exportResultsStub);

test/unit/bin/helpers/capabilityHelper.js

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -925,6 +925,40 @@ describe("capabilityHelper.js", () => {
925925
});
926926
});
927927

928+
it("validate bsConfig.run_settings.enforce_settings", () => {
929+
let bsConfig = {
930+
auth: {},
931+
browsers: [
932+
{
933+
browser: "chrome",
934+
os: "Windows 10",
935+
versions: ["78", "77"],
936+
},
937+
],
938+
run_settings: {
939+
cypress_proj_dir: "random path",
940+
cypressConfigFilePath: "random path",
941+
cypressProjectDir: "random path",
942+
cypress_config_filename: "cypress.json",
943+
spec_timeout: 10,
944+
cypressTestSuiteType: Constants.CYPRESS_V9_AND_OLDER_TYPE,
945+
enforce_settings: true
946+
},
947+
};
948+
949+
return capabilityHelper
950+
.validate(bsConfig, { parallels: undefined })
951+
.then(function (data) {
952+
chai.assert.fail("Promise error");
953+
})
954+
.catch((error) => {
955+
chai.assert.equal(
956+
error,
957+
Constants.validationMessages.EMPTY_SPECS_IN_BROWSERSTACK_JSON
958+
);
959+
});
960+
});
961+
928962
it("resolve with proper message", () => {
929963
let bsConfig = {
930964
auth: {},

test/unit/bin/helpers/utils.js

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3055,6 +3055,49 @@ describe('utils', () => {
30553055
});
30563056
});
30573057

3058+
describe('setEnforceSettingsConfig', () => {
3059+
it('the video config should be assigned to bsconfig run_settings config', () => {
3060+
let bsConfig = {
3061+
run_settings: { video_config: { video:true, videoUploadOnPasses:true} },
3062+
};
3063+
let args = {
3064+
config: 'video=true,videoUploadOnPasses=true'
3065+
}
3066+
utils.setEnforceSettingsConfig(bsConfig);
3067+
expect(args.config).to.be.eql(bsConfig.run_settings.config);
3068+
});
3069+
it('the specPattern config should be assigned to bsconfig run_settings config', () => {
3070+
let bsConfig = {
3071+
run_settings: { specs: 'somerandomspecs', cypressTestSuiteType: 'CYPRESS_V10_AND_ABOVE_TYPE' },
3072+
};
3073+
let args = {
3074+
config: "video=false,videoUploadOnPasses=false,specPattern='somerandomspecs'"
3075+
}
3076+
utils.setEnforceSettingsConfig(bsConfig);
3077+
expect(args.config).to.be.eql(bsConfig.run_settings.config);
3078+
});
3079+
it('the testFiles config should be assigned to bsconfig run_settings config', () => {
3080+
let bsConfig = {
3081+
run_settings: { specs: 'somerandomspecs', cypressTestSuiteType: 'CYPRESS_V9_AND_OLDER_TYPE' },
3082+
};
3083+
let args = {
3084+
config: "video=false,videoUploadOnPasses=false,testFiles='somerandomspecs'"
3085+
}
3086+
utils.setEnforceSettingsConfig(bsConfig);
3087+
expect(args.config).to.be.eql(bsConfig.run_settings.config);
3088+
});
3089+
it('the baseUrl config should be assigned to bsconfig run_settings config', () => {
3090+
let bsConfig = {
3091+
run_settings: { baseUrl: 'http://localhost:8080' },
3092+
};
3093+
let args = {
3094+
config: 'video=false,videoUploadOnPasses=false,baseUrl=http://localhost:8080'
3095+
}
3096+
utils.setEnforceSettingsConfig(bsConfig);
3097+
expect(args.config).to.be.eql(bsConfig.run_settings.config);
3098+
});
3099+
});
3100+
30583101
describe('generateUniqueHash', () => {
30593102
beforeEach(() => {
30603103
let interfaceList = {
@@ -3419,6 +3462,22 @@ describe('utils', () => {
34193462
expect(utils.getVideoConfig({videoUploadOnPasses: false})).to.be.eql({video: true, videoUploadOnPasses: false});
34203463
expect(utils.getVideoConfig({video: false, videoUploadOnPasses: false})).to.be.eql({video: false, videoUploadOnPasses: false});
34213464
});
3465+
3466+
it('should return default hash and ignore video config in cypress config if enforce_settings is passed by the user', () => {
3467+
expect(utils.getVideoConfig({video: false}, {run_settings: {enforce_settings: true}})).to.be.eql({video: true, videoUploadOnPasses: true});
3468+
expect(utils.getVideoConfig({videoUploadOnPasses: false}, {run_settings: {enforce_settings: true}})).to.be.eql({video: true, videoUploadOnPasses: true});
3469+
expect(utils.getVideoConfig({video: false, videoUploadOnPasses: false}, {run_settings: {enforce_settings: true}})).to.be.eql({video: true, videoUploadOnPasses: true});
3470+
});
3471+
3472+
it('should return bsconfig value and ignore video config in cypress config if enforce_settings is passed by the user', () => {
3473+
expect(utils.getVideoConfig({video: true}, {run_settings: {enforce_settings: true, video: false }})).to.be.eql({video: false, videoUploadOnPasses: true});
3474+
expect(utils.getVideoConfig({videoUploadOnPasses: true}, {run_settings: {enforce_settings: true, videoUploadOnPasses: false}})).to.be.eql({video: true, videoUploadOnPasses: false});
3475+
expect(utils.getVideoConfig({video: true, videoUploadOnPasses: true}, {run_settings: {enforce_settings: true, video: false, videoUploadOnPasses: false}})).to.be.eql({video: false, videoUploadOnPasses: false});
3476+
expect(utils.getVideoConfig({video: false}, {run_settings: {enforce_settings: true, video: true }})).to.be.eql({video: true, videoUploadOnPasses: true});
3477+
expect(utils.getVideoConfig({videoUploadOnPasses: false}, {run_settings: {enforce_settings: true, videoUploadOnPasses: true}})).to.be.eql({video: true, videoUploadOnPasses: true});
3478+
expect(utils.getVideoConfig({video: false, videoUploadOnPasses: false}, {run_settings: {enforce_settings: true, video: true, videoUploadOnPasses: true}})).to.be.eql({video: true, videoUploadOnPasses: true});
3479+
});
3480+
34223481
});
34233482

34243483
describe('setNetworkLogs', () => {

0 commit comments

Comments
 (0)