mirror of
https://github.com/cypress-io/cypress.git
synced 2026-04-28 10:49:48 -05:00
feat: Add domain option to cookie commands (#24471)
This commit is contained in:
Vendored
+17
-9
@@ -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.
|
||||
@@ -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.
|
||||
@@ -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.
|
||||
|
||||
@@ -936,6 +936,7 @@ namespace CypressSessionsTests {
|
||||
validate: { foo: true } // $ExpectError
|
||||
})
|
||||
}
|
||||
|
||||
namespace CypressCurrentTest {
|
||||
Cypress.currentTest.title // $ExpectType string
|
||||
Cypress.currentTest.titlePath // $ExpectType string[]
|
||||
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user