context.js 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. /**
  2. * Expose `Context`.
  3. */
  4. module.exports = Context;
  5. /**
  6. * Initialize a new `Context`.
  7. *
  8. * @api private
  9. */
  10. function Context(){}
  11. /**
  12. * Set or get the context `Runnable` to `runnable`.
  13. *
  14. * @param {Runnable} runnable
  15. * @return {Context}
  16. * @api private
  17. */
  18. Context.prototype.runnable = function(runnable){
  19. if (0 == arguments.length) return this._runnable;
  20. this.test = this._runnable = runnable;
  21. return this;
  22. };
  23. /**
  24. * Set test timeout `ms`.
  25. *
  26. * @param {Number} ms
  27. * @return {Context} self
  28. * @api private
  29. */
  30. Context.prototype.timeout = function(ms){
  31. this.runnable().timeout(ms);
  32. return this;
  33. };
  34. /**
  35. * Set test slowness threshold `ms`.
  36. *
  37. * @param {Number} ms
  38. * @return {Context} self
  39. * @api private
  40. */
  41. Context.prototype.slow = function(ms){
  42. this.runnable().slow(ms);
  43. return this;
  44. };
  45. /**
  46. * Inspect the context void of `._runnable`.
  47. *
  48. * @return {String}
  49. * @api private
  50. */
  51. Context.prototype.inspect = function(){
  52. return JSON.stringify(this, function(key, val){
  53. if ('_runnable' == key) return;
  54. if ('test' == key) return;
  55. return val;
  56. }, 2);
  57. };