Skip to content

Commit

Permalink
chore: Remove hardcoded domain for multi-domain (#19323)
Browse files Browse the repository at this point in the history
Co-authored-by: Chris Breiding <chrisbreiding@gmail.com>
Co-authored-by: Bill Glesias <bglesias@gmail.com>
  • Loading branch information
3 people authored Jan 12, 2022
1 parent a408b36 commit 2ee9893
Show file tree
Hide file tree
Showing 71 changed files with 2,099 additions and 824 deletions.
5 changes: 5 additions & 0 deletions cli/schema/cypress.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,11 @@
"default": false,
"description": "Allows listening to the `before:run`, `after:run`, `before:spec`, and `after:spec` events in the plugins file during interactive mode."
},
"experimentalMultiDomain": {
"type": "boolean",
"default": false,
"description": "Enables multi-domain support in Cypress, including the switchToDomain command."
},
"experimentalSourceRewriting": {
"type": "boolean",
"default": false,
Expand Down
55 changes: 54 additions & 1 deletion cli/types/cypress.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ declare namespace Cypress {
* @see https://on.cypress.io/firefox-gc-issue
*/
(task: 'firefox:force:gc'): Promise<void>
(task: 'ready:for:domain'): Promise<void>
(task: 'net', eventName: string, frame: any): Promise<void>
}

Expand Down Expand Up @@ -611,7 +612,7 @@ declare namespace Cypress {
* Trigger action
* @private
*/
action: (action: string, ...args: any[]) => void
action: (action: string, ...args: any[]) => any[] | void

/**
* Load files
Expand Down Expand Up @@ -1879,6 +1880,44 @@ declare namespace Cypress {
*/
spread(fn: (...args: any[]) => void): Chainable<Subject>

/**
* Enables running Cypress commands in a secondary domain
* @see https://on.cypress.io/switchToDomain
* @example
* cy.switchToDomain('example.com', () => {
* cy.get('h1').should('equal', 'Example Domain')
* })
*/
switchToDomain(domain: string, fn: () => void): Chainable<undefined>
/**
* Enables running Cypress commands in a secondary domain
* @see https://on.cypress.io/switchToDomain
* @example
* cy.switchToDomain('example.com', { key: 'value' } ({ key }) => {
* expect(key).to.equal('value')
* })
*/
switchToDomain<T>(domain: string, data: T, fn: (data: T) => void): Chainable<undefined>
/**
* Enables running Cypress commands in a secondary domain
* @see https://on.cypress.io/switchToDomain
* @example
* cy.switchToDomain('example.com', done, () => {
* done()
* })
*/
switchToDomain<T>(domain: string, done: Mocha.Done, fn: (data: T) => void): Chainable<undefined>
/**
* Enables running Cypress commands in a secondary domain
* @see https://on.cypress.io/switchToDomain
* @example
* cy.switchToDomain('example.com', done, { key: 'value' } ({ key }) => {
* expect(key).to.equal('value')
* done()
* })
*/
switchToDomain<T>(domain: string, done: Mocha.Done, data: T, fn: (data: T) => void): Chainable<undefined>

/**
* Run a task in Node via the plugins file.
*
Expand Down Expand Up @@ -2778,6 +2817,11 @@ declare namespace Cypress {
* @default false
*/
experimentalInteractiveRunEvents: boolean
/**
* Enables multi-domain support in Cypress, including the switchToDomain command.
* @default false
*/
experimentalMultiDomain: boolean
/**
* Generate and save commands directly to your test suite by interacting with your app as an end user would.
* @default false
Expand Down Expand Up @@ -5538,6 +5582,12 @@ declare namespace Cypress {
* @see https://on.cypress.io/catalog-of-events#App-Events
*/
(action: 'command:end', fn: (command: CommandQueue) => void): Cypress
/**
* Fires when a command is skipped, namely the `should` command.
* Useful for debugging and understanding how commands are handled.
* @see https://on.cypress.io/catalog-of-events#App-Events
*/
(action: 'skipped:command:end', fn: (command: CommandQueue) => void): Cypress
/**
* Fires whenever a command begins its retrying routines.
* This is called on the trailing edge after Cypress has internally
Expand Down Expand Up @@ -5628,10 +5678,13 @@ declare namespace Cypress {
}

interface EnqueuedCommand {
id: string
name: string
args: any[]
type: string
chainerId: string
injected: boolean
userInvocationStack?: string
fn(...args: any[]): any
}

Expand Down
16 changes: 16 additions & 0 deletions cli/types/tests/cypress-tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -827,3 +827,19 @@ namespace CypressKeyboardTests {
delay: 500 // $ExpectError
})
}

namespace CypressMultiDomainTests {
cy.switchToDomain('example.com', () => {})
cy.switchToDomain('example.com', {}, (value: object) => {})
cy.switchToDomain('example.com', [], (value: any[]) => {})
cy.switchToDomain('example.com', 'value', (value: string) => {})
cy.switchToDomain('example.com', 1, (value: number) => {})
cy.switchToDomain('example.com', true, (value: boolean) => {})

cy.switchToDomain() // $ExpectError
cy.switchToDomain('example.com') // $ExpectError
cy.switchToDomain(true) // $ExpectError
cy.switchToDomain('example.com', {}) // $ExpectError
cy.switchToDomain('example.com', {}, {}) // $ExpectError
cy.switchToDomain('example.com', 'value', (value: boolean) => {}) // $ExpectError
}
10 changes: 6 additions & 4 deletions packages/config/__snapshots__/index_spec.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
exports['src/index .getBreakingKeys returns list of breaking config keys 1'] = [
exports['config/lib/index .getBreakingKeys returns list of breaking config keys 1'] = [
"blacklistHosts",
"experimentalComponentTesting",
"experimentalGetCookiesSameSite",
Expand All @@ -10,7 +10,7 @@ exports['src/index .getBreakingKeys returns list of breaking config keys 1'] = [
"nodeVersion"
]

exports['src/index .getDefaultValues returns list of public config keys 1'] = {
exports['config/lib/index .getDefaultValues returns list of public config keys 1'] = {
"animationDistanceThreshold": 5,
"baseUrl": null,
"blockHosts": null,
Expand All @@ -26,6 +26,7 @@ exports['src/index .getDefaultValues returns list of public config keys 1'] = {
"exit": true,
"experimentalFetchPolyfill": false,
"experimentalInteractiveRunEvents": false,
"experimentalMultiDomain": false,
"experimentalSessionSupport": false,
"experimentalSourceRewriting": false,
"experimentalStudio": false,
Expand All @@ -34,7 +35,6 @@ 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,
Expand Down Expand Up @@ -77,6 +77,7 @@ exports['src/index .getDefaultValues returns list of public config keys 1'] = {
"configFile": "cypress.json",
"devServerPublicPathRoute": "/__cypress/src",
"hosts": null,
"isInteractive": true,
"isTextTerminal": false,
"morgan": true,
"namespace": "__cypress",
Expand All @@ -87,7 +88,7 @@ exports['src/index .getDefaultValues returns list of public config keys 1'] = {
"xhrRoute": "/xhrs/"
}

exports['src/index .getPublicConfigKeys returns list of public config keys 1'] = [
exports['config/lib/index .getPublicConfigKeys returns list of public config keys 1'] = [
"animationDistanceThreshold",
"baseUrl",
"blockHosts",
Expand All @@ -103,6 +104,7 @@ exports['src/index .getPublicConfigKeys returns list of public config keys 1'] =
"exit",
"experimentalFetchPolyfill",
"experimentalInteractiveRunEvents",
"experimentalMultiDomain",
"experimentalSessionSupport",
"experimentalSourceRewriting",
"experimentalStudio",
Expand Down
152 changes: 76 additions & 76 deletions packages/config/__snapshots__/validation_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,71 @@ 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'] = {
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['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['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['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: \`""\`
`

exports['config/lib/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['config/lib/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['config/lib/validation .isValidBrowser passes valid browsers and forms error messages for invalid ones isValidBrowser 1'] = {
"name": "isValidBrowser",
"behavior": [
{
Expand Down Expand Up @@ -64,94 +128,30 @@ exports['src/validation .isValidBrowser passes valid browsers and forms error me
]
}

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['config/lib/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['null instead of a number'] = `
Expected \`test\` to be one of these values: 1, 2, 3. Instead the value was: \`null\`
exports['config/lib/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['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['config/lib/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 .isBoolean returns error message when value is a not a string 1'] = `
exports['config/lib/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'] = `
exports['config/lib/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'] = `
exports['config/lib/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['config/lib/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['empty string'] = `
Expected \`mockConfigKey\` to be a fully qualified URL (starting with \`http://\` or \`https://\`). Instead the value was: \`""\`
`
6 changes: 6 additions & 0 deletions packages/config/lib/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,12 @@ const resolvedOptions: Array<ResolvedConfigOption> = [
validation: validate.isBoolean,
isExperimental: true,
canUpdateDuringTestTime: false,
}, {
name: 'experimentalMultiDomain',
defaultValue: false,
validation: validate.isBoolean,
isExperimental: true,
canUpdateDuringTestTime: false,
}, {
name: 'experimentalSessionSupport',
defaultValue: false,
Expand Down
2 changes: 1 addition & 1 deletion packages/config/test/unit/index_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const configUtil = require('../../lib/index')
chai.use(sinonChai)
const { expect } = chai

describe('src/index', () => {
describe('config/lib/index', () => {
describe('.allowed', () => {
it('returns filter config only containing allowed keys', () => {
const keys = configUtil.allowed({
Expand Down
2 changes: 1 addition & 1 deletion packages/config/test/unit/validation_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const { expect } = require('chai')

const validation = require('../../lib/validation')

describe('src/validation', () => {
describe('config/lib/validation', () => {
const mockKey = 'mockConfigKey'

describe('.isValidClientCertificatesSet', () => {
Expand Down
Loading

0 comments on commit 2ee9893

Please sign in to comment.