f0133e1e5a5ccbe3959cedd6968b2a600a71c180b5960f6cfcf6a224b99c7e88241ef8ed439c76f90c7e191180b9a73feb91e294c6f07fd46c8c2ea1cac3f5 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. /* eslint-disable */
  2. 'use strict';
  3. var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };
  4. var phantom = {};
  5. if (window._phantom) {
  6. console.log = function () {
  7. phantom.sendMessage('console', Array.prototype.slice.apply(arguments).join(', '));
  8. };
  9. }
  10. (function () {
  11. phantom.sendMessage = function () {
  12. var args = [].slice.call(arguments);
  13. var payload = stringify(args);
  14. if (window._phantom) {
  15. alert(payload);
  16. }
  17. };
  18. function PhantomReporter() {
  19. this.started = false;
  20. this.finished = false;
  21. this.suites_ = [];
  22. this.results_ = {};
  23. this.buffer = '';
  24. }
  25. PhantomReporter.prototype.jasmineStarted = function (metadata) {
  26. this.started = true;
  27. phantom.sendMessage('jasmine.jasmineStarted', metadata);
  28. };
  29. PhantomReporter.prototype.specStarted = function (specMetadata) {
  30. specMetadata.startTime = Date.now();
  31. phantom.sendMessage('jasmine.specStarted', specMetadata);
  32. };
  33. PhantomReporter.prototype.suiteStarted = function (suiteMetadata) {
  34. suiteMetadata.startTime = Date.now();
  35. phantom.sendMessage('jasmine.suiteStarted', suiteMetadata);
  36. };
  37. PhantomReporter.prototype.jasmineDone = function () {
  38. this.finished = true;
  39. phantom.sendMessage('jasmine.jasmineDone');
  40. };
  41. PhantomReporter.prototype.suiteDone = function (suiteMetadata) {
  42. suiteMetadata.duration = Date.now() - suiteMetadata.startTime;
  43. phantom.sendMessage('jasmine.suiteDone', suiteMetadata);
  44. };
  45. PhantomReporter.prototype.specDone = function (specMetadata) {
  46. specMetadata.duration = Date.now() - specMetadata.startTime;
  47. this.results_[specMetadata.id] = specMetadata;
  48. phantom.sendMessage('jasmine.specDone', specMetadata);
  49. };
  50. function stringify(obj) {
  51. if ((typeof obj === 'undefined' ? 'undefined' : _typeof(obj)) !== 'object') {
  52. return obj;
  53. }
  54. var cache = [],
  55. keyMap = [];
  56. var string = JSON.stringify(obj, function (key, value) {
  57. // Let json stringify falsy values
  58. if (!value) {
  59. return value;
  60. }
  61. try {
  62. // If we're a node
  63. if (typeof Node !== 'undefined' && value instanceof Node) {
  64. return '[ Node ]';
  65. }
  66. // jasmine-given has expectations on Specs. We intercept to return a
  67. // String to avoid stringifying the entire Jasmine environment, which
  68. // results in exponential string growth
  69. if (value instanceof jasmine.Spec) {
  70. return '[ Spec: ' + value.description + ' ]';
  71. }
  72. // If we're a window (logic stolen from jQuery)
  73. if (value.window && value.window === value.window.window) {
  74. return '[ Window ]';
  75. }
  76. // Simple function reporting
  77. if (typeof value === 'function') {
  78. return '[ Function ]';
  79. }
  80. if ((typeof value === 'undefined' ? 'undefined' : _typeof(value)) === 'object' && value !== null) {
  81. var index = cache.indexOf(value);
  82. if (index !== -1) {
  83. // If we have it in cache, report the circle with the key we first found it in
  84. return '[ Circular {' + (keyMap[index] || 'root') + '} ]';
  85. }
  86. cache.push(value);
  87. keyMap.push(key);
  88. }
  89. } catch (e) {
  90. return '[Object]';
  91. }
  92. return value;
  93. });
  94. return string;
  95. }
  96. jasmine.getEnv().addReporter(new PhantomReporter());
  97. })();