123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263 |
- var path = require('path');
- var yaml = require('js-yaml');
-
- module.exports.getDiag = function (body) {
- var yamlStart = body.indexOf(' ---');
- var yamlEnd = body.indexOf(' ...\n');
- var diag = body.slice(yamlStart, yamlEnd).split('\n').map(function (line) {
- return line.slice(2);
- }).join('\n');
-
-
-
- var withStack = yaml.safeLoad(diag);
- delete withStack.stack;
- delete withStack.at;
- return withStack;
- };
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- module.exports.stripFullStack = function (output) {
- var stripped = ' [... stack stripped ...]';
- var withDuplicates = output.split('\n').map(function (line) {
- var m = line.match(/[ ]{8}at .*\((.*)\)/);
-
- var stripChangingData = function (line) {
- var withoutTestDir = line.replace(__dirname, '$TEST');
- var withoutPackageDir = withoutTestDir.replace(path.dirname(__dirname), '$TAPE');
- var withoutPathSep = withoutPackageDir.replace(new RegExp('\\' + path.sep, 'g'), '/');
- var withoutLineNumbers = withoutPathSep.replace(/:\d+:\d+/g, ':$LINE:$COL');
- var withoutNestedLineNumbers = withoutLineNumbers.replace(/, \<anonymous\>:\$LINE:\$COL\)$/, ')');
- return withoutNestedLineNumbers;
- };
-
- if (m) {
- if (m[1].slice(0, __dirname.length) === __dirname) {
- return stripChangingData(line);
- }
- return stripped;
- }
- return stripChangingData(line);
- });
-
- var deduped = withDuplicates.filter(function (line, ix) {
- var hasPrior = line === stripped && withDuplicates[ix - 1] === stripped;
- return !hasPrior;
- });
-
- return deduped.join('\n');
- };
|