Skip to content

Instantly share code, notes, and snippets.

@beatfactor
Created September 8, 2015 20:26
Show Gist options
  • Save beatfactor/7115c2f0e5c0916b4618 to your computer and use it in GitHub Desktop.
Save beatfactor/7115c2f0e5c0916b4618 to your computer and use it in GitHub Desktop.

Revisions

  1. beatfactor renamed this gist Sep 8, 2015. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  2. beatfactor created this gist Sep 8, 2015.
    73 changes: 73 additions & 0 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,73 @@
    module.exports = {
    groupGlobals : null,

    checkGroupGlobals : function(hookName) {
    if (hookName && this.groupGlobals) {
    return this.groupGlobals[hookName];
    }

    if (this.test_settings.group_name) {
    try {
    this.groupGlobals = require('../globals/' + this.test_settings.group_name.toLowerCase() + '.js');
    if (hookName) {
    return this.groupGlobals[hookName];
    }
    } catch (err) {
    return false;
    }
    }
    return false;
    },

    endSession : function(client, done) {
    if (client.sessionId) {
    client.end(function() {
    done();
    });
    } else {
    done();
    }
    },

    before: function (done) {
    var beforeGroup = this.checkGroupGlobals('before');

    if (beforeGroup) {
    beforeGroup.call(this, done);
    } else {
    done();
    }
    },

    after: function (done) {
    var afterGroup = this.checkGroupGlobals('before');

    if (afterGroup) {
    afterGroup.call(this, done);
    } else {
    done();
    }
    },

    beforeEach: function (client, done) {
    var beforeGroupEach = this.checkGroupGlobals('beforeEach');

    if (beforeGroupEach) {
    beforeGroupEach.call(this, client, done);
    } else {
    done();
    }
    },

    afterEach : function (client, done) {
    var afterGroupEach = this.checkGroupGlobals('afterEach');

    if (afterGroupEach) {
    afterGroupEach.call(this, client, function() {
    this.endSession(client, done);
    }.bind(this));
    } else {
    this.endSession(client, done);
    }
    }
    };