[#25] Added assertion count to testcase output
parent
f7700f93e5
commit
9ea60a18b0
|
@ -1,6 +1,31 @@
|
||||||
|
|
||||||
|
|
||||||
var assert = require( 'assert' );
|
var assert = require( 'assert' ),
|
||||||
|
assert_wrapped = {},
|
||||||
|
acount = 0;
|
||||||
|
|
||||||
|
|
||||||
|
// wrap each of the assertions so that we can keep track of the number of times
|
||||||
|
// that they were invoked
|
||||||
|
for ( f in assert )
|
||||||
|
{
|
||||||
|
var _assert_cur = assert[ f ];
|
||||||
|
|
||||||
|
if ( typeof _assert_cur !== 'function' )
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// wrap the assertion to keep count
|
||||||
|
assert_wrapped[ f ] = ( function( a )
|
||||||
|
{
|
||||||
|
return function()
|
||||||
|
{
|
||||||
|
acount++;
|
||||||
|
a.apply( this, arguments );
|
||||||
|
};
|
||||||
|
} )( _assert_cur );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -28,6 +53,9 @@ module.exports = function( test_case )
|
||||||
context = prepareCaseContext(),
|
context = prepareCaseContext(),
|
||||||
setUp = test_case.setUp;
|
setUp = test_case.setUp;
|
||||||
|
|
||||||
|
// reset assertion count for this case
|
||||||
|
acount = 0;
|
||||||
|
|
||||||
// perform case-wide setup
|
// perform case-wide setup
|
||||||
test_case.caseSetUp && test_case.caseSetUp.call( context );
|
test_case.caseSetUp && test_case.caseSetUp.call( context );
|
||||||
|
|
||||||
|
@ -69,7 +97,8 @@ module.exports = function( test_case )
|
||||||
testPrint(
|
testPrint(
|
||||||
( ( failures.length ) ? "FAILED" : "OK" ) + " - " +
|
( ( failures.length ) ? "FAILED" : "OK" ) + " - " +
|
||||||
scount + " successful, " + failures.length + " failure(s), " +
|
scount + " successful, " + failures.length + " failure(s), " +
|
||||||
( scount + failures.length ) + " total\n"
|
( scount + failures.length ) + " total " +
|
||||||
|
'(' + acount + " assertion" + ( ( acount !== 1 ) ? 's' : '' ) + ")\n"
|
||||||
);
|
);
|
||||||
|
|
||||||
// exit with non-zero status to indicate failure
|
// exit with non-zero status to indicate failure
|
||||||
|
@ -89,16 +118,16 @@ function prepareCaseContext()
|
||||||
return {
|
return {
|
||||||
require: require( __dirname + '/common' ).require,
|
require: require( __dirname + '/common' ).require,
|
||||||
|
|
||||||
fail: assert.fail,
|
fail: assert_wrapped.fail,
|
||||||
assertOk: assert.ok,
|
assertOk: assert_wrapped.ok,
|
||||||
assertEqual: assert.equal,
|
assertEqual: assert_wrapped.equal,
|
||||||
assertNotEqual: assert.notEqual,
|
assertNotEqual: assert_wrapped.notEqual,
|
||||||
assertDeepEqual: assert.deepEqual,
|
assertDeepEqual: assert_wrapped.deepEqual,
|
||||||
assertStrictEqual: assert.strictEqual,
|
assertStrictEqual: assert_wrapped.strictEqual,
|
||||||
assertNotStrictEqual: assert.notStrictEqual,
|
assertNotStrictEqual: assert_wrapped.notStrictEqual,
|
||||||
assertThrows: assert.throws,
|
assertThrows: assert_wrapped.throws,
|
||||||
assertDoesNotThrow: assert.doesNotThrow,
|
assertDoesNotThrow: assert_wrapped.doesNotThrow,
|
||||||
assertIfError: assert.ifError,
|
assertIfError: assert_wrapped.ifError,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue