var cmbf = require('../');
var requireDirectory = require('require-directory');
var path = require('path');
var P = require('bluebird');

module.exports = cmbf.launch({testMode: true}).then(function() {
    cmbf.log.info("CMBF test server was successfully launched!");
    var ctx = {};

    // Build the test context
    var systemLog = cmbf.server.plugins['covistra-system'].systemLog;
    var config = cmbf.server.plugins['hapi-config'].CurrentConfiguration;

    ctx.server = cmbf.server;
    ctx.log = systemLog;
    ctx.config = config;

    ctx.shutdown = function() {
        cmbf.log.info("Test server was successfully terminated");
        process.exit(0);
    };
    ctx.cleanUp = cmbf.server.plugins['covistra-mongodb'].cleanUp;
    ctx.cleanUpRef = cmbf.server.plugins['covistra-mongodb'].cleanUpRef;
    ctx.success = function(cb) {
        return function() {
            return cb();
        };
    };

    // Load all test data
    ctx.data = cmbf.callHook('load-fixtures', function() {
        return cmbf.server.plugins['covistra-mongodb'].loadFixtures(path.resolve('./test/fixtures'));
    });

    ctx.ObjectId = cmbf.server.plugins['covistra-mongodb'].ObjectId;

    cmbf.test_ctx =P.props(ctx);
    return cmbf.test_ctx;
})

.catch(function(err) {
   cmbf.log.error("Unable to launch CMBF server in test mode", err);
});

@@ -28,65 +28,307 @@
 var 
-requireDirectory = require('require-directory');%0Avar path
+path = require('path');%0Avar P = require('bluebird');%0Avar fs = require('fs');%0Avar _ = require('lodash');%0A%0A// Register all test hooks before launching the test server%0Aif(fs.existsSync(path.resolve('./test/test-server-hooks.js'))) %7B%0A    cmbf.log.info(%22Registering all test server hooks%22);%0A    var hooks
  = r
@@ -338,45 +338,246 @@
 ire(
-'
 path
-');%0Avar P = require('bluebird');
+.resolve('./test/test-server-hooks'));%0A%0A    _.each(_.keys(hooks), function(hookKey) %7B%0A        cmbf.registerHook(hookKey, hooks%5BhookKey%5D);%0A    %7D);%0A%0A    cmbf.log.info(%22All %25d hooks were successfully registered%22, _.keys(hooks).length);%0A%7D
 %0A%0Amo

Add support for external hooks when loading test server