Skip to content

Commit d35f016

Browse files
committed
Add warning around spec count
1 parent 4f7a074 commit d35f016

File tree

3 files changed

+80
-2
lines changed

3 files changed

+80
-2
lines changed

bin/helpers/constants.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@ const userMessages = {
4040
CYPRESS_VERSION_CHANGED: "Your build will run using Cypress <actualVersion> instead of Cypress <preferredVersion>. Read more about supported versions here: http://browserstack.com/docs/automate/cypress/supported-versions",
4141
LOCAL_START_FAILED: "Local Testing setup failed.",
4242
LOCAL_STOP_FAILED: "Local Binary stop failed.",
43-
INVALID_LOCAL_MODE_WARNING: "Invalid value specified for local_mode. local_mode: (\"always-on\" | \"on-demand\"). For more info, check out https://www.browserstack.com/docs/automate/cypress/cli-reference"
43+
INVALID_LOCAL_MODE_WARNING: "Invalid value specified for local_mode. local_mode: (\"always-on\" | \"on-demand\"). For more info, check out https://www.browserstack.com/docs/automate/cypress/cli-reference",
44+
SPEC_LIMIT_WARNING: "There is a chance that you might not see all the results on the dashboard because of your spec count."
4445
};
4546

4647
const validationMessages = {
@@ -134,6 +135,8 @@ const specFileTypes = ['js', 'ts', 'feature', 'jsx', 'coffee', 'cjsx'];
134135

135136
const DEFAULT_CYPRESS_SPEC_PATH = "cypress/integration"
136137

138+
const SPEC_TOTAL_CHAR_LIMIT = 32243
139+
137140
module.exports = Object.freeze({
138141
syncCLI,
139142
userMessages,
@@ -143,5 +146,6 @@ module.exports = Object.freeze({
143146
allowedFileTypes,
144147
filesToIgnoreWhileUploading,
145148
specFileTypes,
146-
DEFAULT_CYPRESS_SPEC_PATH
149+
DEFAULT_CYPRESS_SPEC_PATH,
150+
SPEC_TOTAL_CHAR_LIMIT
147151
});

bin/helpers/utils.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,23 @@ exports.setParallels = (bsConfig, args, numOfSpecs) => {
148148
}
149149
};
150150

151+
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) {
157+
logger.warn(Constants.userMessages.SPEC_LIMIT_WARNING);
158+
this.sendUsageReport(
159+
bsConfig,
160+
args,
161+
Constants.userMessages.SPEC_LIMIT_WARNING,
162+
Constants.messageTypes.WARNING,
163+
null
164+
);
165+
}
166+
}
167+
151168
exports.setDefaults = (bsConfig, args) => {
152169
// setting setDefaultAuthHash to {} if not present and set via env variables or via args.
153170
if (this.isUndefined(bsConfig['auth']) && (!this.isUndefined(args.username) || !this.isUndefined(process.env.BROWSERSTACK_USERNAME))) {
@@ -564,6 +581,8 @@ exports.getNumberOfSpecFiles = (bsConfig, args, cypressJson) => {
564581
let globSearchPattern = this.sanitizeSpecsPattern(bsConfig.run_settings.specs) || `${testFolderPath}/**/*.+(${Constants.specFileTypes.join("|")})`;
565582
let ignoreFiles = args.exclude || bsConfig.run_settings.exclude;
566583
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);
567586
return files;
568587
};
569588

test/unit/bin/helpers/utils.js

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1431,6 +1431,13 @@ 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+
});
14341441

14351442
it('glob search pattern should be equal to bsConfig.run_settings.specs', () => {
14361443
let getNumberOfSpecFilesStub = sinon.stub(glob, 'sync');
@@ -1444,6 +1451,7 @@ describe('utils', () => {
14441451

14451452
utils.getNumberOfSpecFiles(bsConfig,{},{});
14461453
sinon.assert.calledOnce(getNumberOfSpecFilesStub);
1454+
sinon.assert.calledOnce(warnSpecLimitStub);
14471455
sinon.assert.calledOnceWithExactly(getNumberOfSpecFilesStub, 'specs', {
14481456
cwd: 'cypressProjectDir',
14491457
matchBase: true,
@@ -1463,6 +1471,7 @@ describe('utils', () => {
14631471

14641472
utils.getNumberOfSpecFiles(bsConfig,{},{});
14651473

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

14831492
utils.getNumberOfSpecFiles(bsConfig, {}, { "integrationFolder": "specs"});
14841493

1494+
sinon.assert.calledOnce(warnSpecLimitStub);
14851495
sinon.assert.calledOnceWithExactly(
14861496
getNumberOfSpecFilesStub,
14871497
`specs/**/*.+(${constant.specFileTypes.join('|')})`,
@@ -1495,6 +1505,51 @@ describe('utils', () => {
14951505
});
14961506
});
14971507

1508+
describe('warnSpecLimit', () => {
1509+
let sendUsageReportStub, loggerStub;
1510+
beforeEach(() => {
1511+
sendUsageReportStub = sandbox
1512+
.stub(utils, 'sendUsageReport')
1513+
.callsFake(function () {
1514+
return 'end';
1515+
});
1516+
loggerStub = sinon.stub(logger, 'warn');
1517+
});
1518+
1519+
afterEach(() => {
1520+
sandbox.restore();
1521+
sinon.restore();
1522+
});
1523+
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
1530+
}
1531+
}
1532+
};
1533+
utils.warnSpecLimit({}, {}, specFiles);
1534+
sinon.assert.calledOnce(sendUsageReportStub);
1535+
sinon.assert.calledOnce(loggerStub);
1536+
});
1537+
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
1544+
}
1545+
}
1546+
};
1547+
utils.warnSpecLimit({}, {}, specFiles);
1548+
sinon.assert.notCalled(sendUsageReportStub);
1549+
sinon.assert.notCalled(loggerStub);
1550+
});
1551+
});
1552+
14981553
describe('capitalizeFirstLetter', () => {
14991554

15001555
it('should capitalize First Letter ', () => {

0 commit comments

Comments
 (0)