lib/runner/runMocha.js
function prepareContext(screenstoryRunner, options, context, file, mochaRunner) {
    debug('prepare context for %s', file);
    var wdOptions = {
                desiredCapabilities: options.wdCapabilities,
                host: options.wdHost,
                port: options.wdPort,
                user: options.wdUsername,
                key: options.wdKey,
                logLevel: options.wdLogLevel
            };

    context.url = options.url;

    // @return webdriverio
    context.newClient = function () {
        // init client
        var client = webdriverio.remote(wdOptions)
            .init();

        // fix resolution
        if (options.resolution) {
            client
                .setViewportSize(options.resolution, true);
        }

        // add extensions
        screenstoryRunner.extensions.forEach(function (extension) {
            Object.keys(extension).forEach(function (key) {
                debug('+  Add command "%s"', key);
                client.addCommand(key, extension[key]);
            });
        });
        screenstoryRunner.emitAsync('new client', client, function (err) {
            if (err) {
                debug('While executing "new client" event, following error occured');
                debug(err);
                console.log(err);
            }
        });

        return client;
    };

    // add globals
    options.global.forEach(function (globalName) {
        addGlobal(context, globalName);
    });
}
function prepareContext(screenstoryRunner, options, context, file, mochaRunner) {
    debug('prepare context for %s', file);
    var wdOptions = {
                desiredCapabilities: options.wdCapabilities,
                host: options.wdHost,
                port: options.wdPort,
                user: options.wdUsername,
                key: options.wdKey,
                logLevel: options.wdLogLevel
            };

    context.url = options.url;

    // @return webdriverio
    context.newClient = function () {
        // init client
        var client = webdriverio.remote(wdOptions)
            .init();

        // fix resolution
        if (options.resolution) {
            client
                .setViewportSize(options.resolution, true);
        }

        // add extensions
        screenstoryRunner.extensions.forEach(function (extension) {
            Object.keys(extension).forEach(function (key) {
                debug('+  Add command "%s"', key);
                client.addCommand(key, extension[key]);
            });
        });
        screenstoryRunner.emitAsync('new client', client, function (err) {
            if (err) {
                debug('While executing "new client" event, following error occured');
                debug(err);
                console.log(err);
            }
        });

        return client;
    };

    // add globals
    options.global.forEach(function (globalName) {
        addGlobal(context, globalName);
    });
}
function prepareContext ( screenstoryRunner , options , context , file , mochaRunner ) { debug ( 'prepare context for %s' , file ) ; var wdOptions = { desiredCapabilities : options . wdCapabilities , host : options . wdHost , port : options . wdPort , user : options . wdUsername , key : options . wdKey , logLevel : options . wdLogLevel } ; context . url = options . url ; // @return webdriverio context . newClient = function ( ) { // init client var client = webdriverio . remote ( wdOptions ) . init ( ) ; // fix resolution if ( options . resolution ) { client . setViewportSize ( options . resolution , true ) ; } // add extensions screenstoryRunner . extensions . forEach ( function ( extension ) { Object . keys ( extension ) . forEach ( function ( key ) { debug ( '+  Add command "%s"' , key ) ; client . addCommand ( key , extension [ key ] ) ; } ) ; } ) ; screenstoryRunner . emitAsync ( 'new client' , client , function ( err ) { if ( err ) { debug ( 'While executing "new client" event, following error occured' ) ; debug ( err ) ; console . log ( err ) ; } } ) ; return client ; } ; // add globals options . global . forEach ( function ( globalName ) { addGlobal ( context , globalName ) ; } ) ; }
prepare context before given file runs  see mocha runner `pre-require` event
prepare context before given file runs see mocha runner pre - require event