This repository has been archived by the owner on Aug 17, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathindex.js
66 lines (54 loc) · 1.6 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
54
55
56
57
58
59
60
61
62
63
64
65
66
'use strict'
// **Github:** https://github.com/thunks/thunk-mocha
//
// **License:** MIT
const thunk = require('thunks')()
module.exports = thunkMocha
// Patch available mocha instances automatically.
findMocha().forEach(thunkMocha)
function thunkMocha (mocha) {
if (!mocha || mocha.Runnable.thunkMochaPatched) return
mocha.Runnable.thunkMochaPatched = true
let runnableProto = mocha.Runnable.prototype
runnableProto._originFn = void 0
Object.defineProperty(runnableProto, 'fn', {
get: function () { return this._fn },
set: function (fn) {
if (typeof fn !== 'function') this._fn = fn
else {
this._fn = function (done) {
thunk.call(this, fn.length ? fn : fn.call(this))(done)
}
}
},
enumerable: true,
configurable: false
})
Object.defineProperty(runnableProto, 'async', {
get: function () { return true },
set: function () {},
enumerable: true,
configurable: false
})
Object.defineProperty(runnableProto, 'sync', {
get: function () { return false },
set: function () {},
enumerable: true,
configurable: false
})
}
function findMocha () {
if (typeof window === 'object' && window.Mocha) return [window.Mocha]
let modules = require.cache || {}
let items = Object.keys(modules)
.filter(function (name) {
// - end of .3.0.2@mocha/index.js for npminstall
// - end of /mocha/index.js for npm
return /[\/\\@]mocha[\/\\]index.js$/.test(name)
})
.map(function (name) {
return modules[name].exports
})
if (items.length === 0) items.push(require('mocha'))
return items
}