Add -f test flag to stop after first test failure

(Mocha has a 'bail' config flag that's supposed to do this, but it doesn't seem
to work when passed to mocha.setup() (maybe because we're setting a custom fail
handler?), so this just calls abort() on the runner manually.)
This commit is contained in:
Dan Stillman 2015-05-29 04:01:40 -04:00
parent 15252623d7
commit f3a6b41c1c
3 changed files with 18 additions and 3 deletions

View file

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

View file

@ -22,7 +22,7 @@ function quit(failed) {
} }
function Reporter(runner) { function Reporter(runner) {
var indents = 0, passed = 0, failed = 0; var indents = 0, passed = 0, failed = 0, aborted = false;
function indent() { function indent() {
return Array(indents).join(' '); return Array(indents).join(' ');
@ -61,10 +61,16 @@ function Reporter(runner) {
+ " " + test.title + "\n" + " " + test.title + "\n"
+ indent() + " " + err.toString() + " at\n" + indent() + " " + err.toString() + " at\n"
+ indent() + " " + err.stack.replace("\n", "\n" + indent() + " ", "g")); + indent() + " " + err.stack.replace("\n", "\n" + indent() + " ", "g"));
if (ZoteroUnit.bail) {
aborted = true;
runner.abort();
}
}); });
runner.on('end', function() { runner.on('end', function() {
dump(passed+"/"+(passed+failed)+" tests passed.\n"); dump(passed + "/" + (passed + failed) + " tests passed"
+ (aborted ? " -- aborting" : "") + "\n");
quit(failed != 0); quit(failed != 0);
}); });
} }

View file

@ -29,13 +29,14 @@ 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 -d enable debug logging
-c open JavaScript console and don't quit on completion -c open JavaScript console and don't quit on completion
-f stop after first test failure
-b skip bundled translator/style installation -b skip bundled translator/style installation
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:dcb" opt; do while getopts "x:dcfb" opt; do
case $opt in case $opt in
x) x)
FX_EXECUTABLE="$OPTARG" FX_EXECUTABLE="$OPTARG"
@ -46,6 +47,9 @@ while getopts "x:dcb" opt; do
c) c)
FX_ARGS="-jsconsole -noquit" FX_ARGS="-jsconsole -noquit"
;; ;;
f)
STOP_ON_FAILURE=true
;;
b) b)
SKIP_BUNDLED=true SKIP_BUNDLED=true
;; ;;
@ -101,6 +105,10 @@ if [ "$SKIP_BUNDLED" = true ]; then
FX_ARGS="$FX_ARGS -ZoteroSkipBundledFiles" FX_ARGS="$FX_ARGS -ZoteroSkipBundledFiles"
fi fi
if [ "$STOP_ON_FAILURE" = true ]; then
FX_ARGS="$FX_ARGS -bail"
fi
# Clean up on exit # Clean up on exit
trap "{ rm -rf \"$PROFILE\"; }" EXIT trap "{ rm -rf \"$PROFILE\"; }" EXIT