From 50cd396918dc56e10a43e860e5f9d969e02e4446 Mon Sep 17 00:00:00 2001 From: Simon Kornblith Date: Sat, 7 Mar 2015 22:17:44 -0500 Subject: [PATCH] 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?) --- test/components/zotero-unit.js | 1 + test/content/runtests.js | 14 +++++++++----- test/runtests.sh | 19 ++++++++++++++++--- 3 files changed, 26 insertions(+), 8 deletions(-) diff --git a/test/components/zotero-unit.js b/test/components/zotero-unit.js index 6b102c13d..a1d3cc685 100644 --- 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 index aa0d6e848..b751b8f85 100644 --- 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 index c31147f01..17a04f28f 100755 --- 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 < "$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 < "$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"