Files: d2f2697f296dd39aed6a8b63c6d04a736a7db5b3 / node_modules / stream-to-pull-stream / test / http.js
1048 bytesRaw
1 | var http = require('http') |
2 | var fs = require('fs') |
3 | var toPull = require('../') |
4 | var pull = require('pull-stream') |
5 | var port = ~~(Math.random()*40000) + 1024 |
6 | var test = require('tape') |
7 | |
8 | var thisFile = fs.readFileSync(__filename, 'utf-8') |
9 | |
10 | test('test http', function (t) { |
11 | |
12 | var server = http.createServer(function (req, res) { |
13 | pull( |
14 | toPull(req), |
15 | pull.reduce(function (b, s) { |
16 | return b + s |
17 | }, '', function (err, body) { |
18 | t.equal(body, thisFile) |
19 | t.notOk(err) |
20 | res.end('done') |
21 | }) |
22 | ) |
23 | }).listen(port, function () { |
24 | |
25 | fs.createReadStream(__filename) |
26 | .pipe(http.request({method: 'PUT', port: port}, function (res) { |
27 | console.log(res.statusCode) |
28 | var _res = toPull(res) |
29 | |
30 | setTimeout(function () { |
31 | |
32 | pull( |
33 | _res, |
34 | pull.collect(function (err, ary) { |
35 | t.equal(ary.map(String).join(''), 'done') |
36 | t.end() |
37 | }) |
38 | ) |
39 | |
40 | }, 200) |
41 | |
42 | server.close() |
43 | })) |
44 | }) |
45 | |
46 | }) |
47 |
Built with git-ssb-web