chore: update session api types & exposed global helpers (#24980)

Co-authored-by: Matt Schile <mschile@cypress.io>
Co-authored-by: Chris Breiding <chrisbreiding@users.noreply.github.com>
This commit is contained in:
Emily Rohrbough
2022-12-06 08:19:39 -06:00
committed by GitHub
parent 166bf8ebd2
commit 797c8f8d77
13 changed files with 156 additions and 179 deletions
+52 -20
View File
@@ -794,25 +794,6 @@ declare namespace Cypress {
onSpecWindow: (window: Window, specList: string[] | Array<() => Promise<void>>) => void
}
interface SessionOptions {
/**
* Whether or not to persist the session across all specs in the run.
* @default {false}
*/
cacheAcrossSpecs?: boolean
/**
* Function to run immediately after the session is created and `setup` function runs or
* after a session is restored and the page is cleared. If this returns `false`, throws an
* exception, returns a Promise which resolves to `false` or rejects or contains any failing
* Cypress command, the session is considered invalid.
*
* If validation fails immediately after `setup`, the test will fail.
* If validation fails after restoring a session, `setup` will re-run.
* @default {false}
*/
validate?: () => Promise<false | void> | void
}
type CanReturnChainable = void | Chainable | Promise<unknown>
type ThenReturn<S, R> =
R extends void ? Chainable<S> :
@@ -3423,8 +3404,59 @@ declare namespace Cypress {
}
interface Session {
// Clear all saved sessions and re-run the current spec file.
/**
* Clear all sessions saved on the backend, including cached global sessions.
*/
clearAllSavedSessions: () => Promise<void>
/**
* Clear all storage and cookie data across all origins associated with the current session.
*/
clearCurrentSessionData: () => Promise<void>
/**
* Get all storage and cookie data across all origins associated with the current session.
*/
getCurrentSessionData: () => Promise<SessionData>
/**
* Get all storage and cookie data saved on the backend associated with the provided session id.
*/
getSession: (id: string) => Promise<ServerSessionData>
}
type ActiveSessions = Record<string, SessionData>
interface SessionData {
id: string
hydrated: boolean
cacheAcrossSpecs: SessionOptions['cacheAcrossSpecs']
cookies?: Cookie[] | null
localStorage?: OriginStorage[] | null
sessionStorage?: OriginStorage[] | null
setup: () => void
validate?: SessionOptions['validate']
}
interface ServerSessionData extends Omit<SessionData, 'setup' |'validate'> {
setup: string
validate?: string
}
interface SessionOptions {
/**
* Whether or not to persist the session across all specs in the run.
* @default {false}
*/
cacheAcrossSpecs?: boolean
/**
* Function to run immediately after the session is created and `setup` function runs or
* after a session is restored and the page is cleared. If this returns `false`, throws an
* exception, returns a Promise which resolves to `false` or rejects or contains any failing
* Cypress command, the session is considered invalid.
*
* If validation fails immediately after `setup`, the test will fail.
* If validation fails after restoring a session, `setup` will re-run.
* @default {false}
*/
validate?: () => Promise<false | void> | void
}
type SameSiteStatus = 'no_restriction' | 'strict' | 'lax'