| 86 | } |
| 87 | |
| 88 | wrapFn(fn) { |
| 89 | const ctx = this; |
| 90 | if (ctx.runningTest) { |
| 91 | expect.fail(null, null, 'calling ctx.test from within a ctx.test is not supported'); |
| 92 | } |
| 93 | |
| 94 | if (fn.length === 0) { |
| 95 | return async function () { |
| 96 | if (ctx.failed) { |
| 97 | this.skip(); |
| 98 | } |
| 99 | ctx.runningTest = true; |
| 100 | fn = fn.bind(this); |
| 101 | try { |
| 102 | await fn(); |
| 103 | } catch (ex) { |
| 104 | ctx.failed = true; |
| 105 | throw ex; |
| 106 | } finally { |
| 107 | ctx.runningTest = false; |
| 108 | } |
| 109 | }; |
| 110 | } |
| 111 | return function (done) { |
| 112 | if (ctx.failed) { |
| 113 | this.skip(); |
| 114 | } |
| 115 | ctx.runningTest = true; |
| 116 | fn = fn.bind(this); |
| 117 | try { |
| 118 | this.runningTest = false; |
| 119 | fn(done); |
| 120 | } catch (ex) { |
| 121 | ctx.failed = true; |
| 122 | throw ex; |
| 123 | } finally { |
| 124 | ctx.runningTest = false; |
| 125 | } |
| 126 | }; |
| 127 | } |
| 128 | |
| 129 | // test is a wrapper around "it" that skips the test if a previous one in |
| 130 | // the same context failed already. |