mirror of
https://github.com/cypress-io/cypress.git
synced 2026-01-06 06:29:45 -06:00
* chore: update playwright-webkit from 1.24.2 to 1.56.1 * chore: fix cookies.cy.js tests in webkit by checking for strict domain match first when calling getCookie and falling back to apex domain * misc: add changelog item
31 lines
1020 B
TypeScript
31 lines
1020 B
TypeScript
import type playwright from 'playwright-webkit'
|
|
import { domainMatch, pathMatch } from 'tough-cookie'
|
|
|
|
// @ts-ignore
|
|
export type CyCookie = Pick<chrome.cookies.Cookie, 'name' | 'value' | 'expirationDate' | 'hostOnly' | 'domain' | 'path' | 'secure' | 'httpOnly'> & {
|
|
// use `undefined` instead of `unspecified`
|
|
sameSite?: 'no_restriction' | 'lax' | 'strict'
|
|
}
|
|
|
|
// Cypress uses the webextension-style filtering
|
|
// https://developer.chrome.com/extensions/cookies#method-getAll
|
|
// @ts-ignore
|
|
export type CyCookieFilter = chrome.cookies.GetAllDetails
|
|
|
|
export const cookieMatches = (cookie: CyCookie | playwright.Cookie, filter?: CyCookieFilter, options?: { strictDomain: boolean }) => {
|
|
if (filter?.domain) {
|
|
if (options?.strictDomain ? filter?.domain !== cookie.domain : !domainMatch(filter?.domain, cookie.domain))
|
|
return false
|
|
}
|
|
|
|
if (filter?.path && !pathMatch(filter.path, cookie.path)) {
|
|
return false
|
|
}
|
|
|
|
if (filter?.name && filter?.name !== cookie.name) {
|
|
return false
|
|
}
|
|
|
|
return true
|
|
}
|