PageRenderTime 25ms CodeModel.GetById 12ms RepoModel.GetById 0ms app.codeStats 0ms

/lib/guard/jasmine/phantomjs/lib/result.js

https://github.com/eventualbuddha/guard-jasmine
JavaScript | 128 lines | 118 code | 10 blank | 0 comment | 29 complexity | d496ddad4dfc0730dfe5472c46c9c0bb MD5 | raw file
  1. (function() {
  2. var Result;
  3. Result = (function() {
  4. function Result(result, logs, errors, options) {
  5. this.result = result;
  6. this.logs = logs != null ? logs : {};
  7. this.errors = errors != null ? errors : {};
  8. this.options = options != null ? options : {};
  9. }
  10. Result.prototype.addLogs = function(suite) {
  11. var id, s, spec;
  12. suite.suites = (function() {
  13. var _i, _len, _ref, _results;
  14. _ref = suite.suites;
  15. _results = [];
  16. for (_i = 0, _len = _ref.length; _i < _len; _i++) {
  17. s = _ref[_i];
  18. _results.push(this.addLogs(s));
  19. }
  20. return _results;
  21. }).call(this);
  22. if (suite.specs) {
  23. suite.specs = (function() {
  24. var _i, _len, _ref, _results;
  25. _ref = suite.specs;
  26. _results = [];
  27. for (_i = 0, _len = _ref.length; _i < _len; _i++) {
  28. spec = _ref[_i];
  29. if (this.options.console === 'always' || (this.options.console === 'failure' && !spec.passed)) {
  30. id = Number(spec['id']);
  31. if (this.logs[id] && this.logs[id].length !== 0) {
  32. spec.logs = this.logs[id];
  33. }
  34. }
  35. _results.push(spec);
  36. }
  37. return _results;
  38. }).call(this);
  39. }
  40. return suite;
  41. };
  42. Result.prototype.addErrors = function(suite) {
  43. var id, s, spec;
  44. suite.suites = (function() {
  45. var _i, _len, _ref, _results;
  46. _ref = suite.suites;
  47. _results = [];
  48. for (_i = 0, _len = _ref.length; _i < _len; _i++) {
  49. s = _ref[_i];
  50. _results.push(this.addErrors(s));
  51. }
  52. return _results;
  53. }).call(this);
  54. if (suite.specs) {
  55. suite.specs = (function() {
  56. var _i, _len, _ref, _results;
  57. _ref = suite.specs;
  58. _results = [];
  59. for (_i = 0, _len = _ref.length; _i < _len; _i++) {
  60. spec = _ref[_i];
  61. if (this.options.errors === 'always' || (this.options.errors === 'failure' && !spec.passed)) {
  62. id = Number(spec['id']);
  63. if (this.errors[id] && this.errors[id].length !== 0) {
  64. spec.errors = this.errors[id];
  65. }
  66. }
  67. _results.push(spec);
  68. }
  69. return _results;
  70. }).call(this);
  71. }
  72. return suite;
  73. };
  74. Result.prototype.cleanResult = function(suite) {
  75. var s, spec, _i, _len, _ref;
  76. suite.suites = (function() {
  77. var _i, _len, _ref, _results;
  78. _ref = suite.suites;
  79. _results = [];
  80. for (_i = 0, _len = _ref.length; _i < _len; _i++) {
  81. s = _ref[_i];
  82. _results.push(this.cleanResult(s));
  83. }
  84. return _results;
  85. }).call(this);
  86. if (suite.specs) {
  87. _ref = suite.specs;
  88. for (_i = 0, _len = _ref.length; _i < _len; _i++) {
  89. spec = _ref[_i];
  90. delete spec['id'];
  91. }
  92. }
  93. delete suite['id'];
  94. delete suite['parent'];
  95. return suite;
  96. };
  97. Result.prototype.process = function() {
  98. if (this.options.console !== 'never') {
  99. this.addLogs(this.result);
  100. }
  101. if (this.options.errors !== 'never') {
  102. this.addErrors(this.result);
  103. }
  104. this.cleanResult(this.result);
  105. return this.result;
  106. };
  107. return Result;
  108. })();
  109. if (typeof module !== 'undefined' && module.exports) {
  110. if (module) {
  111. module.exports = Result;
  112. }
  113. } else {
  114. if (window) {
  115. window.Result = Result;
  116. }
  117. }
  118. }).call(this);