Skip to content

Commit

Permalink
feat: add the burnIn Configuration to the config package. Option
Browse files Browse the repository at this point in the history
currently is a no-op
  • Loading branch information
AtofStryker committed Jul 24, 2023
1 parent f6821e0 commit 62b1191
Show file tree
Hide file tree
Showing 5 changed files with 225 additions and 0 deletions.
9 changes: 9 additions & 0 deletions packages/config/__snapshots__/index.spec.ts.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ exports['config/src/index .getDefaultValues returns list of public config keys 1
'animationDistanceThreshold': 5,
'baseUrl': null,
'blockHosts': null,
'burnIn': {
'default': 3,
'flaky': 5,
},
'chromeWebSecurity': true,
'clientCertificates': [],
'component': {
Expand Down Expand Up @@ -109,6 +113,10 @@ exports['config/src/index .getDefaultValues returns list of public config keys f
'animationDistanceThreshold': 5,
'baseUrl': null,
'blockHosts': null,
'burnIn': {
'default': 3,
'flaky': 5,
},
'chromeWebSecurity': true,
'clientCertificates': [],
'component': {
Expand Down Expand Up @@ -198,6 +206,7 @@ exports['config/src/index .getPublicConfigKeys returns list of public config key
'arch',
'baseUrl',
'blockHosts',
'burnIn',
'chromeWebSecurity',
'clientCertificates',
'component',
Expand Down
71 changes: 71 additions & 0 deletions packages/config/__snapshots__/validation.spec.ts.js
Original file line number Diff line number Diff line change
Expand Up @@ -261,3 +261,74 @@ exports['invalid upper bound'] = {
'value': 52,
'type': 'a valid CRF number between 1 & 51, 0 or false to disable compression, or true to use the default compression of 32',
}

exports['missing key "flaky"'] = {
'key': 'burnIn',
'value': {
'default': 1,
},
'type': 'an object with keys `default` and `flaky`. Keys `default` and `flaky` must be integers greater than 0.',
}

exports['missing key "default"'] = {
'key': 'burnIn',
'value': {
'flaky': 1,
},
'type': 'an object with keys `default` and `flaky`. Keys `default` and `flaky` must be integers greater than 0.',
}

exports['keys cannot be zero key'] = {
'key': 'burnIn',
'value': {
'default': 0,
'flaky': 0,
},
'type': 'an object with keys `default` and `flaky`. Keys `default` and `flaky` must be integers greater than 0.',
}

exports['keys cannot be zero'] = {
'key': 'burnIn',
'value': {
'default': 0,
'flaky': 0,
},
'type': 'an object with keys `default` and `flaky`. Keys `default` and `flaky` must be integers greater than 0.',
}

exports['keys cannot be negative'] = {
'key': 'burnIn',
'value': {
'default': -3,
'flaky': -40,
},
'type': 'an object with keys `default` and `flaky`. Keys `default` and `flaky` must be integers greater than 0.',
}

exports['keys cannot be floating point numbers'] = {
'key': 'burnIn',
'value': {
'default': 5.7,
'flaky': 8.22,
},
'type': 'an object with keys `default` and `flaky`. Keys `default` and `flaky` must be integers greater than 0.',
}

exports['keys cannot be Infinity'] = {
'key': 'burnIn',
'value': {
'default': null,
'flaky': null,
},
'type': 'an object with keys `default` and `flaky`. Keys `default` and `flaky` must be integers greater than 0.',
}

exports['extraneous keys'] = {
'key': 'burnIn',
'value': {
'default': 3,
'flaky': 5,
'notflaky': null,
},
'type': 'an object with keys `default` and `flaky`. Keys `default` and `flaky` must be integers greater than 0.',
}
8 changes: 8 additions & 0 deletions packages/config/src/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,14 @@ const driverConfigOptions: Array<DriverConfigOption> = [
validation: validate.isStringOrArrayOfStrings,
overrideLevel: 'any',
requireRestartOnChange: 'server',
}, {
// burnIn config is only considered in run-mode while recording to cypress-cloud
name: 'burnIn',
defaultValue: {
default: 3,
flaky: 5,
},
validation: validate.isValidBurnInConfig,
}, {
name: 'chromeWebSecurity',
defaultValue: true,
Expand Down
22 changes: 22 additions & 0 deletions packages/config/src/validation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -384,3 +384,25 @@ export function isNullOrArrayOfStrings (key: string, value: any): ErrResult | tr

return errMsg(key, value, 'an array of strings or null')
}

export function isValidBurnInConfig (key: string, value: any): ErrResult | true {
// false can be provided to turn off test burn in
if (_.isBoolean(value)) {
return true
}

if (_.isPlainObject(value)) {
const { default: defaultKey, flaky: flakyKey, ...extraneousKeys } = value

if (defaultKey !== undefined && defaultKey !== undefined && _.isEmpty(extraneousKeys)) {
const isDefaultKeyValid = _.isInteger(defaultKey) && _.inRange(defaultKey, 1, Infinity)
const isFlakyKeyValid = _.isInteger(flakyKey) && _.inRange(flakyKey, 1, Infinity)

if (isDefaultKeyValid && isFlakyKeyValid) {
return true
}
}
}

return errMsg(key, value, 'an object with keys `default` and `flaky`. Keys `default` and `flaky` must be integers greater than 0.')
}
115 changes: 115 additions & 0 deletions packages/config/test/validation.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -509,4 +509,119 @@ describe('config/src/validation', () => {
return snapshot('invalid upper bound', upperBoundMsg)
})
})

describe('.isValidBurnInConfig', () => {
it('validates defaults', () => {
const validate = validation.isValidBurnInConfig('burnIn', {
default: 3,
flaky: 5,
})

expect(validate).to.be.true
})

it('validates false', () => {
const validate = validation.isValidBurnInConfig('burnIn', false)

expect(validate).to.be.true
})

it('validates true', () => {
const validate = validation.isValidBurnInConfig('burnIn', true)

expect(validate).to.be.true
})

it('does not allow extraneous keys', () => {
const validate = validation.isValidBurnInConfig('burnIn', {
default: 3,
flaky: 5,
// extraneous key
notflaky: null,
})

expect(validate).to.not.be.true

return snapshot(`extraneous keys`, validate)
})

const possibleConfigKeys = ['default', 'flaky']

possibleConfigKeys.forEach((burnInConfigKey) => {
it(`Does not populate missing config value with default values (key "${burnInConfigKey}")`, () => {
const validate = validation.isValidBurnInConfig('burnIn', {
[burnInConfigKey]: 1,
})

expect(validate).to.not.be.true

const missingKey = possibleConfigKeys.find((key) => key !== burnInConfigKey)

return snapshot(`missing key "${missingKey}"`, validate)
})
})

it(`does not allow keys to be zero`, () => {
const validate = validation.isValidBurnInConfig('burnIn', {
default: 0,
flaky: 0,
})

expect(validate).to.not.be.true

return snapshot(`keys cannot be zero`, validate)
})

it(`does not allow keys to be negative`, () => {
const validate = validation.isValidBurnInConfig('burnIn', {
default: -3,
flaky: -40,
})

expect(validate).to.not.be.true

return snapshot(`keys cannot be negative`, validate)
})

it(`does not allow keys to be floating point numbers`, () => {
const validate = validation.isValidBurnInConfig('burnIn', {
default: 5.7,
flaky: 8.22,
})

expect(validate).to.not.be.true

return snapshot(`keys cannot be floating point numbers`, validate)
})

it(`does not allow keys to be Infinity`, () => {
const validate = validation.isValidBurnInConfig('burnIn', {
default: Infinity,
flaky: Infinity,
})

expect(validate).to.not.be.true

return snapshot(`keys cannot be Infinity`, validate)
})

it(`tests lower bound`, () => {
const validate = validation.isValidBurnInConfig('burnIn', {
default: 1,
flaky: 1,
})

expect(validate).to.be.true
})

// TODO: revisit limit on 'dafault' and 'flaky' keys to set sane limits
it(`tests upper bound (currently no limit and is subject to change)`, () => {
const validate = validation.isValidBurnInConfig('burnIn', {
default: 100000,
flaky: 142342342,
})

expect(validate).to.be.true
})
})
})

0 comments on commit 62b1191

Please sign in to comment.