Permalink
Browse files

npm test

  • Loading branch information...
1 parent 8c2e256 commit 03b7f014fb8ea9a90403d7f831b1e47f9ad2b7a8 @hdachev committed Jun 25, 2012
Showing with 34 additions and 3 deletions.
  1. +1 −0 .gitignore
  2. +3 −0 package.json
  3. +30 −3 test.js
View
@@ -1 +1,2 @@
node*
+npm*
View
@@ -14,5 +14,8 @@
"repository" : {
"type" : "git",
"url" : "git://github.com/hdachev/fakeredis.git"
+ },
+ "scripts" : {
+ "test" : "node test"
}
}
View
33 test.js
@@ -850,11 +850,13 @@ process.stdout.write ( 'testing fakeredis ...\n\n' );
//// Test shorthand.
-var TEST_COUNT;
+var TEST_COUNT = 0,
+ numErrors = 0;
+
function test ( name, xErr, xData )
{
- if ( !TEST_COUNT ) TEST_COUNT = 0;
- var timeout, c = ++ TEST_COUNT;
+ var timeout,
+ c = ++ TEST_COUNT;
xErr = JSON.stringify ( xErr );
xData = JSON.stringify ( xData );
@@ -863,6 +865,7 @@ function test ( name, xErr, xData )
(
function ()
{
+ numErrors ++;
process.stdout.write ( '\033[1;31m\n ✗ #' + c + ' ' + name + '\033[0m:\n\tDidn\'t call back.\n\txErr = ' + xErr + '\t\txData = ' + xData + '\n\n' );
},
5000
@@ -884,9 +887,33 @@ function test ( name, xErr, xData )
if ( err === xErr && data === xData )
process.stdout.write ( '\033[1;32m ✓ #' + c + ' ' + name + '\033[0m\n' );
+
else
+ {
+ numErrors ++;
process.stdout.write ( '\033[1;31m\n ✗ #' + c + ' ' + name + '\033[0m:\n\terr = ' + err + '\t\tdata = ' + data + '\n\txErr = ' + xErr + '\t\txData = ' + xData + '\n\n' );
+ }
};
}
+var doexit = false;
+process.on ( 'exit', function ()
+{
+ if ( doexit )
+ return;
+ doexit = true;
+
+ if ( !numErrors )
+ {
+ process.stdout.write ( '\n\033[1;32m ✓ All good.\033[0m\n' );
+ process.exit ( 0 );
+ }
+
+ else
+ {
+ process.stdout.write ( '\033[1;31m\n' + numErrors + ' broken.\033[0m\n' );
+ process.exit ( 1 );
+ }
+});
+

0 comments on commit 03b7f01

Please sign in to comment.