commit 50cd396918dc56e10a43e860e5f9d969e02e4446
parent 1c32db68dae445904f562ad7183d829ba56a0451
Author: Simon Kornblith <simon@simonster.com>
Date: Sat, 7 Mar 2015 22:17:44 -0500
Make debugging tests a bit easier
- Add command-line argument to enable debug logging
- Add command-line argument to open (and leave open) jsconsole
- Try to print error stack traces (although Mocha doesn't seem to like
them?)
Diffstat:
3 files changed, 26 insertions(+), 8 deletions(-)
diff --git a/test/components/zotero-unit.js b/test/components/zotero-unit.js
@@ -32,6 +32,7 @@ ZoteroUnit.prototype = {
/* nsICommandLineHandler */
handle:function(cmdLine) {
this.tests = cmdLine.handleFlagWithParam("test", false);
+ this.noquit = cmdLine.handleFlag("noquit", false);
},
dump:function(x) {
diff --git a/test/content/runtests.js b/test/content/runtests.js
@@ -1,5 +1,5 @@
Components.utils.import("resource://gre/modules/FileUtils.jsm");
-Components.utils.import("resource://gre/modules/osfile.jsm")
+Components.utils.import("resource://gre/modules/osfile.jsm");
var ZoteroUnit = Components.classes["@mozilla.org/commandlinehandler/general-startup;1?type=zotero-unit"].
getService(Components.interfaces.nsISupports).
@@ -11,9 +11,11 @@ function quit(failed) {
if(!failed) {
OS.File.writeAtomic(FileUtils.getFile("ProfD", ["success"]).path, Uint8Array(0));
}
- Components.classes['@mozilla.org/toolkit/app-startup;1'].
- getService(Components.interfaces.nsIAppStartup).
- quit(Components.interfaces.nsIAppStartup.eForceQuit);
+ if(!ZoteroUnit.noquit) {
+ Components.classes['@mozilla.org/toolkit/app-startup;1'].
+ getService(Components.interfaces.nsIAppStartup).
+ quit(Components.interfaces.nsIAppStartup.eForceQuit);
+ }
}
function Reporter(runner) {
@@ -50,7 +52,9 @@ function Reporter(runner) {
runner.on('fail', function(test, err){
failed++;
- dump("\r"+indent()+Mocha.reporters.Base.symbols.err+" "+test.title+"\n");
+ dump("\r"+indent()+Mocha.reporters.Base.symbols.err+" "+test.title+"\n"+
+ indent()+" "+err.toString()+" at\n"+
+ indent()+" "+err.stack.replace("\n", "\n"+indent()+" ", "g"));
});
runner.on('end', function() {
diff --git a/test/runtests.sh b/test/runtests.sh
@@ -1,27 +1,37 @@
#!/bin/bash
CWD="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
+DEBUG=false
if [ "`uname`" == "Darwin" ]; then
FX_EXECUTABLE="/Applications/Firefox.app/Contents/MacOS/firefox"
else
FX_EXECUTABLE="firefox"
fi
+FX_ARGS=""
function usage {
cat >&2 <<DONE
Usage: $0 [-x FX_EXECUTABLE] [TESTS...]
Options
-x FX_EXECUTABLE path to Firefox executable (default: $FX_EXECUTABLE)
+ -d enable debug logging
+ -c open JavaScript console and don't quit on completion
TESTS set of tests to run (default: all)
DONE
exit 1
}
-while getopts "x:" opt; do
+while getopts "x:dc" opt; do
case $opt in
x)
FX_EXECUTABLE="$OPTARG"
;;
+ d)
+ DEBUG=true
+ ;;
+ c)
+ FX_ARGS="-jsconsole -noquit"
+ ;;
*)
usage
;;
@@ -42,10 +52,13 @@ PROFILE="`mktemp -d 2>/dev/null || mktemp -d -t 'zotero-unit'`"
mkdir "$PROFILE/extensions"
echo "$CWD" > "$PROFILE/extensions/zotero-unit@zotero.org"
echo "`dirname "$CWD"`" > "$PROFILE/extensions/zotero@chnm.gmu.edu"
-echo 'user_pref("extensions.autoDisableScopes", 0);' > "$PROFILE/prefs.js"
+cat <<EOF > "$PROFILE/prefs.js"
+user_pref("extensions.autoDisableScopes", 0);
+user_pref("extensions.zotero.debug.log", $DEBUG);
+EOF
MOZ_NO_REMOTE=1 NO_EM_RESTART=1 "$FX_EXECUTABLE" -profile "$PROFILE" \
- -chrome chrome://zotero-unit/content/runtests.html -test "$TESTS"
+ -chrome chrome://zotero-unit/content/runtests.html -test "$TESTS" $FX_ARGS
# Check for success
test -e "$PROFILE/success"