-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
53 lines (46 loc) · 1.13 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
var mute = require("mute");
function isPromise(value) {
return typeof value === 'object' && typeof value.then === 'function';
}
function muteit(name, fn) {
if (fn.length) {
it(name, function (done) {
var unmute = mute();
function wrappedDone() {
unmute();
done();
}
fn.call(this, wrappedDone);
});
} else {
it(name, function () {
var unmute = mute();
var out = fn.call(this);
if (isPromise(out)) {
return mutePromise(out);
} else {
unmute();
}
})
}
}
function mutePromise(promise) {
return new Promise(function (resolve, reject) {
var unmute = mute();
promise.then(function (r) {
unmute();
resolve(r);
}).catch(function (e) {
unmute();
reject(e);
})
})
}
function muteFunction(action) {
var unmute = mute();
action();
unmute();
}
module.exports = muteFunction;
module.exports.it = muteit;
module.exports.promise = mutePromise;