forked from DevExpress/testcafe
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstack-cleaning-hook.js
More file actions
35 lines (28 loc) · 925 Bytes
/
stack-cleaning-hook.js
File metadata and controls
35 lines (28 loc) · 925 Bytes
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
import stackTrace from 'stack-chain';
import createStackFilter from './create-stack-filter';
const ORIGINAL_STACK_TRACE_LIMIT = Error.stackTraceLimit;
const STACK_TRACE_LIMIT = 200;
export default {
isEnabled: false,
_hook (err, frames) {
return frames.filter(createStackFilter(ORIGINAL_STACK_TRACE_LIMIT));
},
get enabled () {
return this.isEnabled;
},
set enabled (val) {
if (this.isEnabled === val)
return;
this.isEnabled = val;
if (this.isEnabled) {
// NOTE: Babel errors may have really deep stacks,
// so we increase stack trace capacity
Error.stackTraceLimit = STACK_TRACE_LIMIT;
stackTrace.filter.attach(this._hook);
}
else {
Error.stackTraceLimit = ORIGINAL_STACK_TRACE_LIMIT;
stackTrace.filter.deattach(this._hook);
}
}
};