Skip to content

Commit a99f32a

Browse files
Uzlopakflakey5
authored andcommitted
test: use globalThis.Headers and skip if is missing (nodejs#3684)
1 parent a658ab3 commit a99f32a

File tree

5 files changed

+36
-24
lines changed

5 files changed

+36
-24
lines changed

lib/web/cookies/index.js

+8-4
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ const { stringify } = require('./util')
55
const { webidl } = require('../fetch/webidl')
66
const { Headers } = require('../fetch/headers')
77

8+
const headersToBrandCheck = globalThis.Headers
9+
? [Headers, globalThis.Headers]
10+
: [Headers]
11+
812
/**
913
* @typedef {Object} Cookie
1014
* @property {string} name
@@ -26,7 +30,7 @@ const { Headers } = require('../fetch/headers')
2630
function getCookies (headers) {
2731
webidl.argumentLengthCheck(arguments, 1, 'getCookies')
2832

29-
webidl.brandCheckMultiple(headers, [Headers, globalThis.Headers])
33+
webidl.brandCheckMultiple(headers, headersToBrandCheck)
3034

3135
const cookie = headers.get('cookie')
3236

@@ -53,7 +57,7 @@ function getCookies (headers) {
5357
* @returns {void}
5458
*/
5559
function deleteCookie (headers, name, attributes) {
56-
webidl.brandCheckMultiple(headers, [Headers, globalThis.Headers])
60+
webidl.brandCheckMultiple(headers, headersToBrandCheck)
5761

5862
const prefix = 'deleteCookie'
5963
webidl.argumentLengthCheck(arguments, 2, prefix)
@@ -78,7 +82,7 @@ function deleteCookie (headers, name, attributes) {
7882
function getSetCookies (headers) {
7983
webidl.argumentLengthCheck(arguments, 1, 'getSetCookies')
8084

81-
webidl.brandCheckMultiple(headers, [Headers, globalThis.Headers])
85+
webidl.brandCheckMultiple(headers, headersToBrandCheck)
8286

8387
const cookies = headers.getSetCookie()
8488

@@ -97,7 +101,7 @@ function getSetCookies (headers) {
97101
function setCookie (headers, cookie) {
98102
webidl.argumentLengthCheck(arguments, 2, 'setCookie')
99103

100-
webidl.brandCheckMultiple(headers, [Headers, globalThis.Headers])
104+
webidl.brandCheckMultiple(headers, headersToBrandCheck)
101105

102106
cookie = webidl.converters.Cookie(cookie)
103107

test/cookie/cookies.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -630,7 +630,7 @@ test('Cookie setCookie does not throw if headers is an instance of undici owns H
630630
})
631631
})
632632

633-
test('Cookie setCookie does not throw if headers is an instance of the global Headers class', () => {
633+
test('Cookie setCookie does not throw if headers is an instance of the global Headers class', { skip: !globalThis.Headers }, () => {
634634
const headers = new globalThis.Headers()
635635
setCookie(headers, {
636636
name: 'key',
@@ -659,7 +659,7 @@ test('Cookie getCookies does not throw if headers is an instance of undici owns
659659
getCookies(headers)
660660
})
661661

662-
test('Cookie getCookie does not throw if headers is an instance of the global Headers class', () => {
662+
test('Cookie getCookie does not throw if headers is an instance of the global Headers class', { skip: !globalThis.Headers }, () => {
663663
const headers = new globalThis.Headers()
664664
getCookies(headers)
665665
})
@@ -682,7 +682,7 @@ test('Cookie getSetCookies does not throw if headers is an instance of undici ow
682682
getSetCookies(headers)
683683
})
684684

685-
test('Cookie setCookie does not throw if headers is an instance of the global Headers class', () => {
685+
test('Cookie setCookie does not throw if headers is an instance of the global Headers class', { skip: !globalThis.Headers }, () => {
686686
const headers = new globalThis.Headers({ 'set-cookie': 'Space=Cat' })
687687
getSetCookies(headers)
688688
})
@@ -705,7 +705,7 @@ test('Cookie deleteCookie does not throw if headers is an instance of undici own
705705
deleteCookie(headers, 'deno')
706706
})
707707

708-
test('Cookie getCookie does not throw if headers is an instance of the global Headers class', () => {
708+
test('Cookie getCookie does not throw if headers is an instance of the global Headers class', { skip: !globalThis.Headers }, () => {
709709
const headers = new globalThis.Headers()
710710
deleteCookie(headers, 'deno')
711711
})

test/cookie/global-headers.js

+11-11
Original file line numberDiff line numberDiff line change
@@ -10,24 +10,24 @@ const {
1010
} = require('../..')
1111

1212
describe('Using global Headers', async () => {
13-
test('deleteCookies', () => {
14-
const headers = new Headers()
13+
test('deleteCookies', { skip: !globalThis.Headers }, () => {
14+
const headers = new globalThis.Headers()
1515

1616
assert.equal(headers.get('set-cookie'), null)
1717
deleteCookie(headers, 'undici')
1818
assert.equal(headers.get('set-cookie'), 'undici=; Expires=Thu, 01 Jan 1970 00:00:00 GMT')
1919
})
2020

21-
test('getCookies', () => {
22-
const headers = new Headers({
21+
test('getCookies', { skip: !globalThis.Headers }, () => {
22+
const headers = new globalThis.Headers({
2323
cookie: 'get=cookies; and=attributes'
2424
})
2525

2626
assert.deepEqual(getCookies(headers), { get: 'cookies', and: 'attributes' })
2727
})
2828

29-
test('getSetCookies', () => {
30-
const headers = new Headers({
29+
test('getSetCookies', { skip: !globalThis.Headers }, () => {
30+
const headers = new globalThis.Headers({
3131
'set-cookie': 'undici=getSetCookies; Secure'
3232
})
3333

@@ -46,17 +46,17 @@ describe('Using global Headers', async () => {
4646
}
4747
})
4848

49-
test('setCookie', () => {
50-
const headers = new Headers()
49+
test('setCookie', { skip: !globalThis.Headers }, () => {
50+
const headers = new globalThis.Headers()
5151

5252
setCookie(headers, { name: 'undici', value: 'setCookie' })
5353
assert.equal(headers.get('Set-Cookie'), 'undici=setCookie')
5454
})
5555
})
5656

57-
describe('Headers check is not too lax', () => {
58-
class Headers {}
59-
Object.defineProperty(Headers.prototype, Symbol.toStringTag, {
57+
describe('Headers check is not too lax', { skip: !globalThis.Headers }, () => {
58+
class Headers { }
59+
Object.defineProperty(globalThis.Headers.prototype, Symbol.toStringTag, {
6060
value: 'Headers',
6161
configurable: true
6262
})

test/node-test/debug.js

+11-3
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@ test('debug#websocket', { skip: !process.versions.icu || isCITGM }, async t => {
1414
const assert = tspl(t, { plan: 6 })
1515
const child = spawn(
1616
process.execPath,
17-
[join(__dirname, '../fixtures/websocket.js')],
17+
[
18+
'--no-experimental-fetch',
19+
join(__dirname, '../fixtures/websocket.js')],
1820
{
1921
env: {
2022
NODE_DEBUG: 'websocket'
@@ -50,7 +52,10 @@ test('debug#fetch', { skip: isCITGM }, async t => {
5052
const assert = tspl(t, { plan: 7 })
5153
const child = spawn(
5254
process.execPath,
53-
[join(__dirname, '../fixtures/fetch.js')],
55+
[
56+
'--no-experimental-fetch',
57+
join(__dirname, '../fixtures/fetch.js')
58+
],
5459
{
5560
env: Object.assign({}, process.env, { NODE_DEBUG: 'fetch' })
5661
}
@@ -85,7 +90,10 @@ test('debug#undici', { skip: isCITGM }, async t => {
8590
const assert = tspl(t, { plan: 7 })
8691
const child = spawn(
8792
process.execPath,
88-
[join(__dirname, '../fixtures/undici.js')],
93+
[
94+
'--no-experimental-fetch',
95+
join(__dirname, '../fixtures/undici.js')
96+
],
8997
{
9098
env: {
9199
NODE_DEBUG: 'undici'

test/request.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@ describe('DispatchOptions#reset', () => {
275275
})
276276

277277
describe('Should include headers from iterable objects', scope => {
278-
test('Should include headers built with Headers global object', async t => {
278+
test('Should include headers built with Headers global object', { skip: !globalThis.Headers }, async t => {
279279
t = tspl(t, { plan: 3 })
280280

281281
const server = createServer((req, res) => {
@@ -286,7 +286,7 @@ describe('Should include headers from iterable objects', scope => {
286286
res.end('hello')
287287
})
288288

289-
const headers = new Headers()
289+
const headers = new globalThis.Headers()
290290
headers.set('hello', 'world')
291291

292292
after(() => server.close())

0 commit comments

Comments
 (0)