Add Utils to global.Cylon namespace, add bootstrap
This commit moves Utils to live in the global Cylon namespace, so they can be accessed in test suites. This is necessary because Mocha, when setting up for tests, will override our #after method, making TDR not work if any robots contain a #after call in their work block. To fix this, in test setup you can call global.Cylon.Utils.bootstrap(); which will re-setup our globals.
This commit is contained in:
parent
2563e62de4
commit
1cffa6067e
31
lib/utils.js
31
lib/utils.js
|
@ -77,7 +77,10 @@ Number.prototype.toScale = function(start, end) {
|
|||
}
|
||||
};
|
||||
|
||||
var Utils = {
|
||||
var namespace = require('node-namespace');
|
||||
|
||||
namespace('Cylon', function() {
|
||||
this.Utils = {
|
||||
// Public: Alias to setInterval, combined with Number monkeypatches below to
|
||||
// create an artoo-like syntax.
|
||||
//
|
||||
|
@ -228,10 +231,28 @@ var Utils = {
|
|||
// Returns a function wrapper
|
||||
bind: function(fn, me) {
|
||||
return function() { return fn.apply(me, arguments); };
|
||||
},
|
||||
|
||||
// Public: Adds all methods from Cylon.Utils directly to the global
|
||||
// namespace.
|
||||
//
|
||||
// Examples
|
||||
//
|
||||
// Cylon.Utils.bootstrap();
|
||||
// (after === Cylon.Utils.After) // true
|
||||
//
|
||||
// Returns Cylon.Utils
|
||||
bootstrap: function() {
|
||||
for (util in this) {
|
||||
// we're not going to attach the 'bootstrap' method
|
||||
if (!(util === "bootstrap")) {
|
||||
global[util] = this[util];
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// Add all utility functions to global namespace
|
||||
for (var util in Utils) { global[util] = Utils[util]; }
|
||||
return this;
|
||||
}
|
||||
};
|
||||
});
|
||||
|
||||
module.exports = Utils;
|
||||
module.exports = Cylon.Utils.bootstrap();
|
||||
|
|
Loading…
Reference in New Issue