Skip to content

Commit

Permalink
Added mocha test coverage support
Browse files Browse the repository at this point in the history
  • Loading branch information
tj committed Feb 24, 2012
1 parent d939271 commit 48e9272
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 50 deletions.
8 changes: 7 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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 > $@

Expand All @@ -27,4 +33,4 @@ site: docclean docs
&& cp -fr /tmp/docs/* . \
&& echo "done"

.PHONY: site docs test docclean
.PHONY: test-cov site docs test docclean
4 changes: 3 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@

module.exports = require('./lib/connect');
module.exports = process.env.CONNECT_COV
? require('./lib-cov/connect')
: require('./lib/connect');
97 changes: 49 additions & 48 deletions lib/patch.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

0 comments on commit 48e9272

Please sign in to comment.