forked from request/request
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest-option-reuse.js
54 lines (43 loc) · 1.01 KB
/
test-option-reuse.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
'use strict'
var request = require('../index')
, http = require('http')
, tape = require('tape')
var methodsSeen = {
head: 0,
get: 0
}
var s = http.createServer(function(req, res) {
res.statusCode = 200
res.end('ok')
methodsSeen[req.method.toLowerCase()]++
})
tape('setup', function(t) {
s.listen(0, function() {
s.url = 'http://localhost:' + this.address().port
t.end()
})
})
tape('options object is not mutated', function(t) {
var url = s.url
var options = { url: url }
request.head(options, function(err, resp, body) {
t.equal(err, null)
t.equal(body, '')
t.equal(Object.keys(options).length, 1)
t.equal(options.url, url)
request.get(options, function(err, resp, body) {
t.equal(err, null)
t.equal(body, 'ok')
t.equal(Object.keys(options).length, 1)
t.equal(options.url, url)
t.equal(methodsSeen.head, 1)
t.equal(methodsSeen.get, 1)
t.end()
})
})
})
tape('cleanup', function(t) {
s.close(function() {
t.end()
})
})