UNPKG

1.33 kBJavaScriptView Raw
1'use strict';
2const mochaMod = require('mocha');
3const internal = [
4 '(timers.js:',
5 '(node.js:',
6 '(module.js:',
7 '(domain.js:',
8 'GeneratorFunctionPrototype.next (native)',
9 'at Generator.next',
10 /at process\._tickDomainCallback \(.*\)/,
11 /at emitCloseNT \(net\.js.*\)/,
12 /at _combinedTickCallback \(internal.*\)/,
13 // node 8.x
14 'at Promise (<anonymous>)',
15 'at next (native)',
16 '__mocha_internal__',
17 /node_modules\/.*empower-core\//,
18 /node_modules\/.*mocha\//,
19 /node_modules\/.*co\//,
20 /node_modules\/.*co-mocha\//,
21 /node_modules\/.*supertest\//,
22];
23// monkey-patch `Runner#fail` to modify stack
24const originFn = mochaMod.Runner.prototype.fail;
25mochaMod.Runner.prototype.fail = function (test, err) {
26 /* istanbul ignore else */
27 if (err.stack) {
28 const stack = err.stack.split('\n').filter(line => {
29 line = line.replace(/\\\\?/g, '/');
30 return !internal.some(rule => match(line, rule));
31 });
32 stack.push(' [use `--full-trace` to display the full stack trace]');
33 err.stack = stack.join('\n');
34 }
35 return originFn.call(this, test, err);
36};
37function match(line, rule) {
38 if (rule instanceof RegExp)
39 return rule.test(line);
40 return line.includes(rule);
41}
42//# sourceMappingURL=mocha-clean.js.map
\No newline at end of file