opts.js 868 B

1234567891011121314151617181920212223242526272829303132333435
  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. res.setHeader('content-type', 'text/robot-speak');
  7. res.end('beep boop');
  8. });
  9. test('1st-arg options', function (t) {
  10. t.plan(2);
  11. server.listen(0, function () {
  12. var port = server.address().port;
  13. check(t, port);
  14. });
  15. t.on('end', server.close.bind(server));
  16. });
  17. function check (t, port) {
  18. var r = hyperquest(
  19. { uri: 'http://localhost:' + port },
  20. function (err, res) {
  21. t.equal(res.headers['content-type'], 'text/robot-speak');
  22. }
  23. );
  24. r.pipe(through(write, end));
  25. var data = '';
  26. function write (buf, enc, cb) { data += buf; cb() }
  27. function end () {
  28. t.equal(data, 'beep boop');
  29. }
  30. }