context.js 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. 'use strict';
  2. /**
  3. * @typedef {import('./runnable.js')} Runnable
  4. */
  5. /**
  6. * @module Context
  7. */
  8. /**
  9. * Expose `Context`.
  10. */
  11. module.exports = Context;
  12. /**
  13. * Initialize a new `Context`.
  14. *
  15. * @private
  16. */
  17. function Context() {}
  18. /**
  19. * Set or get the context `Runnable` to `runnable`.
  20. *
  21. * @private
  22. * @param {Runnable} runnable
  23. * @return {Context} context
  24. */
  25. Context.prototype.runnable = function (runnable) {
  26. if (!arguments.length) {
  27. return this._runnable;
  28. }
  29. this.test = this._runnable = runnable;
  30. return this;
  31. };
  32. /**
  33. * Set or get test timeout `ms`.
  34. *
  35. * @private
  36. * @param {number} ms
  37. * @return {Context} self
  38. */
  39. Context.prototype.timeout = function (ms) {
  40. if (!arguments.length) {
  41. return this.runnable().timeout();
  42. }
  43. this.runnable().timeout(ms);
  44. return this;
  45. };
  46. /**
  47. * Set or get test slowness threshold `ms`.
  48. *
  49. * @private
  50. * @param {number} ms
  51. * @return {Context} self
  52. */
  53. Context.prototype.slow = function (ms) {
  54. if (!arguments.length) {
  55. return this.runnable().slow();
  56. }
  57. this.runnable().slow(ms);
  58. return this;
  59. };
  60. /**
  61. * Mark a test as skipped.
  62. *
  63. * @private
  64. * @throws Pending
  65. */
  66. Context.prototype.skip = function () {
  67. this.runnable().skip();
  68. };
  69. /**
  70. * Set or get a number of allowed retries on failed tests
  71. *
  72. * @private
  73. * @param {number} n
  74. * @return {Context} self
  75. */
  76. Context.prototype.retries = function (n) {
  77. if (!arguments.length) {
  78. return this.runnable().retries();
  79. }
  80. this.runnable().retries(n);
  81. return this;
  82. };