hijackresponse
Advanced tools
Comparing version 2.0.0 to 2.0.1
@@ -54,5 +54,5 @@ var Readable = require('stream').Readable | ||
hijackedResponse.emit('close') | ||
} else { | ||
return resEmit.apply(this, arguments) | ||
} | ||
return resEmit.apply(this, arguments) | ||
} | ||
@@ -59,0 +59,0 @@ |
{ | ||
"name": "hijackresponse", | ||
"version": "2.0.0", | ||
"version": "2.0.1", | ||
"description": "Hijack HttpResponses", | ||
@@ -5,0 +5,0 @@ "main": "lib/hijackResponse.js", |
@@ -1,5 +0,7 @@ | ||
/* global describe, it */ | ||
/* global describe, it, before, after */ | ||
var http = require('http') | ||
var expect = require('unexpected') | ||
.clone() | ||
.use(require('unexpected-express')) | ||
.use(require('unexpected-sinon')) | ||
.addAssertion('to yield response', function (expect, subject, value) { | ||
@@ -11,2 +13,3 @@ return expect(subject, 'to yield exchange', { | ||
}) | ||
var sinon = require('sinon') | ||
var express = require('express') | ||
@@ -167,2 +170,63 @@ var passError = require('passerror') | ||
}) | ||
describe('against a real server', function () { | ||
before(function () { | ||
var self = this | ||
var spy = sinon.spy() | ||
this.spy = spy | ||
return new Promise(function (resolve) { | ||
var app = express() | ||
.use(function (req, res, next) { | ||
res.on('close', function () { | ||
spy() | ||
self.resolve() | ||
}) | ||
next() | ||
}) | ||
.use(function (req, res, next) { | ||
hijackResponse(res, passError(next, function (res) { | ||
res.pipe(res) | ||
})) | ||
next() | ||
}) | ||
.use(function (req, res) { | ||
res.write('foo') | ||
}) | ||
var server = http.Server(app) | ||
server.listen(0, function () { | ||
resolve(server) | ||
}) | ||
}).then(function (server) { | ||
self.server = server | ||
}) | ||
}) | ||
it('should not prevent "close" events registered on res from firing when hijacking', function () { | ||
var self = this | ||
var port = this.server.address().port | ||
var spy = this.spy | ||
return new Promise(function (resolve) { | ||
self.resolve = resolve | ||
var options = { | ||
port: port | ||
} | ||
var request = http.request(options, function (res) { | ||
request.abort() | ||
}) | ||
request.end() | ||
}).then(function () { | ||
expect(spy, 'was called') | ||
}) | ||
}) | ||
after(function () { | ||
this.server.close() | ||
}) | ||
}) | ||
}) |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
2026512
643
3