From 186ca437a7a3a9f422942cabdbd02c117644abb5 Mon Sep 17 00:00:00 2001
From: Jed Schmidt
Date: Fri, 23 Apr 2010 11:33:14 -0400
Subject: [PATCH] made all tests async, changed build process.
---
apps/fab.body.js | 32 +++++++++++++++++++++++---------
builds/all.js | 8 ++++++++
builds/core.js | 12 ++++++++++++
builds/default.js | 39 ---------------------------------------
index.js | 2 +-
utils/build.js | 23 +++++++++++++++++++++++
utils/test.js | 27 +++++++++++++++++++++++++++
7 files changed, 94 insertions(+), 49 deletions(-)
create mode 100644 builds/all.js
create mode 100644 builds/core.js
delete mode 100644 builds/default.js
create mode 100644 utils/build.js
create mode 100644 utils/test.js
diff --git a/apps/fab.body.js b/apps/fab.body.js
index 0d0b31e..6426690 100644
--- a/apps/fab.body.js
+++ b/apps/fab.body.js
@@ -7,20 +7,34 @@ function body( obj ) {
exports.summary = "Turns an object into an app that responds with it.";
-exports.test = function() {
+exports.tests = ( function() {
var assert = require( "assert" )
, response = "hello"
, app = body( response )
, fn = function(){};
+
+ return [
+
+ function
+ bodyReturnsUnaryApp() {
+ this( app.length === 0 )
+ },
+
+ function
+ bodyRespondsWithCorrectPayload() {
+ var out = this;
+ app.call( function( obj ){ out( obj.body === response ) } );
+ },
- assert.equal( app.length, 0, "fab.body app is unary." )
-
- app.call( function( obj ) {
- assert.equal( obj.body, response, "body sends correct payload." )
- return function() {
- assert.equal( arguments.length, 0, "fab.body closes connection after payload." )
+ function
+ bodyClosesConnection() {
+ var out = this;
+ app.call( function() {
+ return function(){ out( !arguments.length ) }
+ })
}
- })
-}
+ ];
+
+})();
exports.app = body;
\ No newline at end of file
diff --git a/builds/all.js b/builds/all.js
new file mode 100644
index 0000000..c80d9c8
--- /dev/null
+++ b/builds/all.js
@@ -0,0 +1,8 @@
+var dir = require( "path" ).join( __dirname, "../apps")
+ , apps = require( "fs" )
+ .readdirSync( dir )
+ .filter( function( name ){ return name.substr( -3 ) == ".js" } )
+ .map( function( name ){ return name.replace( /\.js$/, "" ) } )
+ .sort();
+
+module.exports = require( "../utils/build" )( apps );
\ No newline at end of file
diff --git a/builds/core.js b/builds/core.js
new file mode 100644
index 0000000..255a37e
--- /dev/null
+++ b/builds/core.js
@@ -0,0 +1,12 @@
+module.exports = require( "../utils/build" )([
+
+ "fab"
+ , "fab.body"
+ , "fab.Function"
+ , "fab.identity"
+ , "fab.Number"
+ , "fab.path"
+ , "fab.RegExp"
+ , "fab.status"
+
+]);
\ No newline at end of file
diff --git a/builds/default.js b/builds/default.js
deleted file mode 100644
index d03f0e1..0000000
--- a/builds/default.js
+++ /dev/null
@@ -1,39 +0,0 @@
-var tests = [];
-
-[ "fab"
- , "fab.tmpl"
- , "fab.body"
- , "fab.capture"
- , "fab.echo"
- , "fab.Function"
- , "fab.identity"
- , "fab.map"
- , "fab.method"
- , "fab.nodejs"
- , "fab.nodejs.contentLength"
- , "fab.nodejs.fs"
- , "fab.nodejs.http"
- , "fab.Number"
- , "fab.path"
- , "fab.RegExp"
- , "fab.status"
- , "fab.stringify"
- , "fab.tap"
-
-].forEach( function( name ) {
- var name
- , parent = exports
- , parts = name.split( "." )
- , app = require( "../apps/" + name );
-
- while ( parts.length > 1 )
- { parent = parent[ parts.shift() ] }
-
- parent[ parts.shift() ] = app.app;
- if ( app.test ) tests.push( app.test );
-});
-
-exports.app = exports.fab;
-exports.test = function() {
- tests.forEach( function( test ) { test() });
-};
\ No newline at end of file
diff --git a/index.js b/index.js
index 1fb4382..735edb1 100644
--- a/index.js
+++ b/index.js
@@ -2,7 +2,7 @@ var name
, app
, fab
= module.exports
- = require( "./builds/default" ).app;
+ = require( "./builds/all" ).app;
for ( name in fab ) {
app = fab[ name ];
diff --git a/utils/build.js b/utils/build.js
new file mode 100644
index 0000000..032bf66
--- /dev/null
+++ b/utils/build.js
@@ -0,0 +1,23 @@
+module.exports = function( apps ) {
+ var tests = []
+ , ret = {}
+ , dir = require( "path" ).join( __dirname, "../apps/");
+
+ apps.forEach( function( name ) {
+ var name
+ , parent = ret
+ , parts = name.split( "." )
+ , app = require( dir + name );
+
+ while ( parts.length > 1 )
+ { parent = parent[ parts.shift() ] }
+
+ parent[ parts.shift() ] = app.app;
+ tests.push.apply( tests, app.tests || [] );
+ });
+
+ ret.tests = tests;
+ ret.app = ret.fab;
+
+ return ret;
+}
\ No newline at end of file
diff --git a/utils/test.js b/utils/test.js
new file mode 100644
index 0000000..f181297
--- /dev/null
+++ b/utils/test.js
@@ -0,0 +1,27 @@
+var puts = require( "sys" ).puts;
+
+module.exports = function( build ) {
+ var tests = build.tests
+ , count = tests.length
+ , results = [ 0, 0 ];
+
+ puts( "Running " + count + " tests..." )
+
+ build.tests.forEach( function( test ) {
+ test.call( function( ok ) {
+ results[ +ok ]++
+ puts( test.name + ": " + ok );
+
+ if ( results[ 0 ] + results[ 1 ] == count ) {
+ puts(
+ [ "Done. "
+ , results[ 1 ]
+ , " passed, "
+ , results[ 0 ]
+ , " failed."
+ ].join("")
+ )
+ }
+ });
+ })
+}
\ No newline at end of file