formatTestResults.js 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. 'use strict';
  2. Object.defineProperty(exports, '__esModule', {
  3. value: true
  4. });
  5. exports.default = formatTestResults;
  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 formatTestResult = (testResult, codeCoverageFormatter, reporter) => {
  13. const assertionResults = testResult.testResults.map(formatTestAssertion);
  14. if (testResult.testExecError) {
  15. const now = Date.now();
  16. return {
  17. assertionResults,
  18. coverage: {},
  19. endTime: now,
  20. message: testResult.failureMessage
  21. ? testResult.failureMessage
  22. : testResult.testExecError.message,
  23. name: testResult.testFilePath,
  24. startTime: now,
  25. status: 'failed',
  26. summary: ''
  27. };
  28. } else {
  29. const allTestsPassed = testResult.numFailingTests === 0;
  30. return {
  31. assertionResults,
  32. coverage: codeCoverageFormatter
  33. ? codeCoverageFormatter(testResult.coverage, reporter)
  34. : testResult.coverage,
  35. endTime: testResult.perfStats.end,
  36. message: testResult.failureMessage || '',
  37. name: testResult.testFilePath,
  38. startTime: testResult.perfStats.start,
  39. status: allTestsPassed ? 'passed' : 'failed',
  40. summary: ''
  41. };
  42. }
  43. };
  44. function formatTestAssertion(assertion) {
  45. const result = {
  46. ancestorTitles: assertion.ancestorTitles,
  47. failureMessages: null,
  48. fullName: assertion.fullName,
  49. location: assertion.location,
  50. status: assertion.status,
  51. title: assertion.title
  52. };
  53. if (assertion.failureMessages) {
  54. result.failureMessages = assertion.failureMessages;
  55. }
  56. return result;
  57. }
  58. function formatTestResults(results, codeCoverageFormatter, reporter) {
  59. const testResults = results.testResults.map(testResult =>
  60. formatTestResult(testResult, codeCoverageFormatter, reporter)
  61. );
  62. return {...results, testResults};
  63. }