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 | module.exports.stripFullStack = function (output) {
|
35 | var stripped = ' [... stack stripped ...]';
|
36 | var withDuplicates = output.split('\n').map(function (line) {
|
37 | var m = line.match(/[ ]{8}at .*\((.*)\)/);
|
38 |
|
39 | var stripChangingData = function (line) {
|
40 | var withoutTestDir = line.replace(__dirname, '$TEST');
|
41 | var withoutPackageDir = withoutTestDir.replace(path.dirname(__dirname), '$TAPE');
|
42 | var withoutPathSep = withoutPackageDir.replace(new RegExp('\\' + path.sep, 'g'), '/');
|
43 | var withoutLineNumbers = withoutPathSep.replace(/:\d+:\d+/g, ':$LINE:$COL');
|
44 | var withoutNestedLineNumbers = withoutLineNumbers.replace(/, \<anonymous\>:\$LINE:\$COL\)$/, ')');
|
45 | return withoutNestedLineNumbers;
|
46 | }
|
47 |
|
48 | if (m) {
|
49 | if (m[1].slice(0, __dirname.length) === __dirname) {
|
50 | return stripChangingData(line);
|
51 | }
|
52 | return stripped;
|
53 | }
|
54 | return stripChangingData(line);
|
55 | })
|
56 |
|
57 | var deduped = withDuplicates.filter(function (line, ix) {
|
58 | var hasPrior = line === stripped && withDuplicates[ix - 1] === stripped;
|
59 | return !hasPrior;
|
60 | });
|
61 |
|
62 | return deduped.join('\n');
|
63 | }
|