-
Notifications
You must be signed in to change notification settings - Fork 33
/
warning.js
60 lines (42 loc) · 1.46 KB
/
warning.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
57
58
59
60
'use strict'
const Fetch = require('minipass-fetch')
const { test } = require('tap')
const setWarning = require('../warning')
test('setWarning', (t) => {
const code = 999
const message = { hello: 'world' }
const url = 'https://google.com'
t.test('validate append headers', (t) => {
const date = JSON.stringify(new Date().toUTCString())
const replace = false
const headers = new Fetch.Headers()
const req = new Fetch.Request(url, { headers })
const origHeaderAppend = req.headers.append
req.headers.append = (...args) => {
const expectedValue = `999 google.com {"hello":"world"} ${date}`
t.equal('Warning', args[0])
t.same(expectedValue, args[1])
return origHeaderAppend.call(headers, ...args)
}
setWarning(req, code, message, replace)
req.headers.append = origHeaderAppend
t.end()
})
t.test('validate set headers', (t) => {
const date = JSON.stringify(new Date().toUTCString())
const replace = true
const headers = new Fetch.Headers({ Warning: 'world' })
const req = new Fetch.Request(url, { headers })
const origHeaderSet = req.headers.set
req.headers.set = (...args) => {
const expectedValue = `999 google.com {"hello":"world"} ${date}`
t.equal('Warning', args[0])
t.same(expectedValue, args[1])
return origHeaderSet.call(headers, ...args)
}
setWarning(req, code, message, replace)
req.headers.set = origHeaderSet
t.end()
})
t.end()
})