lundi 30 mars 2015

Binding nodejs callback result to global variables

I'm trying to simplify my node js functions. I'm writing a nightwatch test and this is how my setup looks like.




test.js



setUp: function(browser, callback) {
var testSetup = function(cb) {
util.createDefaultSetup(cb);
};

var helper = function(res, cb) {
// res is the result object from the util function
default_setup = res.data;
cb();
};

async.waterfall([
testSetup,
helper
], callback);


},




util.js



createDefaultSetup: function(cb) {
console.log('Default Setup');
var args = {};
post(
URL + '/testing/create_sample_setup/',
args,
'Creating ',
'Not able to create ',
cb,
'json');


}


This is a working piece of code. I'm trying to make my test.js simpler without async waterfall. Any recommendations? My ultimate motive of test.js function is to bind the callback result(res) and store it in a global variable.


Aucun commentaire:

Enregistrer un commentaire