Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Work on console runner output and update some tests

  • Loading branch information...
commit 97781b3d57c099eabd9a42c1617ac9a7c1d48a0e 1 parent 9b68e51
Benjamin Thomas authored
View
78 bin/test-output.sh
@@ -1,45 +1,75 @@
+extras=$@
group() {
echo $1
echo "=============================================================================================="
}
run() {
- for cmd in "$@"
- do
- echo "$cmd\n"
- $cmd
- echo "\n----------------------------------------------------------------------------------------------"
- done
+ echo $ "$@" $extras
+ "$@" $extras
+ echo "----------------------------------------------------------------------------------------------"
}
+echo ""
+
group "mixed multiple"
-run "node test/test-sync_assertions.js test/test-all_passing.js -0" \
- "node test/test-sync_assertions.js test/test-all_passing.js -1" \
- "node test/test-sync_assertions.js test/test-all_passing.js -2"
+run node test/test-sync_assertions.js test/test-all_passing.js -0
+run node test/test-sync_assertions.js test/test-all_passing.js -1
+run node test/test-sync_assertions.js test/test-all_passing.js -2
group "make sure log level flag works"
-run "node test/test-sync_assertions.js test/test-all_passing.js --log-level 0"
+run node test/test-sync_assertions.js test/test-all_passing.js --log-level 0
group "make sure '--all' works with each output level"
-run "node test/test-sync_assertions.js test/test-all_passing.js -0 --all" \
- "node test/test-sync_assertions.js test/test-all_passing.js -1 --all" \
- "node test/test-sync_assertions.js test/test-all_passing.js -2 --all"
+run node test/test-sync_assertions.js test/test-all_passing.js -0 --all
+run node test/test-sync_assertions.js test/test-all_passing.js -1 --all
+run node test/test-sync_assertions.js test/test-all_passing.js -2 --all
group "make sure you can do no color"
-run "node test/test-sync_assertions.js test/test-all_passing.js --no-color"
+run node test/test-sync_assertions.js test/test-all_passing.js --no-color
group "all passing, one suite"
-run "node test/test-all_passing.js -0" \
- "node test/test-all_passing.js -1"
+run node test/test-all_passing.js -0
+run node test/test-all_passing.js -1
group "all passing, multiple suites"
-run "node test/test-all_passing.js test/test-overview.js -0" \
- "node test/test-all_passing.js test/test-overview.js -1"
+run node test/test-all_passing.js test/test-overview.js -0
+run node test/test-all_passing.js test/test-overview.js -1
+
+group "failures, one suite"
+run node test/test-sync_assertions.js -0
+run node test/test-sync_assertions.js -1
+
+group "failures, multiple suites"
+run node test/test-sync_assertions.js test/test-async_assertions.js -0
+run node test/test-sync_assertions.js test/test-async_assertions.js -1
+
+group "test errors, one suite"
+run node test/test-error_sync.js -0
+run node test/test-error_sync.js -1
+
+group "test errors, multiple suites"
+run node test/test-error_sync.js test/test-error_async.js -0
+run node test/test-error_sync.js test/test-error_async.js -1
+
+group "test multiple errors, in parallel"
+run node test/test-error_async.js -0 -p
+run node test/test-error_async.js -1 -p
+
+group "test load error, one suite"
+run node test/test-error_outside_suite.js -0
+run node test/test-error_outside_suite.js -1
+run node test/test-error_outside_suite.js -2
+
+group "test load error, multiple suites"
+run node test/test-error_outside_suite.js test/test-error_syntax.js -0
+run node test/test-error_outside_suite.js test/test-error_syntax.js -1
+run node test/test-error_outside_suite.js test/test-error_syntax.js -2
-group "some failing, one suite"
-run "node test/test-sync_assertions.js -0" \
- "node test/test-sync_assertions.js -1"
+group "--test-name"
+run node test/test-all_passing.js --all --test-name "test A" --test-name "test B"
+run node test/test-all_passing.js test/test-sync_assertions.js --all --test-name "test A" --test-name "test fail"
-group "some failing, multiple suites"
-run "node test/test-sync_assertions.js test/test-async_assertions.js -0" \
- "node test/test-sync_assertions.js test/test-async_assertions.js -1"
+group "--suite-name"
+run node test/test-all_passing.js test/test-sync_assertions.js test/test-async_assertions.js --suite-name "test/test-all_passing.js" --all
+run node test/test-all_passing.js test/test-sync_assertions.js test/test-async_assertions.js --suite-name "test/test-all_passing.js" --suite-name "test/test-sync_assertions.js" --all
View
70 lib/console-runner.js
@@ -221,16 +221,17 @@ exports.run = function(list, options, callback) {
console.log(bold(suite.name));
}
- if (err.stack) {
- var lines = err.stack.split('\n');
- }
- else {
+ console.log(yellow(' ' + bold('!') + ' Error loading suite'));
+
+ if (options.verbosity > 0) {
+ console.log('');
+
var lines = err.split('\n');
- }
- // todo check output level here
- for (var i = 0; i < lines.length; i++) {
- console.log(' ' + lines[i]);
+ var num = options.verbosity == 1 ? Math.min(6, lines.length) : lines.length;
+ for (var i = 0; i < num; i++) {
+ console.log(' ' + lines[i]);
+ }
}
console.log('');
@@ -315,30 +316,39 @@ exports.run = function(list, options, callback) {
console.log(bold(suite.name));
}
+ var names = tests.slice(0, tests.length-1).map(function(name) { return yellow(name); }).join(', ') +
+ (tests.length > 1 ? ' or ' : '') +
+ yellow(tests[tests.length-1]);
- if (tests.length > 1) {
- console.log(' One of the following tests threw an error: ');
- console.log(' ' + tests.map(function(name) { return yellow(name); }).join(', '));
- }
- else {
- console.log(' Error: ' + yellow(tests[0]));
- }
+ console.log(yellow('') + names);
- var s = err.stack.split("\n");
- if (err.message) {
- console.log(' '+err.message);
- }
- if (options.verbosity == 1) {
- if (s.length > 1) {
- console.log(s[1].replace(process.cwd(), '.'));
+ if (options.verbosity > 0) {
+ console.log('');
+
+ if (tests.length > 1) {
+ console.log(' One of the following tests threw an error: ');
+ console.log(' ' + names);
}
- if (s.length > 2) {
- console.log(s[2].replace(process.cwd(), '.'));
+ else {
+ console.log(' Error: ' + yellow(tests[0]));
}
- }
- else {
- for(var k = 1; k < s.length; k++) {
- console.log(s[k]);
+
+ var s = err.stack.split("\n");
+ if (err.message) {
+ console.log(' '+err.message);
+ }
+ if (options.verbosity == 1) {
+ if (s.length > 1) {
+ console.log(s[1].replace(process.cwd(), '.'));
+ }
+ if (s.length > 2) {
+ console.log(s[2].replace(process.cwd(), '.'));
+ }
+ }
+ else {
+ for(var k = 1; k < s.length; k++) {
+ console.log(s[k]);
+ }
}
}
@@ -378,9 +388,7 @@ exports.run = function(list, options, callback) {
}
else {
last += bold(green('SUCCESS:'));
- if (total > 1) {
- last += bold(' '+total+'/'+total+' suites passed successfully.');
- }
+ last += bold(' '+total+'/'+total+' suites passed successfully.');
}
console.log(last + ' ' + bold(((new Date() - startTime)/1000)+' seconds.'));
View
7 test/test-all_passing.js
@@ -1,3 +1,6 @@
+if (module == require.main) {
+ return require('../lib/async_testing').run(__filename, process.ARGV);
+}
module.exports = {
'test A': function(test) {
@@ -20,7 +23,3 @@ module.exports = {
test.finish();
}
};
-
-if (module == require.main) {
- require('../lib/async_testing').run(__filename, process.ARGV);
-}
View
25 test/test-error-async.js
@@ -1,25 +0,0 @@
-
-module.exports = {
- 'test passes': function(test) {
- setTimeout(function() {
- test.ok(true);
- test.finish();
- }, 500);
- },
-
- 'test async error 1': function(test) {
- setTimeout(function() {
- throw new Error('error 1');
- }, 500);
- },
-
- 'test async error 2': function(test) {
- setTimeout(function() {
- throw new Error('error 2');
- }, 500);
- }
-}
-
-if (module == require.main) {
- require('../lib/async_testing').run(__filename, process.ARGV);
-}
View
31 test/test-error_async.js
@@ -0,0 +1,31 @@
+if (module == require.main) {
+ // if this module is the script being run, then run the tests:
+ return require('../lib/async_testing').run(__filename, process.ARGV);
+}
+
+module.exports =
+ { 'test passes': function(test) {
+ setTimeout(function() {
+ test.ok(true);
+ test.finish();
+ }, 500);
+ }
+
+ , 'test async error 1': function(test) {
+ setTimeout(function() {
+ throw new Error('error 1');
+ }, 500);
+ }
+
+ , 'test async error 2': function(test) {
+ setTimeout(function() {
+ throw new Error('error 2');
+ }, 500);
+ }
+
+ , 'test async error 3': function(test) {
+ setTimeout(function() {
+ throw new Error('error 3');
+ }, 500);
+ }
+}
View
0  test/test-error-outside-suite.js → test/test-error_outside_suite.js
File renamed without changes
View
0  test/test-error-sync.js → test/test-error_sync.js
File renamed without changes
View
0  test/test-error-syntax.js → test/test-error_syntax.js
File renamed without changes
View
0  test/test-error-uncaught_exception_handler.js → test/test-error_uncaught_exception_handler.js
File renamed without changes
View
62 test/test-overview.js
@@ -1,42 +1,47 @@
+if (module == require.main) {
+ // if this module is the script being run, then run the tests:
+ return require('../lib/async_testing').run(__filename, process.ARGV);
+}
+
var wrap = require('../lib/async_testing').wrap;
var suiteSetupCount = 0;
-module.exports = {
- 'asynchronous test': function(test) {
- setTimeout(function() {
- // make an assertion (these are just regular assertions)
+module.exports =
+ { 'asynchronous test': function(test) {
+ setTimeout(function() {
+ // make an assertion (these are just regular assertions)
+ test.ok(true);
+ // finish the test
+ test.finish();
+ },500);
+ }
+
+ , 'synchronous test': function(test) {
test.ok(true);
- // finish the test
test.finish();
- },500);
- },
+ }
- 'synchronous test': function(test) {
- test.ok(true);
- test.finish();
- },
+ , 'test assertions expected': function(test) {
+ test.numAssertions = 1;
- 'test assertions expected': function(test) {
- test.numAssertions = 1;
+ test.ok(true);
+ test.finish();
+ }
- test.ok(true);
- test.finish();
- },
+ , 'test catch async error': function(test) {
+ var e = new Error();
- 'test catch async error': function(test) {
- var e = new Error();
+ test.uncaughtExceptionHandler = function(err) {
+ test.equal(e, err);
+ test.finish();
+ }
- test.uncaughtExceptionHandler = function(err) {
- test.equal(e, err);
- test.finish();
+ setTimeout(function() {
+ throw e;
+ }, 500);
}
- setTimeout(function() {
- throw e;
- }, 500);
- }
-
, 'namespace 1':
{ 'test A': function(test) {
test.ok(true);
@@ -121,8 +126,3 @@ module.exports = {
}
})
};
-
-// if this module is the script being run, then run the tests:
-if (module == require.main) {
- require('../lib/async_testing').run(__filename, process.ARGV);
-}
Please sign in to comment.
Something went wrong with that request. Please try again.