@@ -22,18 +22,16 @@ import * as sinon from 'sinon';
22
22
import { teenyRequest } from '../src' ;
23
23
import { pool } from '../src/agents' ;
24
24
25
- // tslint: disable-next-line variable-name
25
+ // eslint- disable-next-line @typescript-eslint/no-var-requires
26
26
const HttpProxyAgent = require ( 'http-proxy-agent' ) ;
27
- // tslint: disable-next-line variable-name
27
+ // eslint- disable-next-line @typescript-eslint/no-var-requires
28
28
const HttpsProxyAgent = require ( 'https-proxy-agent' ) ;
29
29
30
30
nock . disableNetConnect ( ) ;
31
31
const uri = 'https://example.com' ;
32
32
33
33
function mockJson ( ) {
34
- return nock ( uri )
35
- . get ( '/' )
36
- . reply ( 200 , { hello : '🌍' } ) ;
34
+ return nock ( uri ) . get ( '/' ) . reply ( 200 , { hello : '🌍' } ) ;
37
35
}
38
36
39
37
describe ( 'teeny' , ( ) => {
@@ -70,9 +68,7 @@ describe('teeny', () => {
70
68
it ( 'response event emits object compatible with request module' , done => {
71
69
const reqHeaders = { fruit : 'banana' } ;
72
70
const resHeaders = { veggies : 'carrots' } ;
73
- const scope = nock ( uri )
74
- . get ( '/' )
75
- . reply ( 202 , 'ok' , resHeaders ) ;
71
+ const scope = nock ( uri ) . get ( '/' ) . reply ( 202 , 'ok' , resHeaders ) ;
76
72
const reqStream = teenyRequest ( { uri, headers : reqHeaders } ) ;
77
73
reqStream
78
74
. on ( 'response' , res => {
@@ -91,9 +87,7 @@ describe('teeny', () => {
91
87
92
88
it ( 'should include the request in the response' , done => {
93
89
const path = '/?dessert=pie' ;
94
- const scope = nock ( uri )
95
- . get ( path )
96
- . reply ( 202 ) ;
90
+ const scope = nock ( uri ) . get ( path ) . reply ( 202 ) ;
97
91
const headers = { dinner : 'tacos' } ;
98
92
const url = `${ uri } ${ path } ` ;
99
93
teenyRequest ( { url, headers} , ( error , response ) => {
@@ -121,9 +115,7 @@ describe('teeny', () => {
121
115
it ( 'should include headers in the response' , done => {
122
116
const headers = { dinner : 'tacos' } ;
123
117
const body = { hello : '🌍' } ;
124
- const scope = nock ( uri )
125
- . get ( '/' )
126
- . reply ( 200 , body , headers ) ;
118
+ const scope = nock ( uri ) . get ( '/' ) . reply ( 200 , body , headers ) ;
127
119
teenyRequest ( { uri} , ( err , res ) => {
128
120
assert . ifError ( err ) ;
129
121
assert . strictEqual ( headers [ 'dinner' ] , res . headers [ 'dinner' ] ) ;
@@ -133,12 +125,10 @@ describe('teeny', () => {
133
125
} ) ;
134
126
135
127
it ( 'should accept the forever option' , done => {
136
- const scope = nock ( uri )
137
- . get ( '/' )
138
- . reply ( 200 ) ;
128
+ const scope = nock ( uri ) . get ( '/' ) . reply ( 200 ) ;
139
129
teenyRequest ( { uri, forever : true } , ( err , res ) => {
140
130
assert . ifError ( err ) ;
141
- // tslint: disable-next-line no -any
131
+ // eslint- disable-next-line @typescript-eslint/no-explicit -any
142
132
assert . strictEqual ( ( res . request . agent as any ) . keepAlive , true ) ;
143
133
scope . done ( ) ;
144
134
done ( ) ;
@@ -150,11 +140,9 @@ describe('teeny', () => {
150
140
'Accept-Encoding' : 'gzip,deflate' ,
151
141
} ;
152
142
153
- const scope = nock ( uri , { reqheaders} )
154
- . get ( '/' )
155
- . reply ( 200 ) ;
143
+ const scope = nock ( uri , { reqheaders} ) . get ( '/' ) . reply ( 200 ) ;
156
144
157
- teenyRequest ( { uri, gzip : true } , ( err , res ) => {
145
+ teenyRequest ( { uri, gzip : true } , err => {
158
146
assert . ifError ( err ) ;
159
147
scope . done ( ) ;
160
148
done ( ) ;
@@ -164,11 +152,9 @@ describe('teeny', () => {
164
152
it ( 'should allow setting compress/gzip to false' , done => {
165
153
const badheaders = [ 'Accept-Encoding' ] ;
166
154
167
- const scope = nock ( uri , { badheaders} )
168
- . get ( '/' )
169
- . reply ( 200 ) ;
155
+ const scope = nock ( uri , { badheaders} ) . get ( '/' ) . reply ( 200 ) ;
170
156
171
- teenyRequest ( { uri, gzip : false } , ( err , res ) => {
157
+ teenyRequest ( { uri, gzip : false } , err => {
172
158
assert . ifError ( err ) ;
173
159
scope . done ( ) ;
174
160
done ( ) ;
@@ -180,9 +166,7 @@ describe('teeny', () => {
180
166
it ( `should respect ${ v } environment variable for proxy config` , done => {
181
167
sandbox . stub ( process , 'env' ) . value ( { [ v ] : 'https://fake.proxy' } ) ;
182
168
const expectedBody = { hello : '🌎' } ;
183
- const scope = nock ( uri )
184
- . get ( '/' )
185
- . reply ( 200 , expectedBody ) ;
169
+ const scope = nock ( uri ) . get ( '/' ) . reply ( 200 , expectedBody ) ;
186
170
teenyRequest ( { uri} , ( err , res , body ) => {
187
171
scope . done ( ) ;
188
172
assert . ifError ( err ) ;
@@ -196,9 +180,7 @@ describe('teeny', () => {
196
180
it ( 'should create http proxy if upstream scheme is http' , done => {
197
181
sandbox . stub ( process , 'env' ) . value ( { http_proxy : 'https://fake.proxy' } ) ;
198
182
const expectedBody = { hello : '🌎' } ;
199
- const scope = nock ( 'http://example.com' )
200
- . get ( '/' )
201
- . reply ( 200 , expectedBody ) ;
183
+ const scope = nock ( 'http://example.com' ) . get ( '/' ) . reply ( 200 , expectedBody ) ;
202
184
teenyRequest ( { uri : 'http://example.com' } , ( err , res , body ) => {
203
185
scope . done ( ) ;
204
186
assert . ifError ( err ) ;
@@ -210,9 +192,7 @@ describe('teeny', () => {
210
192
211
193
it ( 'should use proxy if set in request options' , done => {
212
194
const expectedBody = { hello : '🌎' } ;
213
- const scope = nock ( uri )
214
- . get ( '/' )
215
- . reply ( 200 , expectedBody ) ;
195
+ const scope = nock ( uri ) . get ( '/' ) . reply ( 200 , expectedBody ) ;
216
196
teenyRequest ( { uri, proxy : 'https://fake.proxy' } , ( err , res , body ) => {
217
197
scope . done ( ) ;
218
198
assert . ifError ( err ) ;
@@ -226,12 +206,14 @@ describe('teeny', () => {
226
206
it ( 'should not throw exception when piped through pumpify' , ( ) => {
227
207
const scope = mockJson ( ) ;
228
208
teenyRequest ( { uri} ) . pipe ( new PassThrough ( ) ) ;
209
+ scope . done ( ) ;
229
210
} ) ;
230
211
231
212
it ( 'should emit response event when called without callback' , done => {
232
213
const scope = mockJson ( ) ;
233
214
teenyRequest ( { uri} ) . on ( 'response' , res => {
234
215
assert . ok ( res ) ;
216
+ scope . done ( ) ;
235
217
return done ( ) ;
236
218
} ) ;
237
219
} ) ;
@@ -241,6 +223,7 @@ describe('teeny', () => {
241
223
teenyRequest ( { uri} )
242
224
. on ( 'error' , done )
243
225
. on ( 'data' , ( ) => {
226
+ scope . done ( ) ;
244
227
done ( ) ;
245
228
} ) ;
246
229
} ) ;
@@ -261,6 +244,7 @@ describe('teeny', () => {
261
244
responseStream . body . _readableState . pipesCount ??
262
245
responseStream . body . _readableState . pipes ?. length ;
263
246
assert . strictEqual ( numPipes , 1 ) ;
247
+ scope . done ( ) ;
264
248
done ( ) ;
265
249
} ) ;
266
250
} ) ;
0 commit comments