1 | var path = require('path');
|
2 | var yaml = require('js-yaml');
|
3 |
|
4 | module.exports.getDiag = function (body) {
|
5 | var yamlStart = body.indexOf(' ---');
|
6 | var yamlEnd = body.indexOf(' ...\n');
|
7 | var diag = body.slice(yamlStart, yamlEnd).split('\n').map(function (line) {
|
8 | return line.slice(2);
|
9 | }).join('\n');
|
10 |
|
11 |
|
12 |
|
13 | var withStack = yaml.safeLoad(diag);
|
14 | delete withStack.stack;
|
15 | delete withStack.at;
|
16 | return withStack;
|
17 | };
|
18 |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 |
|
24 |
|
25 |
|
26 |
|
27 |
|
28 |
|
29 |
|
30 |
|
31 |
|
32 |
|
33 |
|
34 |
|
35 | var stripChangingData = function (line) {
|
36 | var withoutTestDir = line.replace(__dirname, '$TEST');
|
37 | var withoutPackageDir = withoutTestDir.replace(path.dirname(__dirname), '$TAPE');
|
38 | var withoutPathSep = withoutPackageDir.replace(new RegExp('\\' + path.sep, 'g'), '/');
|
39 | var withoutLineNumbers = withoutPathSep.replace(/:\d+:\d+/g, ':$LINE:$COL');
|
40 | var withoutNestedLineNumbers = withoutLineNumbers.replace(/, \<anonymous\>:\$LINE:\$COL\)$/, ')');
|
41 | return withoutNestedLineNumbers;
|
42 | };
|
43 |
|
44 | module.exports.stripFullStack = function (output) {
|
45 | var stripped = ' [... stack stripped ...]';
|
46 | var withDuplicates = output.split('\n').map(stripChangingData).map(function (line) {
|
47 | var m = line.match(/[ ]{8}at .*\((.*)\)/);
|
48 |
|
49 | if (m && m[1].slice(0, 5) !== '$TEST') {
|
50 | return stripped;
|
51 | }
|
52 | return line;
|
53 | });
|
54 |
|
55 | var deduped = withDuplicates.filter(function (line, ix) {
|
56 | var hasPrior = line === stripped && withDuplicates[ix - 1] === stripped;
|
57 | return !hasPrior;
|
58 | });
|
59 |
|
60 | return deduped.join('\n').replace(
|
61 |
|
62 | /at(:?) Test\.(?:module\.exports|tap\.test\.err\.code)/g,
|
63 | 'at$1 Test.<anonymous>'
|
64 | );
|
65 | };
|