Skip to content

Commit

Permalink
fix: throw when writing to 'read only' properties of config (#18896)
Browse files Browse the repository at this point in the history
Co-authored-by: Emily Rohrbough  <emilyrohrbough@users.noreply.github.com>
  • Loading branch information
davidmunechika and emilyrohrbough authored Dec 10, 2021
1 parent f79bdd6 commit dd0fc9b
Show file tree
Hide file tree
Showing 22 changed files with 314 additions and 17 deletions.
6 changes: 3 additions & 3 deletions cli/types/cypress.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ declare namespace Cypress {
// 60000
```
*/
config<K extends keyof ConfigOptions>(key: K): ResolvedConfigOptions[K]
config<K extends keyof Config>(key: K): Config[K]
/**
* Sets one configuration value.
* @see https://on.cypress.io/config
Expand All @@ -337,7 +337,7 @@ declare namespace Cypress {
Cypress.config('viewportWidth', 800)
```
*/
config<K extends keyof ConfigOptions>(key: K, value: ResolvedConfigOptions[K]): void
config<K extends keyof TestConfigOverrides>(key: K, value: TestConfigOverrides[K]): void
/**
* Sets multiple configuration values at once.
* @see https://on.cypress.io/config
Expand Down Expand Up @@ -2879,7 +2879,7 @@ declare namespace Cypress {
xhrUrl: string
}

interface TestConfigOverrides extends Partial<Pick<ConfigOptions, 'animationDistanceThreshold' | 'baseUrl' | 'defaultCommandTimeout' | 'env' | 'execTimeout' | 'includeShadowDom' | 'requestTimeout' | 'responseTimeout' | 'retries' | 'scrollBehavior' | 'taskTimeout' | 'viewportHeight' | 'viewportWidth' | 'waitForAnimations'>> {
interface TestConfigOverrides extends Partial<Pick<ConfigOptions, 'animationDistanceThreshold' | 'baseUrl' | 'blockHosts' | 'defaultCommandTimeout' | 'env' | 'execTimeout' | 'includeShadowDom' | 'numTestsKeptInMemory' | 'pageLoadTimeout' | 'redirectionLimit' | 'requestTimeout' | 'responseTimeout' | 'retries' | 'screenshotOnRunFailure' | 'slowTestThreshold' | 'scrollBehavior' | 'taskTimeout' | 'viewportHeight' | 'viewportWidth' | 'waitForAnimations'>> {
browser?: IsBrowserMatcher | IsBrowserMatcher[]
keystrokeDelay?: number
}
Expand Down
6 changes: 6 additions & 0 deletions packages/config/__snapshots__/index_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ exports['src/index .getDefaultValues returns list of public config keys 1'] = {
"e2e": {},
"env": {},
"execTimeout": 60000,
"exit": true,
"experimentalFetchPolyfill": false,
"experimentalInteractiveRunEvents": false,
"experimentalSessionSupport": false,
Expand All @@ -33,6 +34,8 @@ exports['src/index .getDefaultValues returns list of public config keys 1'] = {
"ignoreTestFiles": "*.hot-update.js",
"includeShadowDom": false,
"integrationFolder": "cypress/integration",
"isInteractive": true,
"keystrokeDelay": 0,
"modifyObstructiveCode": true,
"numTestsKeptInMemory": 50,
"pageLoadTimeout": 60000,
Expand Down Expand Up @@ -97,6 +100,7 @@ exports['src/index .getPublicConfigKeys returns list of public config keys 1'] =
"e2e",
"env",
"execTimeout",
"exit",
"experimentalFetchPolyfill",
"experimentalInteractiveRunEvents",
"experimentalSessionSupport",
Expand All @@ -107,6 +111,7 @@ exports['src/index .getPublicConfigKeys returns list of public config keys 1'] =
"ignoreTestFiles",
"includeShadowDom",
"integrationFolder",
"keystrokeDelay",
"modifyObstructiveCode",
"nodeVersion",
"numTestsKeptInMemory",
Expand Down Expand Up @@ -142,5 +147,6 @@ exports['src/index .getPublicConfigKeys returns list of public config keys 1'] =
"watchForFileChanges",
"browsers",
"hosts",
"isInteractive",
"modifyObstructiveCode"
]
2 changes: 1 addition & 1 deletion packages/config/__snapshots__/validation_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -154,4 +154,4 @@ Expected \`mockConfigKey\` to be a fully qualified URL (starting with \`http://\

exports['empty string'] = `
Expected \`mockConfigKey\` to be a fully qualified URL (starting with \`http://\` or \`https://\`). Instead the value was: \`""\`
`
`
13 changes: 13 additions & 0 deletions packages/config/lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ const breakingKeys = _.map(breakingOptions, 'name')
const defaultValues = createIndex(options, 'name', 'defaultValue')
const publicConfigKeys = _(options).reject({ isInternal: true }).map('name').value()
const validationRules = createIndex(options, 'name', 'validation')
const testConfigOverrideOptions = createIndex(options, 'name', 'canUpdateDuringTestTime')

module.exports = {
allowed: (obj = {}) => {
Expand Down Expand Up @@ -101,4 +102,16 @@ module.exports = {
}
})
},

validateNoReadOnlyConfig: (config, onErr) => {
let errProperty

Object.keys(config).some((option) => {
return errProperty = testConfigOverrideOptions[option] === false ? option : undefined
})

if (errProperty) {
return onErr(errProperty)
}
},
}
Loading

3 comments on commit dd0fc9b

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on dd0fc9b Dec 10, 2021

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.

Learn more about this pre-release platform-specific build at https://on.cypress.io/installing-cypress#Install-pre-release-version.

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/9.1.2/circle-develop-dd0fc9b9f7167f6d02a96f3c10a1bc1dee98f785/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on dd0fc9b Dec 10, 2021

Choose a reason for hiding this comment

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

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

Learn more about this pre-release platform-specific build at https://on.cypress.io/installing-cypress#Install-pre-release-version.

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/9.1.2/circle-develop-dd0fc9b9f7167f6d02a96f3c10a1bc1dee98f785/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on dd0fc9b Dec 10, 2021

Choose a reason for hiding this comment

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

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

Learn more about this pre-release platform-specific build at https://on.cypress.io/installing-cypress#Install-pre-release-version.

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/9.1.2/circle-develop-dd0fc9b9f7167f6d02a96f3c10a1bc1dee98f785/cypress.tgz

Please sign in to comment.