| 90 | }; |
| 91 | |
| 92 | function _mustCallInner (fn, criteria, field) { |
| 93 | if (typeof fn === 'number') { |
| 94 | criteria = fn; |
| 95 | fn = noop; |
| 96 | } else if (fn === undefined) { |
| 97 | fn = noop; |
| 98 | } |
| 99 | if (criteria === undefined) { |
| 100 | criteria = 1; |
| 101 | } |
| 102 | |
| 103 | if (typeof criteria !== 'number') { throw new TypeError(`Invalid ${field} value: ${criteria}`); } |
| 104 | |
| 105 | const context = { |
| 106 | [field]: criteria, |
| 107 | actual: 0, |
| 108 | stack: (new Error()).stack, |
| 109 | name: fn.name || '<anonymous>' |
| 110 | }; |
| 111 | |
| 112 | // add the exit listener only once to avoid listener leak warnings |
| 113 | if (mustCallChecks.length === 0) process.on('exit', runCallChecks); |
| 114 | |
| 115 | mustCallChecks.push(context); |
| 116 | |
| 117 | return function () { |
| 118 | context.actual++; |
| 119 | return fn.apply(this, arguments); |
| 120 | }; |
| 121 | } |
| 122 | |
| 123 | exports.mustNotCall = function (msg) { |
| 124 | return function mustNotCall () { |