Repositorio del curso CCOM4030 el semestre B91 del proyecto Paz para la Mujer

common.js 2.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. var path = require('path');
  2. var yaml = require('js-yaml');
  3. module.exports.getDiag = function (body) {
  4. var yamlStart = body.indexOf(' ---');
  5. var yamlEnd = body.indexOf(' ...\n');
  6. var diag = body.slice(yamlStart, yamlEnd).split('\n').map(function (line) {
  7. return line.slice(2);
  8. }).join('\n');
  9. // The stack trace and at variable will vary depending on where the code
  10. // is run, so just strip it out.
  11. var withStack = yaml.safeLoad(diag);
  12. delete withStack.stack;
  13. delete withStack.at;
  14. return withStack;
  15. };
  16. // There are three challenges associated with checking the stack traces included
  17. // in errors:
  18. // 1) The base checkout directory of tape might change. Because stack traces
  19. // include absolute paths, the stack traces will change depending on the
  20. // checkout path. We handle this by replacing the base test directory with a
  21. // placeholder $TEST variable and the package root with a placehodler
  22. // $TAPE variable.
  23. // 2) Line positions within the file might change. We handle this by replacing
  24. // line and column markers with placeholder $LINE and $COL "variables"
  25. // a) node 0.8 does not provide nested eval line numbers, so we remove them
  26. // 3) Stacks themselves change frequently with refactoring. We've even run into
  27. // issues with node library refactorings "breaking" stack traces. Most of
  28. // these changes are irrelevant to the tests themselves. To counter this, we
  29. // strip out all stack frames that aren't directly under our test directory,
  30. // and replace them with placeholders.
  31. module.exports.stripFullStack = function (output) {
  32. var stripped = ' [... stack stripped ...]';
  33. var withDuplicates = output.split('\n').map(function (line) {
  34. var m = line.match(/[ ]{8}at .*\((.*)\)/);
  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. if (m) {
  44. if (m[1].slice(0, __dirname.length) === __dirname) {
  45. return stripChangingData(line);
  46. }
  47. return stripped;
  48. }
  49. return stripChangingData(line);
  50. });
  51. var deduped = withDuplicates.filter(function (line, ix) {
  52. var hasPrior = line === stripped && withDuplicates[ix - 1] === stripped;
  53. return !hasPrior;
  54. });
  55. return deduped.join('\n');
  56. };