diff --git a/Makefile b/Makefile index cebf867d1..c638e20a5 100644 --- a/Makefile +++ b/Makefile @@ -14,6 +14,12 @@ test: docs: $(HTML) @mv $(HTML) docs +test-cov: lib-cov + @CONNECT_COV=1 $(MAKE) test REPORTER=html-cov > coverage.html + +lib-cov: + @jscoverage lib $@ + %.html: %.js $(DOX) < $< | node support/docs > $@ @@ -27,4 +33,4 @@ site: docclean docs && cp -fr /tmp/docs/* . \ && echo "done" -.PHONY: site docs test docclean \ No newline at end of file +.PHONY: test-cov site docs test docclean \ No newline at end of file diff --git a/index.js b/index.js index 747704821..23240eeda 100644 --- a/index.js +++ b/index.js @@ -1,2 +1,4 @@ -module.exports = require('./lib/connect'); \ No newline at end of file +module.exports = process.env.CONNECT_COV + ? require('./lib-cov/connect') + : require('./lib/connect'); \ No newline at end of file diff --git a/lib/patch.js b/lib/patch.js index b01e6eb39..7cf001255 100644 --- a/lib/patch.js +++ b/lib/patch.js @@ -17,62 +17,63 @@ var http = require('http') // apply only once -if (res._hasConnectPatch) return; +if (!res._hasConnectPatch) { -/** - * Provide a public "header sent" flag - * until node does. - * - * @return {Boolean} - * @api public - */ + /** + * Provide a public "header sent" flag + * until node does. + * + * @return {Boolean} + * @api public + */ -res.__defineGetter__('headerSent', function(){ - return this._header; -}); + res.__defineGetter__('headerSent', function(){ + return this._header; + }); -/** - * Set header `field` to `val`, special-casing - * the `Set-Cookie` field for multiple support. - * - * @param {String} field - * @param {String} val - * @api public - */ + /** + * Set header `field` to `val`, special-casing + * the `Set-Cookie` field for multiple support. + * + * @param {String} field + * @param {String} val + * @api public + */ -res.setHeader = function(field, val){ - var key = field.toLowerCase() - , prev; + res.setHeader = function(field, val){ + var key = field.toLowerCase() + , prev; - // special-case Set-Cookie - if (this._headers && 'set-cookie' == key) { - if (prev = this.getHeader(field)) { - val = Array.isArray(prev) - ? prev.concat(val) - : [prev, val]; + // special-case Set-Cookie + if (this._headers && 'set-cookie' == key) { + if (prev = this.getHeader(field)) { + val = Array.isArray(prev) + ? prev.concat(val) + : [prev, val]; + } + // charset + } else if ('content-type' == key && this.charset) { + val += '; charset=' + this.charset; } - // charset - } else if ('content-type' == key && this.charset) { - val += '; charset=' + this.charset; - } - return setHeader.call(this, field, val); -}; + return setHeader.call(this, field, val); + }; -/** - * Proxy to emit "header" event. - */ + /** + * Proxy to emit "header" event. + */ -res._renderHeaders = function(){ - if (!this._emittedHeader) this.emit('header'); - this._emittedHeader = true; - return _renderHeaders.call(this); -}; + res._renderHeaders = function(){ + if (!this._emittedHeader) this.emit('header'); + this._emittedHeader = true; + return _renderHeaders.call(this); + }; -res.writeHead = function(){ - if (!this._emittedHeader) this.emit('header'); - this._emittedHeader = true; - return writeHead.apply(this, arguments); -}; + res.writeHead = function(){ + if (!this._emittedHeader) this.emit('header'); + this._emittedHeader = true; + return writeHead.apply(this, arguments); + }; -res._hasConnectPatch = true; + res._hasConnectPatch = true; +}