Skip to content

Commit

Permalink
feat: create config package for config validation (#18589)
Browse files Browse the repository at this point in the history
  • Loading branch information
emilyrohrbough committed Nov 9, 2021
1 parent 628202e commit 99c8d46
Show file tree
Hide file tree
Showing 65 changed files with 5,205 additions and 1,193 deletions.
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ system-tests/projects/e2e/cypress/integration/typescript_syntax_error_spec.ts

# cli/types is linted by tslint/dtslint
cli/types

# packages/example is not linted (think about changing this)
packages/example

Expand Down
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,16 @@ cypress.zip
Cached Theme.pak
Cached Theme Material Design.pak

# from config, compiled .js files
packages/config/lib/*.js

# from data-context, compiled .js files
packages/data-context/src/**/*.js

# from desktop-gui
packages/desktop-gui/cypress/videos
packages/desktop-gui/src/jsconfig.json


# from driver
packages/driver/cypress/videos
packages/driver/cypress/screenshots
Expand Down
4 changes: 3 additions & 1 deletion .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
{
// To see these extensions in VS Code:
// 1. Open the Command Palette (Ctrl+Shift+P)
// 1. Open the Command Palette:
// - Non-Mac Users: (Ctrl+Shift+P)
// - Mac Users: (Cmd+Shift+P)
// 2. Select "Extensions: Show Recommended Extensions"

// See https://go.microsoft.com/fwlink/?LinkId=827846 to learn about workspace recommendations.
Expand Down
2 changes: 1 addition & 1 deletion circle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -963,7 +963,7 @@ jobs:
desktop-gui-component-tests,
cli-visual-tests,
runner-integration-tests-chrome,
runner-ct-integration-tests-chrome
runner-ct-integration-tests-chrome,
reporter-integration-tests,
- run: yarn percy build:finalize

Expand Down
1 change: 1 addition & 0 deletions cli/schema/cypress.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"properties": {
"baseUrl": {
"type": "string",
"default": null,
"description": "Url used as prefix for cy.visit() or cy.request() command’s url. Example http://localhost:3030 or https://test.my-domain.com"
},
"env": {
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"bump": "node ./scripts/binary.js bump",
"check-node-version": "node scripts/check-node-version.js",
"check-terminal": "node scripts/check-terminal.js",
"clean": "lerna run clean --parallel",
"clean": "lerna run clean --parallel --no-bail",
"clean-deps": "find . -depth -name node_modules -type d -exec rm -rf {} \\;",
"clean-untracked-files": "git clean -d -f",
"precypress:open": "yarn ensure-deps",
Expand Down Expand Up @@ -46,7 +46,7 @@
"stop-only": "npx stop-only --skip .cy,.publish,.projects,node_modules,dist,dist-test,fixtures,lib,bower_components,src,__snapshots__ --exclude e2e.ts,cypress-tests.ts",
"stop-only-all": "yarn stop-only --folder packages",
"pretest": "yarn ensure-deps",
"test": "yarn lerna exec yarn test --scope cypress --scope \"'@packages/{electron,extension,https-proxy,launcher,net-stubbing,network,proxy,rewriter,runner,runner-shared,socket}'\"",
"test": "yarn lerna exec yarn test --scope cypress --scope \"'@packages/{config,electron,extension,https-proxy,launcher,net-stubbing,network,proxy,rewriter,runner,runner-shared,socket}'\"",
"test-debug": "lerna exec yarn test-debug --ignore \"'@packages/{desktop-gui,driver,root,static,web-config}'\"",
"pretest-e2e": "yarn ensure-deps",
"test-integration": "lerna exec yarn test-integration --ignore \"'@packages/{desktop-gui,driver,root,static,web-config}'\"",
Expand Down
6 changes: 6 additions & 0 deletions packages/config/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"extends": [
"../../.eslintrc.json"
],
"parser": "@typescript-eslint/parser"
}
11 changes: 11 additions & 0 deletions packages/config/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Config

The `config` package contains the configuration types and validation used in both the `server` and the `driver` for setting the Cypress configuration values.

## Testing

### Unit Tests

```bash
yarn workspace @packages/config test-unit
```
146 changes: 146 additions & 0 deletions packages/config/__snapshots__/index_spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
exports['src/index .getBreakingKeys returns list of breaking config keys 1'] = [
"blacklistHosts",
"experimentalComponentTesting",
"experimentalGetCookiesSameSite",
"experimentalNetworkStubbing",
"experimentalRunEvents",
"experimentalShadowDomSupport",
"firefoxGcInterval",
"nodeVersion",
"nodeVersion"
]

exports['src/index .getDefaultValues returns list of public config keys 1'] = {
"animationDistanceThreshold": 5,
"baseUrl": null,
"blockHosts": null,
"chromeWebSecurity": true,
"clientCertificates": [],
"component": {},
"componentFolder": "cypress/component",
"defaultCommandTimeout": 4000,
"downloadsFolder": "cypress/downloads",
"e2e": {},
"env": {},
"execTimeout": 60000,
"experimentalFetchPolyfill": false,
"experimentalInteractiveRunEvents": false,
"experimentalSessionSupport": false,
"experimentalSourceRewriting": false,
"experimentalStudio": false,
"fileServerFolder": "",
"fixturesFolder": "cypress/fixtures",
"ignoreTestFiles": "*.hot-update.js",
"includeShadowDom": false,
"integrationFolder": "cypress/integration",
"modifyObstructiveCode": true,
"numTestsKeptInMemory": 50,
"pageLoadTimeout": 60000,
"pluginsFile": "cypress/plugins",
"port": null,
"projectId": null,
"redirectionLimit": 20,
"reporter": "spec",
"reporterOptions": null,
"requestTimeout": 5000,
"resolvedNodePath": null,
"resolvedNodeVersion": null,
"responseTimeout": 30000,
"retries": {
"runMode": 0,
"openMode": 0
},
"screenshotOnRunFailure": true,
"screenshotsFolder": "cypress/screenshots",
"slowTestThreshold": 10000,
"scrollBehavior": "top",
"supportFile": "cypress/support",
"supportFolder": false,
"taskTimeout": 60000,
"testFiles": "**/*.*",
"trashAssetsBeforeRuns": true,
"userAgent": null,
"video": true,
"videoCompression": 32,
"videosFolder": "cypress/videos",
"videoUploadOnPasses": true,
"viewportHeight": 660,
"viewportWidth": 1000,
"waitForAnimations": true,
"watchForFileChanges": true,
"autoOpen": false,
"browsers": [],
"clientRoute": "/__/",
"configFile": "cypress.json",
"devServerPublicPathRoute": "/__cypress/src",
"hosts": null,
"isTextTerminal": false,
"morgan": true,
"namespace": "__cypress",
"reporterRoute": "/__cypress/reporter",
"socketId": null,
"socketIoCookie": "__socket.io",
"socketIoRoute": "/__socket.io",
"xhrRoute": "/xhrs/"
}

exports['src/index .getPublicConfigKeys returns list of public config keys 1'] = [
"animationDistanceThreshold",
"baseUrl",
"blockHosts",
"chromeWebSecurity",
"clientCertificates",
"component",
"componentFolder",
"defaultCommandTimeout",
"downloadsFolder",
"e2e",
"env",
"execTimeout",
"experimentalFetchPolyfill",
"experimentalInteractiveRunEvents",
"experimentalSessionSupport",
"experimentalSourceRewriting",
"experimentalStudio",
"fileServerFolder",
"fixturesFolder",
"ignoreTestFiles",
"includeShadowDom",
"integrationFolder",
"modifyObstructiveCode",
"nodeVersion",
"numTestsKeptInMemory",
"pageLoadTimeout",
"pluginsFile",
"port",
"projectId",
"redirectionLimit",
"reporter",
"reporterOptions",
"requestTimeout",
"resolvedNodePath",
"resolvedNodeVersion",
"responseTimeout",
"retries",
"screenshotOnRunFailure",
"screenshotsFolder",
"slowTestThreshold",
"scrollBehavior",
"supportFile",
"supportFolder",
"taskTimeout",
"testFiles",
"trashAssetsBeforeRuns",
"userAgent",
"video",
"videoCompression",
"videosFolder",
"videoUploadOnPasses",
"viewportHeight",
"viewportWidth",
"waitForAnimations",
"watchForFileChanges",
"browsers",
"hosts",
"modifyObstructiveCode"
]
157 changes: 157 additions & 0 deletions packages/config/__snapshots__/validation_spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
exports['undefined browsers'] = `
Missing browsers list
`

exports['empty list of browsers'] = `
Expected at least one browser
`

exports['browsers list with a string'] = `
Found an error while validating the \`browsers\` list. Expected \`name\` to be a non-empty string. Instead the value was: \`"foo"\`
`

exports['src/validation .isValidBrowser passes valid browsers and forms error messages for invalid ones isValidBrowser 1'] = {
"name": "isValidBrowser",
"behavior": [
{
"given": {
"name": "Chrome",
"displayName": "Chrome Browser",
"family": "chromium",
"path": "/path/to/chrome",
"version": "1.2.3",
"majorVersion": 1
},
"expect": true
},
{
"given": {
"name": "FF",
"displayName": "Firefox",
"family": "firefox",
"path": "/path/to/firefox",
"version": "1.2.3",
"majorVersion": "1"
},
"expect": true
},
{
"given": {
"name": "Electron",
"displayName": "Electron",
"family": "chromium",
"path": "",
"version": "99.101.3",
"majorVersion": 99
},
"expect": true
},
{
"given": {
"name": "No display name",
"family": "chromium"
},
"expect": "Expected `displayName` to be a non-empty string. Instead the value was: `{\"name\":\"No display name\",\"family\":\"chromium\"}`"
},
{
"given": {
"name": "bad family",
"displayName": "Bad family browser",
"family": "unknown family"
},
"expect": "Expected `family` to be either chromium or firefox. Instead the value was: `{\"name\":\"bad family\",\"displayName\":\"Bad family browser\",\"family\":\"unknown family\"}`"
}
]
}

exports['not one of the strings error message'] = `
Expected \`test\` to be one of these values: "foo", "bar". Instead the value was: \`"nope"\`
`

exports['number instead of string'] = `
Expected \`test\` to be one of these values: "foo", "bar". Instead the value was: \`42\`
`

exports['null instead of string'] = `
Expected \`test\` to be one of these values: "foo", "bar". Instead the value was: \`null\`
`

exports['not one of the numbers error message'] = `
Expected \`test\` to be one of these values: 1, 2, 3. Instead the value was: \`4\`
`

exports['string instead of a number'] = `
Expected \`test\` to be one of these values: 1, 2, 3. Instead the value was: \`"foo"\`
`

exports['null instead of a number'] = `
Expected \`test\` to be one of these values: 1, 2, 3. Instead the value was: \`null\`
`

exports['src/validation .isStringOrFalse returns error message when value is neither string nor false 1'] = `
Expected \`mockConfigKey\` to be a string or false. Instead the value was: \`null\`
`

exports['src/validation .isBoolean returns error message when value is a not a string 1'] = `
Expected \`mockConfigKey\` to be a string. Instead the value was: \`1\`
`

exports['src/validation .isString returns error message when value is a not a string 1'] = `
Expected \`mockConfigKey\` to be a string. Instead the value was: \`1\`
`

exports['src/validation .isArray returns error message when value is a non-array 1'] = `
Expected \`mockConfigKey\` to be an array. Instead the value was: \`1\`
`

exports['not string or array'] = `
Expected \`mockConfigKey\` to be a string or an array of strings. Instead the value was: \`null\`
`

exports['array of non-strings'] = `
Expected \`mockConfigKey\` to be a string or an array of strings. Instead the value was: \`[1,2,3]\`
`

exports['src/validation .isNumberOrFalse returns error message when value is a not number or false 1'] = `
Expected \`mockConfigKey\` to be a number or false. Instead the value was: \`null\`
`

exports['src/validation .isPlainObject returns error message when value is a not an object 1'] = `
Expected \`mockConfigKey\` to be a plain object. Instead the value was: \`1\`
`

exports['src/validation .isNumber returns error message when value is a not a number 1'] = `
Expected \`mockConfigKey\` to be a number. Instead the value was: \`"string"\`
`

exports['invalid retry value'] = `
Expected \`mockConfigKey\` to be a positive number or null or an object with keys "openMode" and "runMode" with values of numbers or nulls. Instead the value was: \`"1"\`
`

exports['invalid retry object'] = `
Expected \`mockConfigKey\` to be a positive number or null or an object with keys "openMode" and "runMode" with values of numbers or nulls. Instead the value was: \`{"fakeMode":1}\`
`

exports['src/validation .isValidClientCertificatesSet returns error message for certs not passed as an array array 1'] = `
Expected \`mockConfigKey\` to be a positive number or null or an object with keys "openMode" and "runMode" with values of numbers or nulls. Instead the value was: \`"1"\`
`

exports['src/validation .isValidClientCertificatesSet returns error message for certs object without url 1'] = `
Expected \`clientCertificates[0].url\` to be a URL matcher. Instead the value was: \`undefined\`
`

exports['missing https protocol'] = `
Expected \`clientCertificates[0].url\` to be an https protocol. Instead the value was: \`"http://url.com"\`
`

exports['invalid url'] = `
Expected \`clientCertificates[0].url\` to be a valid URL. Instead the value was: \`"not *"\`
`

exports['not qualified url'] = `
Expected \`mockConfigKey\` to be a fully qualified URL (starting with \`http://\` or \`https://\`). Instead the value was: \`"url.com"\`
`

exports['empty string'] = `
Expected \`mockConfigKey\` to be a fully qualified URL (starting with \`http://\` or \`https://\`). Instead the value was: \`""\`
`

2 comments on commit 99c8d46

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 99c8d46 Nov 9, 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/8.8.0/circle-9.0-release-99c8d466c8dc675b381a98d5a16c50f05232dc78/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 99c8d46 Nov 9, 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/8.8.0/circle-9.0-release-99c8d466c8dc675b381a98d5a16c50f05232dc78/cypress.tgz

Please sign in to comment.