Skip to content

Commit efdd866

Browse files
committed
add more edge cases
1 parent d35f016 commit efdd866

File tree

4 files changed

+100
-40
lines changed

4 files changed

+100
-40
lines changed

bin/commands/runs.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,9 @@ module.exports = function run(args) {
6363
// accept the number of parallels
6464
utils.setParallels(bsConfig, args, specFiles.length);
6565

66+
// warn if specFiles cross our limit
67+
utils.warnSpecLimit(bsConfig, args, specFiles);
68+
6669
// Archive the spec files
6770
return archiver.archive(bsConfig.run_settings, config.fileName, args.exclude).then(function (data) {
6871

bin/helpers/utils.js

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -149,11 +149,12 @@ exports.setParallels = (bsConfig, args, numOfSpecs) => {
149149
};
150150

151151
exports.warnSpecLimit = (bsConfig, args, specFiles) => {
152-
let numberOfSpecFiles = specFiles.length
153-
let totalLengthOfSpecFiles = specFiles.join("").length;
154-
let expectedCharLength = totalLengthOfSpecFiles + 175 * numberOfSpecFiles;
155-
156-
if (expectedCharLength > Constants.SPEC_TOTAL_CHAR_LIMIT) {
152+
let expectedCharLength = specFiles.join("").length + 175 * specFiles.length;
153+
let parallels = bsConfig['run_settings']['parallels'];
154+
let combinations = this.getBrowserCombinations(bsConfig).length;
155+
let parallelPerCombination = parallels > combinations ? Math.floor(parallels / combinations) : 1
156+
let expectedCharLengthPerParallel = expectedCharLength / parallelPerCombination
157+
if (expectedCharLengthPerParallel > Constants.SPEC_TOTAL_CHAR_LIMIT) {
157158
logger.warn(Constants.userMessages.SPEC_LIMIT_WARNING);
158159
this.sendUsageReport(
159160
bsConfig,
@@ -581,8 +582,6 @@ exports.getNumberOfSpecFiles = (bsConfig, args, cypressJson) => {
581582
let globSearchPattern = this.sanitizeSpecsPattern(bsConfig.run_settings.specs) || `${testFolderPath}/**/*.+(${Constants.specFileTypes.join("|")})`;
582583
let ignoreFiles = args.exclude || bsConfig.run_settings.exclude;
583584
let files = glob.sync(globSearchPattern, {cwd: bsConfig.run_settings.cypressProjectDir, matchBase: true, ignore: ignoreFiles});
584-
// warn if specFiles cross our limit
585-
this.warnSpecLimit(bsConfig, args, files);
586585
return files;
587586
};
588587

test/unit/bin/commands/runs.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,7 @@ describe("runs", () => {
191191
beforeEach(() => {
192192
sandbox = sinon.createSandbox();
193193
setParallelsStub = sandbox.stub();
194+
warnSpecLimitStub = sandbox.stub();
194195
setUsernameStub = sandbox.stub();
195196
setAccessKeyStub = sandbox.stub();
196197
getConfigPathStub = sandbox.stub();
@@ -232,6 +233,7 @@ describe("runs", () => {
232233
validateBstackJson: validateBstackJsonStub,
233234
sendUsageReport: sendUsageReportStub,
234235
setParallels: setParallelsStub,
236+
warnSpecLimit: warnSpecLimitStub,
235237
setUsername: setUsernameStub,
236238
setAccessKey: setAccessKeyStub,
237239
setBuildName: setBuildNameStub,
@@ -281,6 +283,7 @@ describe("runs", () => {
281283
sinon.assert.calledOnce(setCypressConfigFilenameStub);
282284
sinon.assert.calledOnce(getNumberOfSpecFilesStub);
283285
sinon.assert.calledOnce(setParallelsStub);
286+
sinon.assert.calledOnce(warnSpecLimitStub);
284287
sinon.assert.calledOnce(setLocalStub);
285288
sinon.assert.calledOnce(setLocalIdentifierStub);
286289
sinon.assert.calledOnce(setHeadedStub);
@@ -310,6 +313,7 @@ describe("runs", () => {
310313
sandbox = sinon.createSandbox();
311314
validateBstackJsonStub = sandbox.stub();
312315
setParallelsStub = sandbox.stub();
316+
warnSpecLimitStub = sandbox.stub();
313317
setUsernameStub = sandbox.stub();
314318
setAccessKeyStub = sandbox.stub();
315319
setBuildNameStub = sandbox.stub();
@@ -351,6 +355,7 @@ describe("runs", () => {
351355
validateBstackJson: validateBstackJsonStub,
352356
sendUsageReport: sendUsageReportStub,
353357
setParallels: setParallelsStub,
358+
warnSpecLimit: warnSpecLimitStub,
354359
setUsername: setUsernameStub,
355360
setAccessKey: setAccessKeyStub,
356361
setBuildName: setBuildNameStub,
@@ -400,6 +405,7 @@ describe("runs", () => {
400405
sinon.assert.calledOnce(setLocalConfigFileStub);
401406
sinon.assert.calledOnce(getNumberOfSpecFilesStub);
402407
sinon.assert.calledOnce(setParallelsStub);
408+
sinon.assert.calledOnce(warnSpecLimitStub);
403409
sinon.assert.calledOnce(setLocalStub);
404410
sinon.assert.calledOnce(setLocalIdentifierStub);
405411
sinon.assert.calledOnce(setHeadedStub);
@@ -432,6 +438,7 @@ describe("runs", () => {
432438
sandbox = sinon.createSandbox();
433439
validateBstackJsonStub = sandbox.stub();
434440
setParallelsStub = sandbox.stub();
441+
warnSpecLimitStub = sandbox.stub();
435442
setUsernameStub = sandbox.stub();
436443
setAccessKeyStub = sandbox.stub();
437444
setBuildNameStub = sandbox.stub();
@@ -475,6 +482,7 @@ describe("runs", () => {
475482
validateBstackJson: validateBstackJsonStub,
476483
sendUsageReport: sendUsageReportStub,
477484
setParallels: setParallelsStub,
485+
warnSpecLimit: warnSpecLimitStub,
478486
setUsername: setUsernameStub,
479487
setAccessKey: setAccessKeyStub,
480488
setBuildName: setBuildNameStub,
@@ -535,6 +543,7 @@ describe("runs", () => {
535543
sinon.assert.calledOnce(capabilityValidatorStub);
536544
sinon.assert.calledOnce(getNumberOfSpecFilesStub);
537545
sinon.assert.calledOnce(setParallelsStub);
546+
sinon.assert.calledOnce(warnSpecLimitStub);
538547
sinon.assert.calledOnce(setLocalStub);
539548
sinon.assert.calledOnce(setLocalIdentifierStub);
540549
sinon.assert.calledOnce(setHeadedStub);
@@ -567,6 +576,7 @@ describe("runs", () => {
567576
sandbox = sinon.createSandbox();
568577
validateBstackJsonStub = sandbox.stub();
569578
setParallelsStub = sandbox.stub();
579+
warnSpecLimitStub = sandbox.stub()
570580
setUsernameStub = sandbox.stub();
571581
setAccessKeyStub = sandbox.stub();
572582
setBuildNameStub = sandbox.stub();
@@ -620,6 +630,7 @@ describe("runs", () => {
620630
setTestEnvs: setTestEnvsStub,
621631
setUsageReportingFlag: setUsageReportingFlagStub,
622632
setParallels: setParallelsStub,
633+
warnSpecLimit: warnSpecLimitStub,
623634
getConfigPath: getConfigPathStub,
624635
setLocal: setLocalStub,
625636
setLocalMode: setLocalModeStub,
@@ -674,6 +685,7 @@ describe("runs", () => {
674685
sinon.assert.calledOnce(capabilityValidatorStub);
675686
sinon.assert.calledOnce(getNumberOfSpecFilesStub);
676687
sinon.assert.calledOnce(setParallelsStub);
688+
sinon.assert.calledOnce(warnSpecLimitStub);
677689
sinon.assert.calledOnce(setLocalStub);
678690
sinon.assert.calledOnce(setLocalModeStub);
679691
sinon.assert.calledOnce(setupLocalTestingStub);

test/unit/bin/helpers/utils.js

Lines changed: 79 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1431,14 +1431,6 @@ describe('utils', () => {
14311431
});
14321432

14331433
describe('getNumberOfSpecFiles', () => {
1434-
let warnSpecLimitStub;
1435-
beforeEach(() => {
1436-
warnSpecLimitStub = sinon.stub(utils, 'warnSpecLimit');
1437-
});
1438-
afterEach(() => {
1439-
sinon.restore();
1440-
});
1441-
14421434
it('glob search pattern should be equal to bsConfig.run_settings.specs', () => {
14431435
let getNumberOfSpecFilesStub = sinon.stub(glob, 'sync');
14441436
let bsConfig = {
@@ -1451,7 +1443,6 @@ describe('utils', () => {
14511443

14521444
utils.getNumberOfSpecFiles(bsConfig,{},{});
14531445
sinon.assert.calledOnce(getNumberOfSpecFilesStub);
1454-
sinon.assert.calledOnce(warnSpecLimitStub);
14551446
sinon.assert.calledOnceWithExactly(getNumberOfSpecFilesStub, 'specs', {
14561447
cwd: 'cypressProjectDir',
14571448
matchBase: true,
@@ -1471,7 +1462,6 @@ describe('utils', () => {
14711462

14721463
utils.getNumberOfSpecFiles(bsConfig,{},{});
14731464

1474-
sinon.assert.calledOnce(warnSpecLimitStub);
14751465
sinon.assert.calledOnceWithExactly(getNumberOfSpecFilesStub, `cypress/integration/**/*.+(${constant.specFileTypes.join("|")})`, {
14761466
cwd: 'cypressProjectDir',
14771467
matchBase: true,
@@ -1491,7 +1481,6 @@ describe('utils', () => {
14911481

14921482
utils.getNumberOfSpecFiles(bsConfig, {}, { "integrationFolder": "specs"});
14931483

1494-
sinon.assert.calledOnce(warnSpecLimitStub);
14951484
sinon.assert.calledOnceWithExactly(
14961485
getNumberOfSpecFilesStub,
14971486
`specs/**/*.+(${constant.specFileTypes.join('|')})`,
@@ -1507,6 +1496,7 @@ describe('utils', () => {
15071496

15081497
describe('warnSpecLimit', () => {
15091498
let sendUsageReportStub, loggerStub;
1499+
let bsConfig = {run_settings: {}}, args = {};
15101500
beforeEach(() => {
15111501
sendUsageReportStub = sandbox
15121502
.stub(utils, 'sendUsageReport')
@@ -1521,32 +1511,88 @@ describe('utils', () => {
15211511
sinon.restore();
15221512
});
15231513

1524-
it('should log when char limit is breached', () => {
1525-
let specFiles = {
1526-
length: constant.SPEC_TOTAL_CHAR_LIMIT,
1527-
join: function() {
1528-
return {
1529-
length: constant.SPEC_TOTAL_CHAR_LIMIT
1514+
context('limit crossing', () => {
1515+
it('should log and send to eds for one combination, one parallel', () => {
1516+
let specFiles = {
1517+
length: 1,
1518+
join: function() {
1519+
return {
1520+
length: constant.SPEC_TOTAL_CHAR_LIMIT
1521+
}
15301522
}
1531-
}
1532-
};
1533-
utils.warnSpecLimit({}, {}, specFiles);
1534-
sinon.assert.calledOnce(sendUsageReportStub);
1535-
sinon.assert.calledOnce(loggerStub);
1523+
};
1524+
sinon.stub(utils, "getBrowserCombinations").returns(1);
1525+
bsConfig.run_settings.parallels = 1;
1526+
utils.warnSpecLimit(bsConfig, args, specFiles);
1527+
sinon.assert.calledOnce(sendUsageReportStub);
1528+
sinon.assert.calledOnce(loggerStub);
1529+
});
1530+
1531+
it('should log and send to eds for one combination, two parallel', () => {
1532+
let specFiles = {
1533+
length: 1,
1534+
join: function() {
1535+
return {
1536+
length: constant.SPEC_TOTAL_CHAR_LIMIT
1537+
}
1538+
}
1539+
};
1540+
sinon.stub(utils, "getBrowserCombinations").returns(1);
1541+
bsConfig.run_settings.parallels = 2;
1542+
utils.warnSpecLimit(bsConfig, args, specFiles);
1543+
sinon.assert.calledOnce(sendUsageReportStub);
1544+
sinon.assert.calledOnce(loggerStub);
1545+
});
1546+
1547+
it('should log and send to eds for multiple combination, multiple parallel', () => {
1548+
let specFiles = {
1549+
length: 1,
1550+
join: function() {
1551+
return {
1552+
length: constant.SPEC_TOTAL_CHAR_LIMIT
1553+
}
1554+
}
1555+
};
1556+
sinon.stub(utils, "getBrowserCombinations").returns(3);
1557+
bsConfig.run_settings.parallels = 4;
1558+
utils.warnSpecLimit(bsConfig, args, specFiles);
1559+
sinon.assert.calledOnce(sendUsageReportStub);
1560+
sinon.assert.calledOnce(loggerStub);
1561+
});
15361562
});
15371563

1538-
it('should not log when char length is within limit', () => {
1539-
let specFiles = {
1540-
length: 1,
1541-
join: function() {
1542-
return {
1543-
length: 1
1564+
context('within limit', () => {
1565+
it('should not log for one combination, one parallel', () => {
1566+
let specFiles = {
1567+
length: 1,
1568+
join: function() {
1569+
return {
1570+
length: 1
1571+
}
15441572
}
1545-
}
1546-
};
1547-
utils.warnSpecLimit({}, {}, specFiles);
1548-
sinon.assert.notCalled(sendUsageReportStub);
1549-
sinon.assert.notCalled(loggerStub);
1573+
};
1574+
sinon.stub(utils, "getBrowserCombinations").returns(1);
1575+
bsConfig.run_settings.parallels = 1;
1576+
utils.warnSpecLimit(bsConfig, args, specFiles);
1577+
sinon.assert.notCalled(sendUsageReportStub);
1578+
sinon.assert.notCalled(loggerStub);
1579+
});
1580+
1581+
it('should not log for one combination, multiple parallel', () => {
1582+
let specFiles = {
1583+
length: 1,
1584+
join: function() {
1585+
return {
1586+
length: 1
1587+
}
1588+
}
1589+
};
1590+
sinon.stub(utils, "getBrowserCombinations").returns(1);
1591+
bsConfig.run_settings.parallels = 2;
1592+
utils.warnSpecLimit(bsConfig, args, specFiles);
1593+
sinon.assert.notCalled(sendUsageReportStub);
1594+
sinon.assert.notCalled(loggerStub);
1595+
});
15501596
});
15511597
});
15521598

0 commit comments

Comments
 (0)