helpers.js 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. 'use strict';
  2. Object.defineProperty(exports, '__esModule', {
  3. value: true
  4. });
  5. exports.createEmptyTestResult = exports.addResult = exports.buildFailureTestResult = exports.makeEmptyAggregatedTestResult = void 0;
  6. /**
  7. * Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
  8. *
  9. * This source code is licensed under the MIT license found in the
  10. * LICENSE file in the root directory of this source tree.
  11. */
  12. const makeEmptyAggregatedTestResult = () => ({
  13. numFailedTestSuites: 0,
  14. numFailedTests: 0,
  15. numPassedTestSuites: 0,
  16. numPassedTests: 0,
  17. numPendingTestSuites: 0,
  18. numPendingTests: 0,
  19. numRuntimeErrorTestSuites: 0,
  20. numTodoTests: 0,
  21. numTotalTestSuites: 0,
  22. numTotalTests: 0,
  23. openHandles: [],
  24. snapshot: {
  25. added: 0,
  26. didUpdate: false,
  27. // is set only after the full run
  28. failure: false,
  29. filesAdded: 0,
  30. // combines individual test results + removed files after the full run
  31. filesRemoved: 0,
  32. filesRemovedList: [],
  33. filesUnmatched: 0,
  34. filesUpdated: 0,
  35. matched: 0,
  36. total: 0,
  37. unchecked: 0,
  38. uncheckedKeysByFile: [],
  39. unmatched: 0,
  40. updated: 0
  41. },
  42. startTime: 0,
  43. success: true,
  44. testResults: [],
  45. wasInterrupted: false
  46. });
  47. exports.makeEmptyAggregatedTestResult = makeEmptyAggregatedTestResult;
  48. const buildFailureTestResult = (testPath, err) => ({
  49. console: undefined,
  50. displayName: undefined,
  51. failureMessage: null,
  52. leaks: false,
  53. numFailingTests: 0,
  54. numPassingTests: 0,
  55. numPendingTests: 0,
  56. numTodoTests: 0,
  57. openHandles: [],
  58. perfStats: {
  59. end: 0,
  60. runtime: 0,
  61. slow: false,
  62. start: 0
  63. },
  64. skipped: false,
  65. snapshot: {
  66. added: 0,
  67. fileDeleted: false,
  68. matched: 0,
  69. unchecked: 0,
  70. uncheckedKeys: [],
  71. unmatched: 0,
  72. updated: 0
  73. },
  74. sourceMaps: {},
  75. testExecError: err,
  76. testFilePath: testPath,
  77. testResults: []
  78. }); // Add individual test result to an aggregated test result
  79. exports.buildFailureTestResult = buildFailureTestResult;
  80. const addResult = (aggregatedResults, testResult) => {
  81. // `todos` are new as of Jest 24, and not all runners return it.
  82. // Set it to `0` to avoid `NaN`
  83. if (!testResult.numTodoTests) {
  84. testResult.numTodoTests = 0;
  85. }
  86. aggregatedResults.testResults.push(testResult);
  87. aggregatedResults.numTotalTests +=
  88. testResult.numPassingTests +
  89. testResult.numFailingTests +
  90. testResult.numPendingTests +
  91. testResult.numTodoTests;
  92. aggregatedResults.numFailedTests += testResult.numFailingTests;
  93. aggregatedResults.numPassedTests += testResult.numPassingTests;
  94. aggregatedResults.numPendingTests += testResult.numPendingTests;
  95. aggregatedResults.numTodoTests += testResult.numTodoTests;
  96. if (testResult.testExecError) {
  97. aggregatedResults.numRuntimeErrorTestSuites++;
  98. }
  99. if (testResult.skipped) {
  100. aggregatedResults.numPendingTestSuites++;
  101. } else if (testResult.numFailingTests > 0 || testResult.testExecError) {
  102. aggregatedResults.numFailedTestSuites++;
  103. } else {
  104. aggregatedResults.numPassedTestSuites++;
  105. } // Snapshot data
  106. if (testResult.snapshot.added) {
  107. aggregatedResults.snapshot.filesAdded++;
  108. }
  109. if (testResult.snapshot.fileDeleted) {
  110. aggregatedResults.snapshot.filesRemoved++;
  111. }
  112. if (testResult.snapshot.unmatched) {
  113. aggregatedResults.snapshot.filesUnmatched++;
  114. }
  115. if (testResult.snapshot.updated) {
  116. aggregatedResults.snapshot.filesUpdated++;
  117. }
  118. aggregatedResults.snapshot.added += testResult.snapshot.added;
  119. aggregatedResults.snapshot.matched += testResult.snapshot.matched;
  120. aggregatedResults.snapshot.unchecked += testResult.snapshot.unchecked;
  121. if (
  122. testResult.snapshot.uncheckedKeys &&
  123. testResult.snapshot.uncheckedKeys.length > 0
  124. ) {
  125. aggregatedResults.snapshot.uncheckedKeysByFile.push({
  126. filePath: testResult.testFilePath,
  127. keys: testResult.snapshot.uncheckedKeys
  128. });
  129. }
  130. aggregatedResults.snapshot.unmatched += testResult.snapshot.unmatched;
  131. aggregatedResults.snapshot.updated += testResult.snapshot.updated;
  132. aggregatedResults.snapshot.total +=
  133. testResult.snapshot.added +
  134. testResult.snapshot.matched +
  135. testResult.snapshot.unmatched +
  136. testResult.snapshot.updated;
  137. };
  138. exports.addResult = addResult;
  139. const createEmptyTestResult = () => ({
  140. leaks: false,
  141. // That's legacy code, just adding it as needed for typing
  142. numFailingTests: 0,
  143. numPassingTests: 0,
  144. numPendingTests: 0,
  145. numTodoTests: 0,
  146. openHandles: [],
  147. perfStats: {
  148. end: 0,
  149. runtime: 0,
  150. slow: false,
  151. start: 0
  152. },
  153. skipped: false,
  154. snapshot: {
  155. added: 0,
  156. fileDeleted: false,
  157. matched: 0,
  158. unchecked: 0,
  159. uncheckedKeys: [],
  160. unmatched: 0,
  161. updated: 0
  162. },
  163. testFilePath: '',
  164. testResults: []
  165. });
  166. exports.createEmptyTestResult = createEmptyTestResult;