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.
globals.js
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);
}
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment