Files
cypress/packages/server/lib/session.ts
Lachlan Miller ab401ecd35 chore: use import type syntax (#17864)
* chore: use import type across repo

* chore: use import type across repo

* chore: use import type across repo

* chore: use import type across repo

* update exports

* update test

* update import type

* update types

* use import type in driver

* correctly export function

* revert test

* remove unrelated code

* revert code

* improve type imports

* override for reporter
2021-08-25 09:11:56 +10:00

34 lines
638 B
TypeScript

import type { CyCookie } from './browsers/cdp_automation'
interface SessionData {
cookies: CyCookie[]
id: string
localStorage: object
sessionStorage: object
}
const state = {
sessions: {},
}
export function saveSession (data: SessionData) {
if (!data.id) throw new Error('session data had no id')
state.sessions[data.id] = data
}
export function getSession (id: string): SessionData {
const session = state.sessions[id]
if (!session) throw new Error(`session with id "${id}" not found`)
return session
}
export function getState () {
return state
}
export function clearSessions () {
state.sessions = {}
}