Permalink
Browse files

Added mocha test coverage support

  • Loading branch information...
1 parent d939271 commit 48e927241339c4a02f9c64c413585741bff9124c @tj tj committed Feb 24, 2012
Showing with 59 additions and 50 deletions.
  1. +7 −1 Makefile
  2. +3 −1 index.js
  3. +49 −48 lib/patch.js
View
@@ -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
+.PHONY: test-cov site docs test docclean
View
@@ -1,2 +1,4 @@
-module.exports = require('./lib/connect');
+module.exports = process.env.CONNECT_COV
+ ? require('./lib-cov/connect')
+ : require('./lib/connect');
View
@@ -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.