Skip to content

Commit 0089b8c

Browse files
Added new test cases
1 parent 137aa3f commit 0089b8c

File tree

4 files changed

+125
-16
lines changed

4 files changed

+125
-16
lines changed

bin/commands/runs.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,10 @@ module.exports = function run(args) {
4848
return capabilityHelper.validate(bsConfig, args).then(function (cypressJson) {
4949

5050
//get the number of spec files
51-
let files = utils.getNumberOfSpecFiles(bsConfig,args,cypressJson);
52-
logger.info(files);
51+
let specFiles = utils.getNumberOfSpecFiles(bsConfig,args,cypressJson);
5352

5453
// accept the number of parallels
55-
utils.setParallels(bsConfig, args);
54+
utils.setParallels(bsConfig, args, specFiles.length);
5655

5756
// Archive the spec files
5857
return archiver.archive(bsConfig.run_settings, config.fileName, args.exclude).then(function (data) {

bin/helpers/utils.js

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,10 +110,18 @@ exports.setUsageReportingFlag = (bsConfig, disableUsageReporting) => {
110110
}
111111
};
112112

113-
exports.setParallels = (bsConfig, args) => {
113+
exports.setParallels = (bsConfig, args, numOfSpecs) => {
114114
if (!this.isUndefined(args.parallels)) {
115115
bsConfig["run_settings"]["parallels"] = args.parallels;
116116
}
117+
let browserCombinations = this.getBrowserCombinations(bsConfig);
118+
let maxParallels = browserCombinations.length * numOfSpecs;
119+
if (bsConfig['run_settings']['parallels'] > maxParallels) {
120+
logger.warn(
121+
`Using ${maxParallels} machines instead of ${bsConfig['run_settings']['parallels']} that you configured as there are ${numOfSpecs} specs to be run on ${browserCombinations.length} browser combinations.`
122+
);
123+
bsConfig['run_settings']['parallels'] = maxParallels;
124+
}
117125
};
118126

119127
exports.setDefaultAuthHash = (bsConfig, args) => {
@@ -323,3 +331,17 @@ exports.getNumberOfSpecFiles = (bsConfig, args, cypressJson) => {
323331
let files = glob.sync(globSearchPatttern, {cmd: bsConfig.run_settings.cypressConfigFilePath, matchBase: true, ignore: ignoreFiles});
324332
return files;
325333
};
334+
335+
exports.getBrowserCombinations = (bsConfig) => {
336+
let osBrowserArray = [];
337+
let osBrowser = "";
338+
if (bsConfig.browsers) {
339+
bsConfig.browsers.forEach((element) => {
340+
osBrowser = element.os + '-' + element.browser;
341+
element.versions.forEach((version) => {
342+
osBrowserArray.push(osBrowser + version);
343+
});
344+
});
345+
}
346+
return osBrowserArray;
347+
};

test/unit/bin/commands/runs.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ describe("runs", () => {
189189
setLocalIdentifierStub = sandbox.stub();
190190
deleteResultsStub = sandbox.stub();
191191
setDefaultAuthHashStub = sandbox.stub();
192-
getNumberOfSpecFilesStub = sandbox.stub();
192+
getNumberOfSpecFilesStub = sandbox.stub().returns([]);
193193
});
194194

195195
afterEach(() => {
@@ -243,6 +243,7 @@ describe("runs", () => {
243243
.catch((error) => {
244244
sinon.assert.calledOnce(getConfigPathStub);
245245
sinon.assert.calledOnce(getConfigPathStub);
246+
sinon.assert.calledOnce(getNumberOfSpecFilesStub);
246247
sinon.assert.calledOnce(setParallelsStub);
247248
sinon.assert.calledOnce(setLocalStub);
248249
sinon.assert.calledOnce(setLocalIdentifierStub);
@@ -291,7 +292,7 @@ describe("runs", () => {
291292
setLocalIdentifierStub = sandbox.stub();
292293
deleteResultsStub = sandbox.stub();
293294
setDefaultAuthHashStub = sandbox.stub();
294-
getNumberOfSpecFilesStub = sandbox.stub();
295+
getNumberOfSpecFilesStub = sandbox.stub().returns([]);
295296
});
296297

297298
afterEach(() => {
@@ -349,6 +350,7 @@ describe("runs", () => {
349350
.catch((error) => {
350351
sinon.assert.calledOnce(getConfigPathStub);
351352
sinon.assert.calledOnce(getConfigPathStub);
353+
sinon.assert.calledOnce(getNumberOfSpecFilesStub);
352354
sinon.assert.calledOnce(setParallelsStub);
353355
sinon.assert.calledOnce(setLocalStub);
354356
sinon.assert.calledOnce(setLocalIdentifierStub);
@@ -401,7 +403,7 @@ describe("runs", () => {
401403
setLocalIdentifierStub = sandbox.stub();
402404
deleteResultsStub = sandbox.stub();
403405
setDefaultAuthHashStub = sandbox.stub();
404-
getNumberOfSpecFilesStub = sandbox.stub();
406+
getNumberOfSpecFilesStub = sandbox.stub().returns([]);
405407
});
406408

407409
afterEach(() => {
@@ -467,6 +469,7 @@ describe("runs", () => {
467469
sinon.assert.calledOnce(getConfigPathStub);
468470
sinon.assert.calledOnce(validateBstackJsonStub);
469471
sinon.assert.calledOnce(capabilityValidatorStub);
472+
sinon.assert.calledOnce(getNumberOfSpecFilesStub);
470473
sinon.assert.calledOnce(setParallelsStub);
471474
sinon.assert.calledOnce(setLocalStub);
472475
sinon.assert.calledOnce(setLocalIdentifierStub);
@@ -525,7 +528,7 @@ describe("runs", () => {
525528
isUndefinedStub = sandbox.stub();
526529
setLocalStub = sandbox.stub();
527530
setLocalIdentifierStub = sandbox.stub();
528-
getNumberOfSpecFilesStub = sandbox.stub();
531+
getNumberOfSpecFilesStub = sandbox.stub().returns([]);
529532
});
530533

531534
afterEach(() => {
@@ -597,6 +600,7 @@ describe("runs", () => {
597600
sinon.assert.calledOnce(getConfigPathStub);
598601
sinon.assert.calledOnce(validateBstackJsonStub);
599602
sinon.assert.calledOnce(capabilityValidatorStub);
603+
sinon.assert.calledOnce(getNumberOfSpecFilesStub);
600604
sinon.assert.calledOnce(setParallelsStub);
601605
sinon.assert.calledOnce(setLocalStub);
602606
sinon.assert.calledOnce(setLocalIdentifierStub);

test/unit/bin/helpers/utils.js

Lines changed: 92 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,7 @@ describe('utils', () => {
302302
let args = testObjects.initSampleArgs;
303303

304304
it('should call sendUsageReport', () => {
305-
sandbox = sinon.createSandbox();
305+
let sandbox = sinon.createSandbox();
306306
sendUsageReportStub = sandbox
307307
.stub(utils, 'sendUsageReport')
308308
.callsFake(function () {
@@ -953,22 +953,106 @@ describe('utils', () => {
953953
describe('getNumberOfSpecFiles', () => {
954954

955955
it('glob search pattern should be equal to bsConfig.run_settings.specs', () => {
956-
sinon.stub(glob, 'sync').returns(true);
956+
let getNumberOfSpecFilesStub = sinon.stub(glob, 'sync');
957957
let bsConfig = {
958958
run_settings: {
959+
specs: 'specs',
959960
cypressConfigFilePath: 'cypressConfigFilePath',
960961
exclude: 'exclude'
961962
},
962963
};
963-
// sinon.assert.calledOnce(getNumberOfSpecFilesStub);
964-
// sinon.assert.calledOnceWithExactly(getNumberOfSpecFilesStub, 'specs', {
965-
// cmd: 'cypressConfigFilePath',
966-
// matchBase: true,
967-
// ignore: 'exclude',
968-
// });
964+
965+
utils.getNumberOfSpecFiles(bsConfig,{},{});
966+
sinon.assert.calledOnce(getNumberOfSpecFilesStub);
967+
sinon.assert.calledOnceWithExactly(getNumberOfSpecFilesStub, 'specs', {
968+
cmd: 'cypressConfigFilePath',
969+
matchBase: true,
970+
ignore: 'exclude',
971+
});
972+
glob.sync.restore();
973+
});
974+
975+
it('glob search pattern should be equal to default', () => {
976+
let getNumberOfSpecFilesStub = sinon.stub(glob, 'sync');
977+
let bsConfig = {
978+
run_settings: {
979+
cypressConfigFilePath: 'cypressConfigFilePath',
980+
exclude: 'exclude'
981+
},
982+
};
983+
969984
utils.getNumberOfSpecFiles(bsConfig,{},{});
985+
986+
sinon.assert.calledOnceWithExactly(getNumberOfSpecFilesStub, `cypress/integration/**/*.+(${constant.specFileTypes.join("|")})`, {
987+
cmd: 'cypressConfigFilePath',
988+
matchBase: true,
989+
ignore: 'exclude',
990+
});
991+
glob.sync.restore();
992+
});
993+
994+
it('glob search pattern should be equal to default with integrationFolder', () => {
995+
let getNumberOfSpecFilesStub = sinon.stub(glob, 'sync');
996+
let bsConfig = {
997+
run_settings: {
998+
cypressConfigFilePath: 'cypressConfigFilePath',
999+
exclude: 'exclude',
1000+
},
1001+
};
1002+
1003+
utils.getNumberOfSpecFiles(bsConfig, {}, { "integrationFolder": "specs"});
1004+
1005+
sinon.assert.calledOnceWithExactly(
1006+
getNumberOfSpecFilesStub,
1007+
`specs/**/*.+(${constant.specFileTypes.join('|')})`,
1008+
{
1009+
cmd: 'cypressConfigFilePath',
1010+
matchBase: true,
1011+
ignore: 'exclude',
1012+
}
1013+
);
9701014
glob.sync.restore();
9711015
});
1016+
1017+
});
1018+
1019+
describe('getBrowserCombinations', () => {
1020+
1021+
it('returns correct number of browserCombinations for one combination', () => {
1022+
let bsConfig = {
1023+
browsers: [
1024+
{
1025+
browser: 'chrome',
1026+
os: 'OS X Mojave',
1027+
versions: ['85'],
1028+
},
1029+
]
1030+
};
1031+
chai.assert.deepEqual(utils.getBrowserCombinations(bsConfig), ['OS X Mojave-chrome85']);
1032+
});
1033+
1034+
it('returns correct number of browserCombinations for multiple combinations', () => {
1035+
let bsConfig = {
1036+
browsers: [
1037+
{
1038+
browser: 'chrome',
1039+
os: 'OS X Mojave',
1040+
versions: ['85'],
1041+
},
1042+
{
1043+
browser: 'chrome',
1044+
os: 'OS X Catalina',
1045+
versions: ['85','84'],
1046+
},
1047+
],
1048+
};
1049+
chai.assert.deepEqual(utils.getBrowserCombinations(bsConfig), [
1050+
'OS X Mojave-chrome85',
1051+
'OS X Catalina-chrome85',
1052+
'OS X Catalina-chrome84'
1053+
]);
1054+
});
1055+
9721056
});
9731057

9741058
});

0 commit comments

Comments
 (0)