Skip to content

Commit

Permalink
Merge branch 'develop' into bugfix/cross-origin-snapshots
Browse files Browse the repository at this point in the history
  • Loading branch information
AtofStryker authored Nov 4, 2022
2 parents ae2d5cd + bf2fc3a commit 6fcb661
Show file tree
Hide file tree
Showing 10 changed files with 670 additions and 195 deletions.
26 changes: 17 additions & 9 deletions cli/types/cypress.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -775,20 +775,20 @@ declare namespace Cypress {
clear(options?: Partial<ClearOptions>): Chainable<Subject>

/**
* Clear a specific browser cookie.
* Clear a specific browser cookie for the current superdomain or for the domain specified.
* Cypress automatically clears all cookies before each test to prevent state from being shared across tests. You shouldn't need to use this command unless you're using it to clear a specific cookie inside a single test.
*
* @see https://on.cypress.io/clearcookie
*/
clearCookie(name: string, options?: Partial<Loggable & Timeoutable>): Chainable<null>
clearCookie(name: string, options?: CookieOptions): Chainable<null>

/**
* Clear all browser cookies.
* Cypress automatically clears all cookies before each test to prevent state from being shared across tests. You shouldn't need to use this command unless you're using it to clear a specific cookie inside a single test.
* Clear all browser cookies for the current superdomain or for the domain specified.
* Cypress automatically clears all cookies before each test to prevent state from being shared across tests. You shouldn't need to use this command unless you're using it to clear all cookies or specific cookies inside a single test.
*
* @see https://on.cypress.io/clearcookies
*/
clearCookies(options?: Partial<Loggable & Timeoutable>): Chainable<null>
clearCookies(options?: CookieOptions): Chainable<null>

/**
* Clear data in local storage.
Expand Down Expand Up @@ -1248,18 +1248,18 @@ declare namespace Cypress {
get<S = any>(alias: string, options?: Partial<Loggable & Timeoutable & Withinable & Shadow>): Chainable<S>

/**
* Get a browser cookie by its name.
* Get a browser cookie by its name for the current superdomain or for the domain specified.
*
* @see https://on.cypress.io/getcookie
*/
getCookie(name: string, options?: Partial<Loggable & Timeoutable>): Chainable<Cookie | null>
getCookie(name: string, options?: CookieOptions): Chainable<Cookie | null>

/**
* Get all of the browser cookies.
* Get all of the browser cookies for the current superdomain or for the domain specified.
*
* @see https://on.cypress.io/getcookies
*/
getCookies(options?: Partial<Loggable & Timeoutable>): Chainable<Cookie[]>
getCookies(options?: CookieOptions): Chainable<Cookie[]>

/**
* Navigate back or forward to the previous or next URL in the browser's history.
Expand Down Expand Up @@ -2633,6 +2633,14 @@ declare namespace Cypress {
cmdKey: boolean
}

interface CookieOptions extends Partial<Loggable & Timeoutable> {
/**
* Domain to set cookies on or get cookies from
* @default superdomain of the current app under test
*/
domain?: string
}

interface PEMCert {
/**
* Path to the certificate file, relative to project root.
Expand Down
80 changes: 80 additions & 0 deletions cli/types/tests/cypress-tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -936,6 +936,7 @@ namespace CypressSessionsTests {
validate: { foo: true } // $ExpectError
})
}

namespace CypressCurrentTest {
Cypress.currentTest.title // $ExpectType string
Cypress.currentTest.titlePath // $ExpectType string[]
Expand Down Expand Up @@ -974,3 +975,82 @@ namespace CypressOriginTests {
cy.origin('example.com', { args: ['value'] }, (value: boolean[]) => {}) // $ExpectError
cy.origin('example.com', {}, (value: undefined) => {}) // $ExpectError
}

namespace CypressGetCookiesTests {
cy.getCookies().then((cookies) => {
cookies // $ExpectType Cookie[]
})
cy.getCookies({ log: true })
cy.getCookies({ timeout: 10 })
cy.getCookies({ domain: 'localhost' })
cy.getCookies({ log: true, timeout: 10, domain: 'localhost' })

cy.getCookies({ log: 'true' }) // $ExpectError
cy.getCookies({ timeout: '10' }) // $ExpectError
cy.getCookies({ domain: false }) // $ExpectError
}

namespace CypressGetCookieTests {
cy.getCookie('name').then((cookie) => {
cookie // $ExpectType Cookie | null
})
cy.getCookie('name', { log: true })
cy.getCookie('name', { timeout: 10 })
cy.getCookie('name', { domain: 'localhost' })
cy.getCookie('name', { log: true, timeout: 10, domain: 'localhost' })

cy.getCookie('name', { log: 'true' }) // $ExpectError
cy.getCookie('name', { timeout: '10' }) // $ExpectError
cy.getCookie('name', { domain: false }) // $ExpectError
}

namespace CypressSetCookieTests {
cy.setCookie('name', 'value').then((cookie) => {
cookie // $ExpectType Cookie
})
cy.setCookie('name', 'value', { log: true })
cy.setCookie('name', 'value', { timeout: 10 })
cy.setCookie('name', 'value', {
domain: 'localhost',
path: '/',
secure: true,
httpOnly: false,
expiry: 12345,
sameSite: 'lax',
})
cy.setCookie('name', 'value', { log: true, timeout: 10, domain: 'localhost' })

cy.setCookie('name') // $ExpectError
cy.setCookie('name', 'value', { log: 'true' }) // $ExpectError
cy.setCookie('name', 'value', { timeout: '10' }) // $ExpectError
cy.setCookie('name', 'value', { domain: false }) // $ExpectError
cy.setCookie('name', 'value', { foo: 'bar' }) // $ExpectError
}

namespace CypressClearCookieTests {
cy.clearCookie('name').then((result) => {
result // $ExpectType null
})
cy.clearCookie('name', { log: true })
cy.clearCookie('name', { timeout: 10 })
cy.clearCookie('name', { domain: 'localhost' })
cy.clearCookie('name', { log: true, timeout: 10, domain: 'localhost' })

cy.clearCookie('name', { log: 'true' }) // $ExpectError
cy.clearCookie('name', { timeout: '10' }) // $ExpectError
cy.clearCookie('name', { domain: false }) // $ExpectError
}

namespace CypressClearCookiesTests {
cy.clearCookies().then((result) => {
result // $ExpectType null
})
cy.clearCookies({ log: true })
cy.clearCookies({ timeout: 10 })
cy.clearCookies({ domain: 'localhost' })
cy.clearCookies({ log: true, timeout: 10, domain: 'localhost' })

cy.clearCookies({ log: 'true' }) // $ExpectError
cy.clearCookies({ timeout: '10' }) // $ExpectError
cy.clearCookies({ domain: false }) // $ExpectError
}
Loading

0 comments on commit 6fcb661

Please sign in to comment.