Skip to content
This repository has been archived by the owner on Mar 3, 2023. It is now read-only.

Commit

Permalink
made all tests async, changed build process.
Browse files Browse the repository at this point in the history
  • Loading branch information
jed committed Apr 23, 2010
1 parent edbdedd commit 186ca43
Show file tree
Hide file tree
Showing 7 changed files with 94 additions and 49 deletions.
32 changes: 23 additions & 9 deletions apps/fab.body.js
Expand Up @@ -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;
8 changes: 8 additions & 0 deletions 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 );
12 changes: 12 additions & 0 deletions 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"

]);
39 changes: 0 additions & 39 deletions builds/default.js

This file was deleted.

2 changes: 1 addition & 1 deletion index.js
Expand Up @@ -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 ];
Expand Down
23 changes: 23 additions & 0 deletions 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;
}
27 changes: 27 additions & 0 deletions 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("")
)
}
});
})
}

0 comments on commit 186ca43

Please sign in to comment.