-
-
Notifications
You must be signed in to change notification settings - Fork 269
/
root.js
104 lines (88 loc) · 2.23 KB
/
root.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
var Test = require('./test.js')
var tap = new Test()
module.exports = tap
if (tap._timer && tap._timer.unref) {
tap._timer.unref()
}
tap._name = 'TAP'
// No sense continuing after bailout!
tap.on('bailout', function () {
process.exit(1)
})
process.on('exit', function (code) {
tap.endAll()
if (!tap._ok && code === 0) {
process.exit(1)
}
})
// need to autoend if a teardown is added.
// otherwise we may never see process.on('exit')!
tap.tearDown = function (fn) {
var ret = Test.prototype.tearDown.apply(tap, arguments)
tap.autoend()
return ret
}
tap.pipe(process.stdout)
tap.mocha = require('./mocha.js')
tap.mochaGlobals = tap.mocha.global
tap.Test = Test
tap.synonyms = require('./synonyms.js')
process.on('uncaughtException', onUncaught)
function onUncaught (er) {
var child = tap
while (child._currentChild && child._currentChild instanceof Test) {
child = child._currentChild
}
child.threw(er)
}
tap.on('end', function () {
process.removeListener('uncaughtException', onUncaught)
})
// SIGTERM means being forcibly killed, almost always by timeout
var onExit = require('signal-exit')
onExit(function (code, signal) {
if (signal !== 'SIGTERM') {
return
}
var handles = process._getActiveHandles().filter(function (h) {
return h !== process.stdout &&
h !== process.stdin &&
h !== process.stderr
})
var requests = process._getActiveRequests()
// Ignore this because it's really hard to test cover in a way
// that isn't inconsistent and unpredictable.
/* istanbul ignore next */
var extra = {
at: null,
signal: signal
}
if (requests.length) {
extra.requests = requests.map(function (r) {
var ret = { type: r.constructor.name }
if (r.context) {
ret.context = r.context
}
return ret
})
}
if (handles.length) {
extra.handles = handles.map(function (h) {
var ret = { type: h.constructor.name }
if (h.msecs) {
ret.msecs = h.msecs
}
if (h._events) {
ret.events = Object.keys(h._events)
}
if (h._sockname) {
ret.sockname = h._sockname
}
if (h._connectionKey) {
ret.connectionKey = h._connectionKey
}
return ret
})
}
tap._onTimeout(extra)
})