helpers.js 4.7 KB

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