Archived
1
0
This repository has been archived on 2024-09-09. You can view files and clone it, but cannot push or open issues or pull requests.
code-server/test/helpers.ts
Asher 47a05c998a
Gate wtfnode behind WTF_NODE env var
After thinking about it some more it's probably mostly only useful to
see the output when the tests are hanging. Otherwise there's a lot of
noise about Jest child processes and pipes.
2021-02-22 13:41:12 -07:00

36 lines
912 B
TypeScript

// Borrowed from playwright
export interface Cookie {
name: string
value: string
domain: string
path: string
/**
* Unix time in seconds.
*/
expires: number
httpOnly: boolean
secure: boolean
sameSite: "Strict" | "Lax" | "None"
}
/**
* Checks if a cookie exists in array of cookies
*/
export function checkForCookie(cookies: Array<Cookie>, key: string): boolean {
// Check for a cookie where the name is equal to key
return Boolean(cookies.find((cookie) => cookie.name === key))
}
/**
* Creates a login cookie if one doesn't already exist
*/
export function createCookieIfDoesntExist(cookies: Array<Cookie>, cookieToStore: Cookie): Array<Cookie> {
const cookieName = cookieToStore.name
const doesCookieExist = checkForCookie(cookies, cookieName)
if (!doesCookieExist) {
const updatedCookies = [...cookies, cookieToStore]
return updatedCookies
}
return cookies
}