-
Notifications
You must be signed in to change notification settings - Fork 523
/
global-headers.js
56 lines (46 loc) · 1.37 KB
/
global-headers.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
'use strict'
const { describe, test } = require('node:test')
const assert = require('node:assert')
const {
deleteCookie,
getCookies,
getSetCookies,
setCookie
} = require('../..')
const { getHeadersList } = require('../../lib/web/cookies/util')
describe('Using global Headers', async () => {
test('deleteCookies', () => {
const headers = new Headers()
assert.equal(headers.get('set-cookie'), null)
deleteCookie(headers, 'undici')
assert.equal(headers.get('set-cookie'), 'undici=; Expires=Thu, 01 Jan 1970 00:00:00 GMT')
})
test('getCookies', () => {
const headers = new Headers({
cookie: 'get=cookies; and=attributes'
})
assert.deepEqual(getCookies(headers), { get: 'cookies', and: 'attributes' })
})
test('getSetCookies', () => {
const headers = new Headers({
'set-cookie': 'undici=getSetCookies; Secure'
})
const supportsCookies = getHeadersList(headers).cookies
if (!supportsCookies) {
assert.deepEqual(getSetCookies(headers), [])
} else {
assert.deepEqual(getSetCookies(headers), [
{
name: 'undici',
value: 'getSetCookies',
secure: true
}
])
}
})
test('setCookie', () => {
const headers = new Headers()
setCookie(headers, { name: 'undici', value: 'setCookie' })
assert.equal(headers.get('Set-Cookie'), 'undici=setCookie')
})
})