1 | 'use strict';
|
2 | const mochaMod = require('mocha');
|
3 | const 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 |
|
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 |
|
24 | const originFn = mochaMod.Runner.prototype.fail;
|
25 | mochaMod.Runner.prototype.fail = function (test, err) {
|
26 |
|
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 | };
|
37 | function match(line, rule) {
|
38 | if (rule instanceof RegExp)
|
39 | return rule.test(line);
|
40 | return line.includes(rule);
|
41 | }
|
42 |
|
\ | No newline at end of file |