/
test-promise.js
52 lines (45 loc) 路 1.09 KB
/
test-promise.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
'use strict'
var http = require('http')
, request = require('../index')
, tape = require('tape')
, Promise = require('bluebird')
var s = http.createServer(function(req, res) {
res.writeHead(200, {})
res.end('ok')
})
tape('setup', function(t) {
s.listen(6767, function() {
t.end()
})
})
tape('promisify convenience method', function(t) {
var get = request.get
var p = Promise.promisify(get, {multiArgs: true})
p('http://localhost:6767')
.then(function (results) {
var res = results[0]
t.equal(res.statusCode, 200)
t.end()
})
})
tape('promisify request function', function(t) {
var p = Promise.promisify(request, {multiArgs: true})
p('http://localhost:6767')
.spread(function (res, body) {
t.equal(res.statusCode, 200)
t.end()
})
})
tape('promisify all methods', function(t) {
Promise.promisifyAll(request, {multiArgs: true})
request.getAsync('http://localhost:6767')
.spread(function (res, body) {
t.equal(res.statusCode, 200)
t.end()
})
})
tape('cleanup', function(t) {
s.close(function() {
t.end()
})
})