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