web 3d图形渲染器
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

177 lines
4.6 KiB

  1. 'use strict';
  2. Object.defineProperty(exports, '__esModule', {
  3. value: true
  4. });
  5. exports.default = void 0;
  6. var _testResult = require('@jest/test-result');
  7. var _jestMessageUtil = require('jest-message-util');
  8. var Symbol = global['jest-symbol-do-not-touch'] || global.Symbol;
  9. var Symbol = global['jest-symbol-do-not-touch'] || global.Symbol;
  10. var jestNow = global[Symbol.for('jest-native-now')] || global.Date.now;
  11. var Symbol = global['jest-symbol-do-not-touch'] || global.Symbol;
  12. var Promise = global[Symbol.for('jest-native-promise')] || global.Promise;
  13. function _defineProperty(obj, key, value) {
  14. if (key in obj) {
  15. Object.defineProperty(obj, key, {
  16. value: value,
  17. enumerable: true,
  18. configurable: true,
  19. writable: true
  20. });
  21. } else {
  22. obj[key] = value;
  23. }
  24. return obj;
  25. }
  26. class Jasmine2Reporter {
  27. constructor(globalConfig, config, testPath) {
  28. _defineProperty(this, '_testResults', void 0);
  29. _defineProperty(this, '_globalConfig', void 0);
  30. _defineProperty(this, '_config', void 0);
  31. _defineProperty(this, '_currentSuites', void 0);
  32. _defineProperty(this, '_resolve', void 0);
  33. _defineProperty(this, '_resultsPromise', void 0);
  34. _defineProperty(this, '_startTimes', void 0);
  35. _defineProperty(this, '_testPath', void 0);
  36. this._globalConfig = globalConfig;
  37. this._config = config;
  38. this._testPath = testPath;
  39. this._testResults = [];
  40. this._currentSuites = [];
  41. this._resolve = null;
  42. this._resultsPromise = new Promise(resolve => (this._resolve = resolve));
  43. this._startTimes = new Map();
  44. }
  45. jasmineStarted(_runDetails) {}
  46. specStarted(spec) {
  47. this._startTimes.set(spec.id, jestNow());
  48. }
  49. specDone(result) {
  50. this._testResults.push(
  51. this._extractSpecResults(result, this._currentSuites.slice(0))
  52. );
  53. }
  54. suiteStarted(suite) {
  55. this._currentSuites.push(suite.description);
  56. }
  57. suiteDone(_result) {
  58. this._currentSuites.pop();
  59. }
  60. jasmineDone(_runDetails) {
  61. let numFailingTests = 0;
  62. let numPassingTests = 0;
  63. let numPendingTests = 0;
  64. let numTodoTests = 0;
  65. const testResults = this._testResults;
  66. testResults.forEach(testResult => {
  67. if (testResult.status === 'failed') {
  68. numFailingTests++;
  69. } else if (testResult.status === 'pending') {
  70. numPendingTests++;
  71. } else if (testResult.status === 'todo') {
  72. numTodoTests++;
  73. } else {
  74. numPassingTests++;
  75. }
  76. });
  77. const testResult = {
  78. ...(0, _testResult.createEmptyTestResult)(),
  79. console: null,
  80. failureMessage: (0, _jestMessageUtil.formatResultsErrors)(
  81. testResults,
  82. this._config,
  83. this._globalConfig,
  84. this._testPath
  85. ),
  86. numFailingTests,
  87. numPassingTests,
  88. numPendingTests,
  89. numTodoTests,
  90. snapshot: {
  91. added: 0,
  92. fileDeleted: false,
  93. matched: 0,
  94. unchecked: 0,
  95. unmatched: 0,
  96. updated: 0
  97. },
  98. testFilePath: this._testPath,
  99. testResults
  100. };
  101. this._resolve(testResult);
  102. }
  103. getResults() {
  104. return this._resultsPromise;
  105. }
  106. _addMissingMessageToStack(stack, message) {
  107. // Some errors (e.g. Angular injection error) don't prepend error.message
  108. // to stack, instead the first line of the stack is just plain 'Error'
  109. const ERROR_REGEX = /^Error:?\s*\n/;
  110. if (stack && message && !stack.includes(message)) {
  111. return message + stack.replace(ERROR_REGEX, '\n');
  112. }
  113. return stack;
  114. }
  115. _extractSpecResults(specResult, ancestorTitles) {
  116. const start = this._startTimes.get(specResult.id);
  117. const duration = start ? jestNow() - start : undefined;
  118. const status =
  119. specResult.status === 'disabled' ? 'pending' : specResult.status;
  120. const location = specResult.__callsite
  121. ? {
  122. column: specResult.__callsite.getColumnNumber(),
  123. line: specResult.__callsite.getLineNumber()
  124. }
  125. : null;
  126. const results = {
  127. ancestorTitles,
  128. duration,
  129. failureDetails: [],
  130. failureMessages: [],
  131. fullName: specResult.fullName,
  132. location,
  133. numPassingAsserts: 0,
  134. // Jasmine2 only returns an array of failed asserts.
  135. status,
  136. title: specResult.description
  137. };
  138. specResult.failedExpectations.forEach(failed => {
  139. const message =
  140. !failed.matcherName && typeof failed.stack === 'string'
  141. ? this._addMissingMessageToStack(failed.stack, failed.message)
  142. : failed.message || '';
  143. results.failureMessages.push(message);
  144. results.failureDetails.push(failed);
  145. });
  146. return results;
  147. }
  148. }
  149. exports.default = Jasmine2Reporter;