mirror of
https://github.com/cypress-io/cypress.git
synced 2026-01-25 16:39:04 -06:00
Co-authored-by: Matt Schile <mschile@cypress.io> Co-authored-by: Chris Breiding <chrisbreiding@users.noreply.github.com>
48 lines
998 B
TypeScript
48 lines
998 B
TypeScript
import type { StoredSessions } from '@packages/types'
|
|
|
|
type State = {
|
|
globalSessions: StoredSessions
|
|
specSessions: StoredSessions
|
|
}
|
|
|
|
const state: State = {
|
|
globalSessions: {},
|
|
specSessions: {},
|
|
}
|
|
|
|
export function saveSession (data: Cypress.ServerSessionData): void {
|
|
if (!data.id) throw new Error('session data had no id')
|
|
|
|
if (data.cacheAcrossSpecs) {
|
|
state.globalSessions[data.id] = data
|
|
|
|
return
|
|
}
|
|
|
|
state.specSessions[data.id] = data
|
|
}
|
|
|
|
export function getActiveSessions (): StoredSessions {
|
|
return state.globalSessions
|
|
}
|
|
|
|
export function getSession (id: string): Cypress.ServerSessionData {
|
|
const session = state.globalSessions[id] || state.specSessions[id]
|
|
|
|
if (!session) throw new Error(`session with id "${id}" not found`)
|
|
|
|
return session
|
|
}
|
|
|
|
export function getState (): State {
|
|
return state
|
|
}
|
|
|
|
export function clearSessions (clearAllSessions: boolean = false): void {
|
|
state.specSessions = {}
|
|
|
|
if (clearAllSessions) {
|
|
state.globalSessions = {}
|
|
}
|
|
}
|