-
Notifications
You must be signed in to change notification settings - Fork 525
/
agent.test-d.ts
115 lines (104 loc) · 4.68 KB
/
agent.test-d.ts
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
import { Duplex, Readable, Writable } from 'stream'
import { expectAssignable } from 'tsd'
import { Agent, Dispatcher } from '../..'
import { URL } from 'url'
expectAssignable<Agent>(new Agent())
expectAssignable<Agent>(new Agent({}))
expectAssignable<Agent>(new Agent({ maxRedirections: 1 }))
expectAssignable<Agent>(new Agent({ factory: () => new Dispatcher() }))
{
const agent = new Agent()
// properties
expectAssignable<boolean>(agent.closed)
expectAssignable<boolean>(agent.destroyed)
// request
expectAssignable<Promise<Dispatcher.ResponseData>>(agent.request({ origin: '', path: '', method: 'GET' }))
expectAssignable<Promise<Dispatcher.ResponseData>>(agent.request({ origin: '', path: '', method: 'GET', onInfo: (info) => {} }))
expectAssignable<Promise<Dispatcher.ResponseData>>(agent.request({ origin: new URL('http://localhost'), path: '', method: 'GET' }))
expectAssignable<void>(agent.request({ origin: '', path: '', method: 'GET' }, (err, data) => {
expectAssignable<Error | null>(err)
expectAssignable<Dispatcher.ResponseData>(data)
}))
expectAssignable<void>(agent.request({ origin: new URL('http://localhost'), path: '', method: 'GET' }, (err, data) => {
expectAssignable<Error | null>(err)
expectAssignable<Dispatcher.ResponseData>(data)
}))
// stream
expectAssignable<Promise<Dispatcher.StreamData>>(agent.stream({ origin: '', path: '', method: 'GET' }, data => {
expectAssignable<Dispatcher.StreamFactoryData>(data)
return new Writable()
}))
expectAssignable<Promise<Dispatcher.StreamData>>(agent.stream({ origin: '', path: '', method: 'GET', onInfo: (info) => {} }, data => {
expectAssignable<Dispatcher.StreamFactoryData>(data)
return new Writable()
}))
expectAssignable<Promise<Dispatcher.StreamData>>(agent.stream({ origin: new URL('http://localhost'), path: '', method: 'GET' }, data => {
expectAssignable<Dispatcher.StreamFactoryData>(data)
return new Writable()
}))
expectAssignable<void>(agent.stream(
{ origin: '', path: '', method: 'GET' },
data => {
expectAssignable<Dispatcher.StreamFactoryData>(data)
return new Writable()
},
(err, data) => {
expectAssignable<Error | null>(err)
expectAssignable<Dispatcher.StreamData>(data)
}
))
expectAssignable<void>(agent.stream(
{ origin: new URL('http://localhost'), path: '', method: 'GET' },
data => {
expectAssignable<Dispatcher.StreamFactoryData>(data)
return new Writable()
},
(err, data) => {
expectAssignable<Error | null>(err)
expectAssignable<Dispatcher.StreamData>(data)
}
))
// pipeline
expectAssignable<Duplex>(agent.pipeline({ origin: '', path: '', method: 'GET' }, data => {
expectAssignable<Dispatcher.PipelineHandlerData>(data)
return new Readable()
}))
expectAssignable<Duplex>(agent.pipeline({ origin: '', path: '', method: 'GET', onInfo: (info) => {} }, data => {
expectAssignable<Dispatcher.PipelineHandlerData>(data)
return new Readable()
}))
expectAssignable<Duplex>(agent.pipeline({ origin: new URL('http://localhost'), path: '', method: 'GET' }, data => {
expectAssignable<Dispatcher.PipelineHandlerData>(data)
return new Readable()
}))
// upgrade
expectAssignable<Promise<Dispatcher.UpgradeData>>(agent.upgrade({ path: '' }))
expectAssignable<void>(agent.upgrade({ path: '' }, (err, data) => {
expectAssignable<Error | null>(err)
expectAssignable<Dispatcher.UpgradeData>(data)
}))
// connect
expectAssignable<Promise<Dispatcher.ConnectData>>(agent.connect({ origin: '', path: '' }))
expectAssignable<Promise<Dispatcher.ConnectData>>(agent.connect({ origin: new URL('http://localhost'), path: '' }))
expectAssignable<void>(agent.connect({ origin: '', path: '' }, (err, data) => {
expectAssignable<Error | null>(err)
expectAssignable<Dispatcher.ConnectData>(data)
}))
expectAssignable<void>(agent.connect({ origin: new URL('http://localhost'), path: '' }, (err, data) => {
expectAssignable<Error | null>(err)
expectAssignable<Dispatcher.ConnectData>(data)
}))
// dispatch
expectAssignable<boolean>(agent.dispatch({ origin: '', path: '', method: 'GET' }, {}))
expectAssignable<boolean>(agent.dispatch({ origin: '', path: '', method: 'GET', maxRedirections: 1 }, {}))
// close
expectAssignable<Promise<void>>(agent.close())
expectAssignable<void>(agent.close(() => {}))
// destroy
expectAssignable<Promise<void>>(agent.destroy())
expectAssignable<Promise<void>>(agent.destroy(new Error()))
expectAssignable<Promise<void>>(agent.destroy(null))
expectAssignable<void>(agent.destroy(() => {}))
expectAssignable<void>(agent.destroy(new Error(), () => {}))
expectAssignable<void>(agent.destroy(null, () => {}))
}