UNPKG

1.74 kBJavaScriptView Raw
1'use strict';
2/**
3 * @module Context
4 */
5/**
6 * Expose `Context`.
7 */
8
9module.exports = Context;
10
11/**
12 * Initialize a new `Context`.
13 *
14 * @private
15 */
16function Context() {}
17
18/**
19 * Set or get the context `Runnable` to `runnable`.
20 *
21 * @private
22 * @param {Runnable} runnable
23 * @return {Context} context
24 */
25Context.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/**
34 * Set or get test timeout `ms`.
35 *
36 * @private
37 * @param {number} ms
38 * @return {Context} self
39 */
40Context.prototype.timeout = function(ms) {
41 if (!arguments.length) {
42 return this.runnable().timeout();
43 }
44 this.runnable().timeout(ms);
45 return this;
46};
47
48/**
49 * Set test timeout `enabled`.
50 *
51 * @private
52 * @param {boolean} enabled
53 * @return {Context} self
54 */
55Context.prototype.enableTimeouts = function(enabled) {
56 if (!arguments.length) {
57 return this.runnable().enableTimeouts();
58 }
59 this.runnable().enableTimeouts(enabled);
60 return this;
61};
62
63/**
64 * Set or get test slowness threshold `ms`.
65 *
66 * @private
67 * @param {number} ms
68 * @return {Context} self
69 */
70Context.prototype.slow = function(ms) {
71 if (!arguments.length) {
72 return this.runnable().slow();
73 }
74 this.runnable().slow(ms);
75 return this;
76};
77
78/**
79 * Mark a test as skipped.
80 *
81 * @private
82 * @throws Pending
83 */
84Context.prototype.skip = function() {
85 this.runnable().skip();
86};
87
88/**
89 * Set or get a number of allowed retries on failed tests
90 *
91 * @private
92 * @param {number} n
93 * @return {Context} self
94 */
95Context.prototype.retries = function(n) {
96 if (!arguments.length) {
97 return this.runnable().retries();
98 }
99 this.runnable().retries(n);
100 return this;
101};