96 lines
1.5 KiB
JavaScript
96 lines
1.5 KiB
JavaScript
|
/**
|
||
|
* Expose `Context`.
|
||
|
*/
|
||
|
|
||
|
module.exports = Context;
|
||
|
|
||
|
/**
|
||
|
* Initialize a new `Context`.
|
||
|
*
|
||
|
* @api private
|
||
|
*/
|
||
|
|
||
|
function Context(){}
|
||
|
|
||
|
/**
|
||
|
* Set or get the context `Runnable` to `runnable`.
|
||
|
*
|
||
|
* @param {Runnable} runnable
|
||
|
* @return {Context}
|
||
|
* @api private
|
||
|
*/
|
||
|
|
||
|
Context.prototype.runnable = function(runnable){
|
||
|
if (0 == arguments.length) return this._runnable;
|
||
|
this.test = this._runnable = runnable;
|
||
|
return this;
|
||
|
};
|
||
|
|
||
|
/**
|
||
|
* Set test timeout `ms`.
|
||
|
*
|
||
|
* @param {Number} ms
|
||
|
* @return {Context} self
|
||
|
* @api private
|
||
|
*/
|
||
|
|
||
|
Context.prototype.timeout = function(ms){
|
||
|
if (arguments.length === 0) return this.runnable().timeout();
|
||
|
this.runnable().timeout(ms);
|
||
|
return this;
|
||
|
};
|
||
|
|
||
|
/**
|
||
|
* Set test timeout `enabled`.
|
||
|
*
|
||
|
* @param {Boolean} enabled
|
||
|
* @return {Context} self
|
||
|
* @api private
|
||
|
*/
|
||
|
|
||
|
Context.prototype.enableTimeouts = function (enabled) {
|
||
|
this.runnable().enableTimeouts(enabled);
|
||
|
return this;
|
||
|
};
|
||
|
|
||
|
|
||
|
/**
|
||
|
* Set test slowness threshold `ms`.
|
||
|
*
|
||
|
* @param {Number} ms
|
||
|
* @return {Context} self
|
||
|
* @api private
|
||
|
*/
|
||
|
|
||
|
Context.prototype.slow = function(ms){
|
||
|
this.runnable().slow(ms);
|
||
|
return this;
|
||
|
};
|
||
|
|
||
|
/**
|
||
|
* Mark a test as skipped.
|
||
|
*
|
||
|
* @return {Context} self
|
||
|
* @api private
|
||
|
*/
|
||
|
|
||
|
Context.prototype.skip = function(){
|
||
|
this.runnable().skip();
|
||
|
return this;
|
||
|
};
|
||
|
|
||
|
/**
|
||
|
* Inspect the context void of `._runnable`.
|
||
|
*
|
||
|
* @return {String}
|
||
|
* @api private
|
||
|
*/
|
||
|
|
||
|
Context.prototype.inspect = function(){
|
||
|
return JSON.stringify(this, function(key, val){
|
||
|
if ('_runnable' == key) return;
|
||
|
if ('test' == key) return;
|
||
|
return val;
|
||
|
}, 2);
|
||
|
};
|