Skip to content

Commit

Permalink
fix: retries validation (#8268)
Browse files Browse the repository at this point in the history
* fix: validation logic issues
  • Loading branch information
JessicaSachs committed Aug 13, 2020
1 parent 2d2c653 commit 4aedd98
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 9 deletions.
19 changes: 10 additions & 9 deletions packages/server/lib/util/validation.js
Expand Up @@ -104,18 +104,19 @@ const isValidBrowserList = (key, browsers) => {
}

const isValidRetriesConfig = (key, value) => {
const isNullOrNumber = isOneOf([_.isNumber, _.isNull])

if (
isNullOrNumber(value)
|| (_.isEqual(_.keys(value), ['runMode', 'openMode']))
&& isNullOrNumber(value.runMode)
&& isNullOrNumber(value.openMode)
) {
const optionalKeys = ['runMode', 'openMode']
const isValidRetryValue = (val) => _.isNull(val) || (Number.isInteger(val) && val >= 0)
const optionalKeysAreValid = (val, k) => optionalKeys.includes(k) && isValidRetryValue(val)

if (isValidRetryValue(value)) {
return true
}

if (_.isObject(value) && _.every(value, optionalKeysAreValid)) {
return true
}

return errMsg(key, value, 'a number or null or an object with keys "openMode" and "runMode" with values of numbers or nulls')
return errMsg(key, value, 'a positive number or null or an object with keys "openMode" and "runMode" with values of numbers or nulls')
}

const isValidFirefoxGcInterval = (key, value) => {
Expand Down
28 changes: 28 additions & 0 deletions packages/server/test/unit/config_spec.js
Expand Up @@ -690,6 +690,34 @@ describe('lib/config', () => {
})
})

context('retries', () => {
const retriesError = 'a positive number or null or an object with keys "openMode" and "runMode" with values of numbers or nulls'

// need to keep the const here or it'll get stripped by the build
// eslint-disable-next-line no-unused-vars
const cases = [
[{ retries: null }, 'with null', true],
[{ retries: 3 }, 'when a number', true],
[{ retries: 3.2 }, 'when a float', false],
[{ retries: -1 }, 'with a negative number', false],
[{ retries: true }, 'when true', false],
[{ retries: false }, 'when false', false],
[{ retries: {} }, 'with an empty object', true],
[{ retries: { runMode: 3 } }, 'when runMode is a positive number', true],
[{ retries: { runMode: -1 } }, 'when runMode is a negative number', false],
[{ retries: { openMode: 3 } }, 'when openMode is a positive number', true],
[{ retries: { openMode: -1 } }, 'when openMode is a negative number', false],
[{ retries: { openMode: 3, TypoRunMode: 3 } }, 'when there is an additional unknown key', false],
[{ retries: { openMode: 3, runMode: 3 } }, 'when both runMode and openMode are positive numbers', true],
].forEach(([config, expectation, shouldPass]) => {
it(`${shouldPass ? 'passes' : 'fails'} ${expectation}`, function () {
this.setup(config)

return shouldPass ? this.expectValidationPasses() : this.expectValidationFails(retriesError)
})
})
})

context('firefoxGcInterval', () => {
it('passes if a number', function () {
this.setup({ firefoxGcInterval: 1 })
Expand Down

1 comment on commit 4aedd98

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 4aedd98 Aug 13, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Circle has built the linux x64 version of the Test Runner.

You can install this pre-release platform-specific build using instructions at https://on.cypress.io/installing-cypress#Install-pre-release-version.

You will need to use custom CYPRESS_INSTALL_BINARY url and install Cypress using an url instead of the version.

export CYPRESS_INSTALL_BINARY=https://cdn.cypress.io/beta/binary/5.0.0/linux-x64/circle-v5.0-release-4aedd98b5d45a171e9ea3980c54a5bc0750e76b2-420869/cypress.zip
npm install https://cdn.cypress.io/beta/npm/5.0.0/circle-v5.0-release-4aedd98b5d45a171e9ea3980c54a5bc0750e76b2-420862/cypress.tgz

Please sign in to comment.