You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

47 lines
918 B

4 years ago
  1. var Buffer = require('buffer').Buffer
  2. var fs = require('fs')
  3. var test = require('tape')
  4. var http = require('../..')
  5. var reference = fs.readFileSync(__dirname + '/../server/static/basic.txt')
  6. test('post text', function (t) {
  7. var req = http.request({
  8. path: '/echo',
  9. method: 'POST'
  10. }, function (res) {
  11. var buffers = []
  12. res.on('end', function () {
  13. t.ok(reference.equals(Buffer.concat(buffers)), 'echoed contents match')
  14. t.end()
  15. })
  16. res.on('data', function (data) {
  17. buffers.push(data)
  18. })
  19. })
  20. req.write(reference)
  21. req.end()
  22. })
  23. test('post text with data in end()', function (t) {
  24. var req = http.request({
  25. path: '/echo',
  26. method: 'POST'
  27. }, function (res) {
  28. var buffers = []
  29. res.on('end', function () {
  30. t.ok(reference.equals(Buffer.concat(buffers)), 'echoed contents match')
  31. t.end()
  32. })
  33. res.on('data', function (data) {
  34. buffers.push(data)
  35. })
  36. })
  37. req.end(reference)
  38. })