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.

272 lines
6.9 KiB

  1. 'use strict';
  2. Object.defineProperty(exports, '__esModule', {
  3. value: true
  4. });
  5. exports.default = void 0;
  6. function _chalk() {
  7. const data = _interopRequireDefault(require('chalk'));
  8. _chalk = function () {
  9. return data;
  10. };
  11. return data;
  12. }
  13. function _jestUtil() {
  14. const data = require('jest-util');
  15. _jestUtil = function () {
  16. return data;
  17. };
  18. return data;
  19. }
  20. var _BaseReporter = _interopRequireDefault(require('./BaseReporter'));
  21. var _getResultHeader = _interopRequireDefault(require('./getResultHeader'));
  22. var _getSnapshotSummary = _interopRequireDefault(
  23. require('./getSnapshotSummary')
  24. );
  25. var _utils = require('./utils');
  26. function _interopRequireDefault(obj) {
  27. return obj && obj.__esModule ? obj : {default: obj};
  28. }
  29. function _defineProperty(obj, key, value) {
  30. if (key in obj) {
  31. Object.defineProperty(obj, key, {
  32. value: value,
  33. enumerable: true,
  34. configurable: true,
  35. writable: true
  36. });
  37. } else {
  38. obj[key] = value;
  39. }
  40. return obj;
  41. }
  42. const TEST_SUMMARY_THRESHOLD = 20;
  43. const NPM_EVENTS = new Set([
  44. 'prepublish',
  45. 'publish',
  46. 'postpublish',
  47. 'preinstall',
  48. 'install',
  49. 'postinstall',
  50. 'preuninstall',
  51. 'uninstall',
  52. 'postuninstall',
  53. 'preversion',
  54. 'version',
  55. 'postversion',
  56. 'pretest',
  57. 'test',
  58. 'posttest',
  59. 'prestop',
  60. 'stop',
  61. 'poststop',
  62. 'prestart',
  63. 'start',
  64. 'poststart',
  65. 'prerestart',
  66. 'restart',
  67. 'postrestart'
  68. ]);
  69. const {
  70. npm_config_user_agent,
  71. npm_lifecycle_event,
  72. npm_lifecycle_script
  73. } = process.env;
  74. class SummaryReporter extends _BaseReporter.default {
  75. constructor(globalConfig) {
  76. super();
  77. _defineProperty(this, '_estimatedTime', void 0);
  78. _defineProperty(this, '_globalConfig', void 0);
  79. this._globalConfig = globalConfig;
  80. this._estimatedTime = 0;
  81. } // If we write more than one character at a time it is possible that
  82. // Node.js exits in the middle of printing the result. This was first observed
  83. // in Node.js 0.10 and still persists in Node.js 6.7+.
  84. // Let's print the test failure summary character by character which is safer
  85. // when hundreds of tests are failing.
  86. _write(string) {
  87. for (let i = 0; i < string.length; i++) {
  88. process.stderr.write(string.charAt(i));
  89. }
  90. }
  91. onRunStart(aggregatedResults, options) {
  92. super.onRunStart(aggregatedResults, options);
  93. this._estimatedTime = options.estimatedTime;
  94. }
  95. onRunComplete(contexts, aggregatedResults) {
  96. const {numTotalTestSuites, testResults, wasInterrupted} = aggregatedResults;
  97. if (numTotalTestSuites) {
  98. const lastResult = testResults[testResults.length - 1]; // Print a newline if the last test did not fail to line up newlines
  99. // similar to when an error would have been thrown in the test.
  100. if (
  101. !this._globalConfig.verbose &&
  102. lastResult &&
  103. !lastResult.numFailingTests &&
  104. !lastResult.testExecError
  105. ) {
  106. this.log('');
  107. }
  108. this._printSummary(aggregatedResults, this._globalConfig);
  109. this._printSnapshotSummary(
  110. aggregatedResults.snapshot,
  111. this._globalConfig
  112. );
  113. if (numTotalTestSuites) {
  114. let message = (0, _utils.getSummary)(aggregatedResults, {
  115. estimatedTime: this._estimatedTime
  116. });
  117. if (!this._globalConfig.silent) {
  118. message +=
  119. '\n' +
  120. (wasInterrupted
  121. ? _chalk().default.bold.red('Test run was interrupted.')
  122. : this._getTestSummary(contexts, this._globalConfig));
  123. }
  124. this.log(message);
  125. }
  126. }
  127. }
  128. _printSnapshotSummary(snapshots, globalConfig) {
  129. if (
  130. snapshots.added ||
  131. snapshots.filesRemoved ||
  132. snapshots.unchecked ||
  133. snapshots.unmatched ||
  134. snapshots.updated
  135. ) {
  136. let updateCommand;
  137. const event = npm_lifecycle_event || '';
  138. const prefix = NPM_EVENTS.has(event) ? '' : 'run ';
  139. const isYarn =
  140. typeof npm_config_user_agent === 'string' &&
  141. npm_config_user_agent.includes('yarn');
  142. const client = isYarn ? 'yarn' : 'npm';
  143. const scriptUsesJest =
  144. typeof npm_lifecycle_script === 'string' &&
  145. npm_lifecycle_script.includes('jest');
  146. if (globalConfig.watch || globalConfig.watchAll) {
  147. updateCommand = 'press `u`';
  148. } else if (event && scriptUsesJest) {
  149. updateCommand = `run \`${
  150. client + ' ' + prefix + event + (isYarn ? '' : ' --')
  151. } -u\``;
  152. } else {
  153. updateCommand = 're-run jest with `-u`';
  154. }
  155. const snapshotSummary = (0, _getSnapshotSummary.default)(
  156. snapshots,
  157. globalConfig,
  158. updateCommand
  159. );
  160. snapshotSummary.forEach(this.log);
  161. this.log(''); // print empty line
  162. }
  163. }
  164. _printSummary(aggregatedResults, globalConfig) {
  165. // If there were any failing tests and there was a large number of tests
  166. // executed, re-print the failing results at the end of execution output.
  167. const failedTests = aggregatedResults.numFailedTests;
  168. const runtimeErrors = aggregatedResults.numRuntimeErrorTestSuites;
  169. if (
  170. failedTests + runtimeErrors > 0 &&
  171. aggregatedResults.numTotalTestSuites > TEST_SUMMARY_THRESHOLD
  172. ) {
  173. this.log(_chalk().default.bold('Summary of all failing tests'));
  174. aggregatedResults.testResults.forEach(testResult => {
  175. const {failureMessage} = testResult;
  176. if (failureMessage) {
  177. this._write(
  178. (0, _getResultHeader.default)(testResult, globalConfig) +
  179. '\n' +
  180. failureMessage +
  181. '\n'
  182. );
  183. }
  184. });
  185. this.log(''); // print empty line
  186. }
  187. }
  188. _getTestSummary(contexts, globalConfig) {
  189. const getMatchingTestsInfo = () => {
  190. const prefix = globalConfig.findRelatedTests
  191. ? ' related to files matching '
  192. : ' matching ';
  193. return (
  194. _chalk().default.dim(prefix) +
  195. (0, _jestUtil().testPathPatternToRegExp)(
  196. globalConfig.testPathPattern
  197. ).toString()
  198. );
  199. };
  200. let testInfo = '';
  201. if (globalConfig.runTestsByPath) {
  202. testInfo = _chalk().default.dim(' within paths');
  203. } else if (globalConfig.onlyChanged) {
  204. testInfo = _chalk().default.dim(' related to changed files');
  205. } else if (globalConfig.testPathPattern) {
  206. testInfo = getMatchingTestsInfo();
  207. }
  208. let nameInfo = '';
  209. if (globalConfig.runTestsByPath) {
  210. nameInfo = ' ' + globalConfig.nonFlagArgs.map(p => `"${p}"`).join(', ');
  211. } else if (globalConfig.testNamePattern) {
  212. nameInfo =
  213. _chalk().default.dim(' with tests matching ') +
  214. `"${globalConfig.testNamePattern}"`;
  215. }
  216. const contextInfo =
  217. contexts.size > 1
  218. ? _chalk().default.dim(' in ') +
  219. contexts.size +
  220. _chalk().default.dim(' projects')
  221. : '';
  222. return (
  223. _chalk().default.dim('Ran all test suites') +
  224. testInfo +
  225. nameInfo +
  226. contextInfo +
  227. _chalk().default.dim('.')
  228. );
  229. }
  230. }
  231. exports.default = SummaryReporter;