@ -38,8 +38,31 @@ function testThrowInCallback (d, done) {
}
}
// Test that operations are executed in the right order
// We prevent Mocha from catching the exception we throw on purpose by remembering all current handlers, remove them and register them back after test ends
function testRightOrder ( d , done ) {
var currentUncaughtExceptionHandlers = process . listeners ( 'uncaughtException' ) ;
process . removeAllListeners ( 'uncaughtException' ) ;
process . on ( 'uncaughtException' , function ( err ) {
// Do nothing with the error which is only there to test we stay on track
} ) ;
d . find ( { } , function ( err ) {
process . nextTick ( function ( ) {
d . insert ( { bar : 1 } , function ( err ) {
for ( var i = 0 ; i < currentUncaughtExceptionHandlers . length ; i += 1 ) {
process . on ( 'uncaughtException' , currentUncaughtExceptionHandlers [ i ] ) ;
}
done ( ) ;
} ) ;
} ) ;
throw 'Some error' ;
} ) ;
}
@ -84,28 +107,14 @@ describe('Executor', function () {
var d ;
var d ;
beforeEach ( function ( done ) {
beforeEach ( function ( done ) {
d = new Datastore ( { filename : testDb } ) ;
d = new Datastore ( { inMemoryOnly : true } ) ;
d . filename . should . equal ( testDb ) ;
d . inMemoryOnly . should . equal ( true ) ;
d . inMemoryOnly . should . equal ( false ) ;
async . waterfall ( [
d . loadDatabase ( function ( err ) {
function ( cb ) {
assert . isNull ( err ) ;
Persistence . ensureDirectoryExists ( path . dirname ( testDb ) , function ( ) {
d . getAllData ( ) . length . should . equal ( 0 ) ;
fs . exists ( testDb , function ( exists ) {
return cb ( ) ;
if ( exists ) {
} ) ;
fs . unlink ( testDb , cb ) ;
} else { return cb ( ) ; }
} ) ;
} ) ;
}
, function ( cb ) {
d . loadDatabase ( function ( err ) {
assert . isNull ( err ) ;
d . getAllData ( ) . length . should . equal ( 0 ) ;
return cb ( ) ;
} ) ;
}
] , done ) ;
} ) ;
} ) ;
it ( 'A throw in a callback doesnt prevent execution of next operations' , function ( done ) {
it ( 'A throw in a callback doesnt prevent execution of next operations' , function ( done ) {