helpers.js 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. 'use strict';
  2. Object.defineProperty(exports, '__esModule', {
  3. value: true
  4. });
  5. 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: '',
  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. start: 0
  61. },
  62. skipped: false,
  63. snapshot: {
  64. added: 0,
  65. fileDeleted: false,
  66. matched: 0,
  67. unchecked: 0,
  68. uncheckedKeys: [],
  69. unmatched: 0,
  70. updated: 0
  71. },
  72. sourceMaps: {},
  73. testExecError: err,
  74. testFilePath: testPath,
  75. testResults: []
  76. }); // Add individual test result to an aggregated test result
  77. exports.buildFailureTestResult = buildFailureTestResult;
  78. const addResult = (aggregatedResults, testResult) => {
  79. // `todos` are new as of Jest 24, and not all runners return it.
  80. // Set it to `0` to avoid `NaN`
  81. if (!testResult.numTodoTests) {
  82. testResult.numTodoTests = 0;
  83. }
  84. aggregatedResults.testResults.push(testResult);
  85. aggregatedResults.numTotalTests +=
  86. testResult.numPassingTests +
  87. testResult.numFailingTests +
  88. testResult.numPendingTests +
  89. testResult.numTodoTests;
  90. aggregatedResults.numFailedTests += testResult.numFailingTests;
  91. aggregatedResults.numPassedTests += testResult.numPassingTests;
  92. aggregatedResults.numPendingTests += testResult.numPendingTests;
  93. aggregatedResults.numTodoTests += testResult.numTodoTests;
  94. if (testResult.testExecError) {
  95. aggregatedResults.numRuntimeErrorTestSuites++;
  96. }
  97. if (testResult.skipped) {
  98. aggregatedResults.numPendingTestSuites++;
  99. } else if (testResult.numFailingTests > 0 || testResult.testExecError) {
  100. aggregatedResults.numFailedTestSuites++;
  101. } else {
  102. aggregatedResults.numPassedTestSuites++;
  103. } // Snapshot data
  104. if (testResult.snapshot.added) {
  105. aggregatedResults.snapshot.filesAdded++;
  106. }
  107. if (testResult.snapshot.fileDeleted) {
  108. aggregatedResults.snapshot.filesRemoved++;
  109. }
  110. if (testResult.snapshot.unmatched) {
  111. aggregatedResults.snapshot.filesUnmatched++;
  112. }
  113. if (testResult.snapshot.updated) {
  114. aggregatedResults.snapshot.filesUpdated++;
  115. }
  116. aggregatedResults.snapshot.added += testResult.snapshot.added;
  117. aggregatedResults.snapshot.matched += testResult.snapshot.matched;
  118. aggregatedResults.snapshot.unchecked += testResult.snapshot.unchecked;
  119. if (
  120. testResult.snapshot.uncheckedKeys &&
  121. testResult.snapshot.uncheckedKeys.length > 0
  122. ) {
  123. aggregatedResults.snapshot.uncheckedKeysByFile.push({
  124. filePath: testResult.testFilePath,
  125. keys: testResult.snapshot.uncheckedKeys
  126. });
  127. }
  128. aggregatedResults.snapshot.unmatched += testResult.snapshot.unmatched;
  129. aggregatedResults.snapshot.updated += testResult.snapshot.updated;
  130. aggregatedResults.snapshot.total +=
  131. testResult.snapshot.added +
  132. testResult.snapshot.matched +
  133. testResult.snapshot.unmatched +
  134. testResult.snapshot.updated;
  135. };
  136. exports.addResult = addResult;