From 280cd232f73080caf3a68ded879bf929d6520533 Mon Sep 17 00:00:00 2001
From: Lloyd Hilaiel <lloyd@hilaiel.com>
Date: Wed, 14 Sep 2011 17:25:06 -0600
Subject: [PATCH] make npm test work right.  improve test.sh to ensure it's
 using the version of vows that the package is locked to and works both when
 invoked via npm and from cmdline

---
 package.json             |  3 ++-
 scripts/run_all_tests.sh | 31 +++++++++++++++++++++++++++++++
 test.sh                  | 24 ++----------------------
 3 files changed, 35 insertions(+), 23 deletions(-)
 create mode 100755 scripts/run_all_tests.sh

diff --git a/package.json b/package.json
index eb3760192..1a9eee6fa 100644
--- a/package.json
+++ b/package.json
@@ -28,6 +28,7 @@
     , "jwcrypto": "https://github.com/lloyd/jwcrypto/tarball/ace101"
   }
   , "scripts": {
-    "postinstall": "./scripts/generate_ephemeral_keys.sh"
+    "postinstall": "./scripts/generate_ephemeral_keys.sh",
+    "test": "./scripts/run_all_tests.sh"
   }
 }
diff --git a/scripts/run_all_tests.sh b/scripts/run_all_tests.sh
new file mode 100755
index 000000000..ed6ab62f2
--- /dev/null
+++ b/scripts/run_all_tests.sh
@@ -0,0 +1,31 @@
+#!/bin/bash
+
+SCRIPT_DIR="$( cd "$( dirname "$0" )" && pwd )"
+BASEDIR=$(dirname $SCRIPT_DIR)
+export PATH=$PATH:$SCRIPT_DIR/../node_modules/.bin
+
+VOWS=`which vows 2> /dev/null`
+if [ ! -x "$VOWS" ]; then
+    echo "vows not found in your path.  try:  npm install"
+    exit 1
+fi
+
+# vows hates absolute paths.  sheesh.
+cd $BASEDIR
+
+for env in test_json test_mysql ; do
+  export NODE_ENV=$env
+  $SCRIPT_DIR/test_db_connectivity.js
+  if [ $? = 0 ] ; then 
+      echo "Testing with NODE_ENV=$env"
+      for file in browserid/tests/*.js ; do
+          echo $file
+          vows $file
+          if [[ $? != 0 ]] ; then
+              exit 1
+          fi
+      done
+  else
+      echo "CANNOT TEST '$env' ENVIRONMENT: can't connect to the database"
+  fi
+done
diff --git a/test.sh b/test.sh
index 7dec3f2b6..b41801ed1 100755
--- a/test.sh
+++ b/test.sh
@@ -1,23 +1,3 @@
-#!/bin/bash
+#!/bin/sh
 
-VOWS=`which vows 2> /dev/null`
-if [ ! -x "$VOWS" ]; then
-    echo "vows not found in your path.  try:  npm install -g vows"
-    exit 1
-fi
-
-for env in test_json test_mysql ; do
-  export NODE_ENV=$env
-  ./scripts/test_db_connectivity.js
-  if [ $? = 0 ] ; then 
-      echo "Testing with NODE_ENV=$env"
-      for file in browserid/tests/*.js ; do
-          vows $file
-          if [[ $? != 0 ]] ; then
-              exit 1
-          fi
-      done
-  else
-      echo "CANNOT TEST '$env' ENVIRONMENT: can't connect to the database"
-  fi
-done
+npm test
-- 
GitLab