Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Update switchToDomain signature with args key #20722

Merged
merged 13 commits into from
Mar 24, 2022
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions cli/types/cypress.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1912,16 +1912,22 @@ declare namespace Cypress {
* })
*/
switchToDomain(originOrDomain: string, fn: () => void): Chainable

// TODO: when we find other options to put into the 'data' argument of switchToDomain, we may want to overload this type with
// a 'data' paramater that contains all data options, including args, and one that contains all data options, excluding args.
// This will provide better typings support for whatever args is set to as opposed to an optional undefined
/**
* Enables running Cypress commands in a secondary domain
* @see https://on.cypress.io/switchToDomain
* @example
* cy.switchToDomain('example.com', [{ key: 'value' }, 'foo'], ([{ key }, foo]) => {
* cy.switchToDomain('example.com', { args: { key: 'value', foo: 'foo' } }, ({ key, foo }) => {
* expect(key).to.equal('value')
* expect(foo).to.equal('foo')
* })
*/
switchToDomain<T>(originOrDomain: string, data: T[], fn: (data: T[]) => void): Chainable
switchToDomain<T>(originOrDomain: string, data: {
AtofStryker marked this conversation as resolved.
Show resolved Hide resolved
args: T
}, fn: (data: T) => void): Chainable

/**
* Run a task in Node via the plugins file.
Expand Down
15 changes: 8 additions & 7 deletions cli/types/tests/cypress-tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -830,17 +830,18 @@ namespace CypressKeyboardTests {

namespace CypressMultiDomainTests {
cy.switchToDomain('example.com', () => {})
cy.switchToDomain('example.com', [{}], (value: object[]) => {})
cy.switchToDomain('example.com', [], (value: any[]) => {})
cy.switchToDomain('example.com', [1, 'value', {}, true], (value: Array<string | number | boolean | {}>) => {})
cy.switchToDomain('example.com', ['value'], (value: string[]) => {})
cy.switchToDomain('example.com', [1], (value: number[]) => {})
cy.switchToDomain('example.com', [true], (value: boolean[]) => {})
cy.switchToDomain('example.com', { args: {}}, (value: object) => {})
cy.switchToDomain('example.com', { args: { one: 1, key: 'value', bool: true } }, (value: { one: number, key: string, bool: boolean}) => {})
cy.switchToDomain('example.com', { args: [1, 'value', true ] }, (value: Array<(number | string | boolean)>) => {})
cy.switchToDomain('example.com', { args : 'value'}, (value: string) => {})
cy.switchToDomain('example.com', { args: 1 }, (value: number) => {})
cy.switchToDomain('example.com', { args: 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
cy.switchToDomain('example.com', { args: ['value'] }, (value: boolean[]) => {}) // $ExpectError
cy.switchToDomain('example.com', {}, (value: undefined) => {}) // $ExpectError
}
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ describe('basic login', { experimentalSessionSupport: true }, () => {
const login = (name) => {
cy.session(name, () => {
// Note, this assumes localhost is the primary domain, ideally we'd be able to specify this directly.
cy.switchToDomain('http://idp.com:3500', [name], ([name]) => {
cy.switchToDomain('http://idp.com:3500', { args: name }, (name) => {
cy.visit('http://www.idp.com:3500/fixtures/auth/idp.html')
cy.get('[data-cy="username"]').type(name)
cy.get('[data-cy="login"]').click()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ context('multi-domain screenshot', { experimentalSessionSupport: true }, () => {
})

it('captures the fullPage', () => {
cy.switchToDomain('http://foobar.com:3500', [this.serverResult], ([serverResult]) => {
cy.switchToDomain('http://foobar.com:3500', { args: this.serverResult }, (serverResult) => {
const automationStub = cy.stub(Cypress, 'automation').withArgs('take:screenshot').resolves(serverResult)

cy.screenshot({ capture: 'fullPage' })
Expand All @@ -36,7 +36,7 @@ context('multi-domain screenshot', { experimentalSessionSupport: true }, () => {
})

it('captures the runner', () => {
cy.switchToDomain('http://foobar.com:3500', [this.serverResult], ([serverResult]) => {
cy.switchToDomain('http://foobar.com:3500', { args: this.serverResult }, (serverResult) => {
const automationStub = cy.stub(Cypress, 'automation').withArgs('take:screenshot').resolves(serverResult)

cy.screenshot({ capture: 'runner' })
Expand All @@ -48,7 +48,7 @@ context('multi-domain screenshot', { experimentalSessionSupport: true }, () => {
})

it('captures the viewport', () => {
cy.switchToDomain('http://foobar.com:3500', [this.serverResult], ([serverResult]) => {
cy.switchToDomain('http://foobar.com:3500', { args: this.serverResult }, (serverResult) => {
const automationStub = cy.stub(Cypress, 'automation').withArgs('take:screenshot').resolves(serverResult)

cy.screenshot({ capture: 'viewport' })
Expand Down Expand Up @@ -80,7 +80,7 @@ context('multi-domain screenshot', { experimentalSessionSupport: true }, () => {
})

it('supports multiple titles', () => {
cy.switchToDomain('http://foobar.com:3500', [this.serverResult], ([serverResult]) => {
cy.switchToDomain('http://foobar.com:3500', { args: this.serverResult }, (serverResult) => {
const automationStub = cy.stub(Cypress, 'automation').withArgs('take:screenshot').resolves(serverResult)

cy.screenshot()
Expand All @@ -91,7 +91,7 @@ context('multi-domain screenshot', { experimentalSessionSupport: true }, () => {
})

it('supports the blackout option', () => {
cy.switchToDomain('http://foobar.com:3500', [this.serverResult], ([serverResult]) => {
cy.switchToDomain('http://foobar.com:3500', { args: this.serverResult }, (serverResult) => {
cy.stub(Cypress, 'automation').withArgs('take:screenshot').resolves(serverResult)

cy.screenshot({
Expand All @@ -109,7 +109,7 @@ context('multi-domain screenshot', { experimentalSessionSupport: true }, () => {
})

it('supports element screenshots', () => {
cy.switchToDomain('http://foobar.com:3500', [this.serverResult], ([serverResult]) => {
cy.switchToDomain('http://foobar.com:3500', { args: this.serverResult }, (serverResult) => {
const automationStub = cy.stub(Cypress, 'automation').withArgs('take:screenshot').resolves(serverResult)

cy.get('.tall-element').screenshot()
Expand All @@ -121,7 +121,7 @@ context('multi-domain screenshot', { experimentalSessionSupport: true }, () => {
})

it('supports screenshot retrying with appropriate naming', () => {
cy.switchToDomain('http://foobar.com:3500', [this.serverResult], ([serverResult]) => {
cy.switchToDomain('http://foobar.com:3500', { args: this.serverResult }, (serverResult) => {
const automationStub = cy.stub(Cypress, 'automation').withArgs('take:screenshot').resolves(serverResult)

cy.state('runnable')._currentRetry = 2
Expand All @@ -134,7 +134,7 @@ context('multi-domain screenshot', { experimentalSessionSupport: true }, () => {
})

it('calls the onBeforeScreenshot callback', () => {
cy.switchToDomain('http://foobar.com:3500', [this.serverResult], ([serverResult]) => {
cy.switchToDomain('http://foobar.com:3500', { args: this.serverResult }, (serverResult) => {
cy.stub(Cypress, 'automation').withArgs('take:screenshot').resolves(serverResult)
const onBeforeScreenshot = cy.stub()

Expand All @@ -144,7 +144,7 @@ context('multi-domain screenshot', { experimentalSessionSupport: true }, () => {
})

it('calls the onAfterScreenshot callback', () => {
cy.switchToDomain('http://foobar.com:3500', [this.serverResult], ([serverResult]) => {
cy.switchToDomain('http://foobar.com:3500', { args: this.serverResult }, (serverResult) => {
cy.stub(Cypress, 'automation').withArgs('take:screenshot').resolves(serverResult)
const onAfterScreenshot = cy.stub()

Expand All @@ -154,7 +154,7 @@ context('multi-domain screenshot', { experimentalSessionSupport: true }, () => {
})

it('supports the Cypress.screenshot callbacks', () => {
cy.switchToDomain('http://foobar.com:3500', [this.serverResult], ([serverResult]) => {
cy.switchToDomain('http://foobar.com:3500', { args: this.serverResult }, (serverResult) => {
cy.stub(Cypress, 'automation').withArgs('take:screenshot').resolves(serverResult)
const onAfterScreenshot = cy.stub()
const onBeforeScreenshot = cy.stub()
Expand All @@ -171,7 +171,7 @@ context('multi-domain screenshot', { experimentalSessionSupport: true }, () => {
})

it('supports pausing timers', () => {
cy.switchToDomain('http://foobar.com:3500', [this.serverResult], ([serverResult]) => {
cy.switchToDomain('http://foobar.com:3500', { args: this.serverResult }, (serverResult) => {
cy.stub(Cypress, 'automation').withArgs('take:screenshot').returns(Cypress.Promise.delay(500, serverResult))

cy.window().then((win) => {
Expand Down Expand Up @@ -204,7 +204,7 @@ context('multi-domain screenshot', { experimentalSessionSupport: true }, () => {
})

it('does not pause timers when disableTimersAndAnimations is false', () => {
cy.switchToDomain('http://foobar.com:3500', [this.serverResult], ([serverResult]) => {
cy.switchToDomain('http://foobar.com:3500', { args: this.serverResult }, (serverResult) => {
cy.stub(Cypress, 'automation').withArgs('take:screenshot').returns(Cypress.Promise.delay(500, serverResult))

cy.window().then((win) => {
Expand Down Expand Up @@ -234,7 +234,7 @@ context('multi-domain screenshot', { experimentalSessionSupport: true }, () => {
expect(err.message).to.include('setTimeout error after screenshot')
})

cy.switchToDomain('http://foobar.com:3500', [this.serverResult], ([serverResult]) => {
cy.switchToDomain('http://foobar.com:3500', { args: this.serverResult }, (serverResult) => {
cy.stub(Cypress, 'automation').withArgs('take:screenshot').returns(Cypress.Promise.delay(100, serverResult))

cy.window().then((win) => {
Expand All @@ -260,7 +260,7 @@ context('multi-domain screenshot', { experimentalSessionSupport: true }, () => {
expect(err.docsUrl).to.deep.eq(['https://on.cypress.io/uncaught-exception-from-application'])
})

cy.switchToDomain('http://foobar.com:3500', [this.serverResult], ([serverResult]) => {
cy.switchToDomain('http://foobar.com:3500', { args: this.serverResult }, (serverResult) => {
cy.stub(Cypress, 'automation').withArgs('take:screenshot').returns(Cypress.Promise.delay(100, serverResult))

cy.window().then((win) => {
Expand Down
Loading