Skip to content

Commit 609bb92

Browse files
Added unit test cases and handle -1 parallels case
1 parent 0089b8c commit 609bb92

File tree

4 files changed

+52
-5
lines changed

4 files changed

+52
-5
lines changed

bin/commands/runs.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ module.exports = function run(args) {
4848
return capabilityHelper.validate(bsConfig, args).then(function (cypressJson) {
4949

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

5353
// accept the number of parallels
5454
utils.setParallels(bsConfig, args, specFiles.length);

bin/helpers/constants.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ const allowedFileTypes = ['js', 'json', 'txt', 'ts', 'feature', 'features', 'pdf
9191

9292
const filesToIgnoreWhileUploading = ['node_modules/**', 'package-lock.json', 'package.json', 'browserstack-package.json', 'tests.zip', 'cypress.json']
9393

94-
const specFileTypes = ['js', 'ts', 'feature', 'jsx', 'coffee', 'cjsx']
94+
const specFileTypes = ['js', 'ts', 'feature']
9595

9696
const DEFAULT_CYPRESS_SPEC_PATH = "cypress/integration"
9797

bin/helpers/utils.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,11 @@ exports.setParallels = (bsConfig, args, numOfSpecs) => {
116116
}
117117
let browserCombinations = this.getBrowserCombinations(bsConfig);
118118
let maxParallels = browserCombinations.length * numOfSpecs;
119-
if (bsConfig['run_settings']['parallels'] > maxParallels) {
119+
if (numOfSpecs <= 0) {
120+
bsConfig['run_settings']['parallels'] = browserCombinations.length;
121+
return;
122+
}
123+
if (bsConfig['run_settings']['parallels'] > maxParallels && bsConfig['run_settings']['parallels'] != -1 ) {
120124
logger.warn(
121125
`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.`
122126
);

test/unit/bin/helpers/utils.js

Lines changed: 45 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,13 +140,25 @@ describe('utils', () => {
140140
});
141141

142142
describe('setParallels', () => {
143+
var sandbox;
144+
beforeEach(() => {
145+
sandbox = sinon.createSandbox();
146+
sandbox.stub(utils,'getBrowserCombinations').returns(['a','b']);
147+
});
148+
149+
afterEach(() => {
150+
sandbox.restore();
151+
sinon.restore();
152+
});
153+
143154
it('should set bsconfig parallels equal to value provided in args', () => {
144155
let bsConfig = {
145156
run_settings: {
146157
parallels: 10,
147158
},
148159
};
149-
utils.setParallels(bsConfig, {parallels: 100});
160+
161+
utils.setParallels(bsConfig, {parallels: 100}, 100);
150162
expect(bsConfig['run_settings']['parallels']).to.be.eq(100);
151163
});
152164

@@ -156,9 +168,40 @@ describe('utils', () => {
156168
parallels: 10,
157169
},
158170
};
159-
utils.setParallels(bsConfig, {parallels: undefined});
171+
utils.setParallels(bsConfig, {parallels: undefined}, 10);
160172
expect(bsConfig['run_settings']['parallels']).to.be.eq(10);
161173
});
174+
175+
it('should set bsconfig parallels to browserCombinations.length if numOfSpecs is zero', () => {
176+
let bsConfig = {
177+
run_settings: {
178+
parallels: 10,
179+
},
180+
};
181+
utils.setParallels(bsConfig, {parallels: undefined}, 0);
182+
expect(bsConfig['run_settings']['parallels']).to.be.eq(2);
183+
});
184+
185+
it('shouldnot set bsconfig parallels if parallels is -1', () => {
186+
let bsConfig = {
187+
run_settings: {
188+
parallels: -1,
189+
},
190+
};
191+
utils.setParallels(bsConfig, {parallels: undefined}, 2);
192+
expect(bsConfig['run_settings']['parallels']).to.be.eq(-1);
193+
});
194+
195+
it('should set bsconfig parallels if parallels is greater than numOfSpecs * combinations', () => {
196+
let bsConfig = {
197+
run_settings: {
198+
parallels: 100,
199+
},
200+
};
201+
utils.setParallels(bsConfig, {parallels: undefined}, 2);
202+
expect(bsConfig['run_settings']['parallels']).to.be.eq(4);
203+
});
204+
162205
});
163206

164207
describe('getErrorCodeFromErr', () => {

0 commit comments

Comments
 (0)