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.

36 lines
963 B

7 years ago
  1. var assert = require('assert'),
  2. vows = require('vows'),
  3. request = require('request'),
  4. union = require('../');
  5. function stream_callback(cb) {
  6. return function () {
  7. var stream = new union.ResponseStream();
  8. stream.once("pipe", function (req) {
  9. return cb ? cb(null,req) : undefined;
  10. });
  11. return stream;
  12. };
  13. }
  14. vows.describe('union/after').addBatch({
  15. 'When using `union`': {
  16. 'a union server with after middleware': {
  17. topic: function () {
  18. var self = this;
  19. union.createServer({
  20. after: [ stream_callback(), stream_callback(self.callback) ]
  21. }).listen(9000, function () {
  22. request.get('http://localhost:9000');
  23. });
  24. },
  25. 'should preserve the request until the last call': function (req) {
  26. assert.equal(req.req.httpVersion, '1.1');
  27. assert.equal(req.req.url, '/');
  28. assert.equal(req.req.method, 'GET');
  29. }
  30. }
  31. }
  32. }).export(module);