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?)
This commit is contained in:
Simon Kornblith 2015-03-07 22:17:44 -05:00
parent 1c32db68da
commit 50cd396918
3 changed files with 26 additions and 8 deletions

View File

@ -32,6 +32,7 @@ ZoteroUnit.prototype = {
/* nsICommandLineHandler */ /* nsICommandLineHandler */
handle:function(cmdLine) { handle:function(cmdLine) {
this.tests = cmdLine.handleFlagWithParam("test", false); this.tests = cmdLine.handleFlagWithParam("test", false);
this.noquit = cmdLine.handleFlag("noquit", false);
}, },
dump:function(x) { dump:function(x) {

View File

@ -1,5 +1,5 @@
Components.utils.import("resource://gre/modules/FileUtils.jsm"); 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"]. var ZoteroUnit = Components.classes["@mozilla.org/commandlinehandler/general-startup;1?type=zotero-unit"].
getService(Components.interfaces.nsISupports). getService(Components.interfaces.nsISupports).
@ -11,9 +11,11 @@ function quit(failed) {
if(!failed) { if(!failed) {
OS.File.writeAtomic(FileUtils.getFile("ProfD", ["success"]).path, Uint8Array(0)); OS.File.writeAtomic(FileUtils.getFile("ProfD", ["success"]).path, Uint8Array(0));
} }
Components.classes['@mozilla.org/toolkit/app-startup;1']. if(!ZoteroUnit.noquit) {
getService(Components.interfaces.nsIAppStartup). Components.classes['@mozilla.org/toolkit/app-startup;1'].
quit(Components.interfaces.nsIAppStartup.eForceQuit); getService(Components.interfaces.nsIAppStartup).
quit(Components.interfaces.nsIAppStartup.eForceQuit);
}
} }
function Reporter(runner) { function Reporter(runner) {
@ -50,7 +52,9 @@ function Reporter(runner) {
runner.on('fail', function(test, err){ runner.on('fail', function(test, err){
failed++; 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() { runner.on('end', function() {

View File

@ -1,27 +1,37 @@
#!/bin/bash #!/bin/bash
CWD="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" CWD="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
DEBUG=false
if [ "`uname`" == "Darwin" ]; then if [ "`uname`" == "Darwin" ]; then
FX_EXECUTABLE="/Applications/Firefox.app/Contents/MacOS/firefox" FX_EXECUTABLE="/Applications/Firefox.app/Contents/MacOS/firefox"
else else
FX_EXECUTABLE="firefox" FX_EXECUTABLE="firefox"
fi fi
FX_ARGS=""
function usage { function usage {
cat >&2 <<DONE cat >&2 <<DONE
Usage: $0 [-x FX_EXECUTABLE] [TESTS...] Usage: $0 [-x FX_EXECUTABLE] [TESTS...]
Options Options
-x FX_EXECUTABLE path to Firefox executable (default: $FX_EXECUTABLE) -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) TESTS set of tests to run (default: all)
DONE DONE
exit 1 exit 1
} }
while getopts "x:" opt; do while getopts "x:dc" opt; do
case $opt in case $opt in
x) x)
FX_EXECUTABLE="$OPTARG" FX_EXECUTABLE="$OPTARG"
;; ;;
d)
DEBUG=true
;;
c)
FX_ARGS="-jsconsole -noquit"
;;
*) *)
usage usage
;; ;;
@ -42,10 +52,13 @@ PROFILE="`mktemp -d 2>/dev/null || mktemp -d -t 'zotero-unit'`"
mkdir "$PROFILE/extensions" mkdir "$PROFILE/extensions"
echo "$CWD" > "$PROFILE/extensions/zotero-unit@zotero.org" echo "$CWD" > "$PROFILE/extensions/zotero-unit@zotero.org"
echo "`dirname "$CWD"`" > "$PROFILE/extensions/zotero@chnm.gmu.edu" 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" \ 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 # Check for success
test -e "$PROFILE/success" test -e "$PROFILE/success"