Permalink
Browse files

made all tests async, changed build process.

  • Loading branch information...
1 parent edbdedd commit 186ca437a7a3a9f422942cabdbd02c117644abb5 @jed committed Apr 23, 2010
Showing with 94 additions and 49 deletions.
  1. +23 −9 apps/fab.body.js
  2. +8 −0 builds/all.js
  3. +12 −0 builds/core.js
  4. +0 −39 builds/default.js
  5. +1 −1 index.js
  6. +23 −0 utils/build.js
  7. +27 −0 utils/test.js
View
@@ -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;
View
@@ -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 );
View
@@ -0,0 +1,12 @@
+module.exports = require( "../utils/build" )([
+
+ "fab"
+ , "fab.body"
+ , "fab.Function"
+ , "fab.identity"
+ , "fab.Number"
+ , "fab.path"
+ , "fab.RegExp"
+ , "fab.status"
+
+]);
View
@@ -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() });
-};
View
@@ -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 ];
View
@@ -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;
+}
View
@@ -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("")
+ )
+ }
+ });
+ })
+}

0 comments on commit 186ca43

Please sign in to comment.