From 9b6378f3f2b3176148f62c02b28778cf2c3b17de Mon Sep 17 00:00:00 2001 From: Benjamin Thomas Date: Fri, 29 Oct 2010 23:47:19 -0600 Subject: [PATCH] Format console runners summary line differently --- lib/console-runner.js | 61 ++++++++++++++++++++++++++----------------- todo.txt | 22 ++++++++-------- 2 files changed, 48 insertions(+), 35 deletions(-) diff --git a/lib/console-runner.js b/lib/console-runner.js index abe6963..056eda7 100644 --- a/lib/console-runner.js +++ b/lib/console-runner.js @@ -1,8 +1,3 @@ -/* Console runner - * - * this is a mess right now, but it gets the job done! - */ - var assert = require('assert') , path = require('path') ; @@ -266,21 +261,21 @@ exports.run = function(list, options, callback) { if (suiteResults.numFailures > 0) { console.log(''); last += ' '; - if (suiteResults.numFailures > 0) { + if (suites.length > 1) { last += ' FAILURES: '+suiteResults.numFailures+'/'+total+' tests failed.'; } } - else if (options.verbosity > 0 && suites.length > 1) { + else if (suites.length > 1) { last += ' '+green('OK: ')+total+' test'+(total == 1 ? '' : 's')+'. '+totalAssertions+' assertion'+(totalAssertions == 1 ? '' : 's')+'.'; } } if (options.verbosity == 0) { - if (options.printSuccesses || suiteResults.numFailures >0) { + if (options.printSuccesses || suiteResults.numFailures > 0) { console.log(''); } } - else if(suiteResults.numFailures > 0 || suites.length > 1) { + else if(suiteResults.numFailures > 0 && suites.length > 1) { console.log(last + ' ' + (suite.duration/1000) + ' seconds.'); console.log(''); } @@ -344,33 +339,51 @@ exports.run = function(list, options, callback) { console.log('Did you forget to call test.finish()?'); } , allDone: function() { - var successes = 0; - var total = 0; - - var allResults = suites.map(function(el) { - return el.results; - }); + var passingSuites = 0 + , totalSuites = 0 + , totalTests = 0 + , passingTests = 0 + ; for(var i = 0; i < suites.length; i++) { - total++; + totalSuites++; if (suites[i].status == 'suiteCompleted' && suites[i].results[0].numFailures == 0) { - successes++; + passingSuites++; + } + + if (typeof suites[i].results[0] == 'object' && 'numSuccesses' in suites[i].results[0]) { + totalTests += suites[i].results[0].numSuccesses + suites[i].results[0].numFailures; + passingTests += suites[i].results[0].numSuccesses; + } + else { + totalTests += NaN; } } var last = ''; - if (successes != total) { - last += bold(red('PROBLEMS:')); - last += bold(' '+(total-successes)+'/'+total+' suites had problems.'); + if (passingSuites != totalSuites) { + last += red('PROBLEMS:'); + last += ' '+(totalSuites-passingSuites)+'/'+totalSuites+' suites had problems.'; } else { - last += bold(green('SUCCESS:')); - last += bold(' '+total+'/'+total+' suites passed successfully.'); + last += green('SUCCESS:'); + last += ' '+totalSuites+' suite' + (totalSuites == 1 ? '' : 's') + '.'; + } + + if (isNaN(totalTests)) { + last += ' Could not count tests.'; + } + else if (passingTests != totalTests) { + last += ' ' + (totalTests-passingTests)+'/'+totalTests+' tests' + ' failed.'; } - console.log(last + ' ' + bold(((new Date() - startTime)/1000)+' seconds.')); + else { + last += ' ' + totalTests + ' test' + (totalTests == 1 ? '' : 's') + '.'; + } + + console.log(bold(last + ' ' + ((new Date() - startTime)/1000) + ' seconds.')); if (callback) { - callback(total - successes); + callback(totalSuites - passingSuites); } } } diff --git a/todo.txt b/todo.txt index e3d73a4..5b23bbf 100644 --- a/todo.txt +++ b/todo.txt @@ -2,21 +2,21 @@ Featueres (not sorted in order of importance -------------------------------------------- async_testing.run: + better error handling when parsing arguments, and by better I mean, some -+ rethink args to run's callback (make them more useful) <---- +? stop using home grown options parser and add one as a sub module? + help message summarizing async_testing in generateHelp + ++ rethink args to run's callback (make them more useful) <---- + ? allow a config file (at say ~/.node-async-testing.json) or something for setting default run options, so say if you want the default to have tests and suites be parallel you can do that. ? make the default to be to run test and suites in parallel? ? Add new flag, which says to run everything in parallel, but if a suite fails in some way, don't output it's results, instead re-run the suite serially -+ stop using home grown options parser and add one as a sub module - -Console Runner: -+ readd number of completed tests back to summary in console runner <---- -? are we being too redundant when we have errors? Web Runner: ++ only show suites that have tests we are running and only show those tests (in <---- + the case of the --test-name flag) + checkbox for web runner to automatically run suites on window or tab focus + keep track of which suites have been opened and are parallel across refreshes (in a cookie) @@ -24,12 +24,13 @@ Web Runner: via the command line) ? Instead of just show test as blank when a file changes, mention something? ? Show number of failures when the test is closed? -+ only show suites that have tests we are running and only show those tests (in <---- - the case of the --test-name flag) Running tests (async_testing.runSuite, async_testing.runFile): ? consider combining suiteCompleted, suiteError, suiteExit and suiteLoadError all into one callback, (suiteDone) ++ readd support for catching and reporting on errors that I ripped earlier this + month. They screw up suiteSetup and suiteTeardown and setup and teardown, but + we still might be able to make it work (v0.5) ? test.finish can take error? so you could say do: `fs.readFile(test.finish)` to make sure that readFile doesn't error without having to write your @@ -45,10 +46,9 @@ Running tests (async_testing.runSuite, async_testing.runFile): + improve stack traces for assertion failures (remove first line, which is just the wrapped assertion being called) + code coverage -+ readd support for catching and reporting on errors that I ripped earlier this - month. They screw up suiteSetup and suiteTeardown and setup and teardown, but - we still might be able to make it work +? add a script for running tests? (like we used to have...) Docs ---- + update docs and add list of command line arguments for run and what they do ++ add note about contributing/contacting