post_immediate.js 770 B

1234567891011121314151617181920212223242526272829303132
  1. var test = require('tape');
  2. var http = require('http');
  3. var hyperquest = require('../');
  4. var through = require('through2');
  5. var server = http.createServer(function (req, res) {
  6. req.pipe(through(function (buf, enc, cb) {
  7. this.push(String(buf).toUpperCase());
  8. cb();
  9. })).pipe(res);
  10. });
  11. test('post', function (t) {
  12. t.plan(1);
  13. server.listen(0, function () {
  14. var port = server.address().port;
  15. check(t, port);
  16. });
  17. t.on('end', server.close.bind(server));
  18. });
  19. function check (t, port) {
  20. var r = hyperquest.post('http://localhost:' + port);
  21. r.end('beep boop.');
  22. var data = '';
  23. r.on('data', function (buf) { data += buf });
  24. r.on('end', function () {
  25. t.equal(data, 'BEEP BOOP.');
  26. });
  27. }