get_result_header.js 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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 _chalk() {
  9. return data;
  10. };
  11. return data;
  12. }
  13. var _utils = require('./utils');
  14. function _interopRequireDefault(obj) {
  15. return obj && obj.__esModule ? obj : {default: obj};
  16. }
  17. /**
  18. * Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
  19. *
  20. * This source code is licensed under the MIT license found in the
  21. * LICENSE file in the root directory of this source tree.
  22. */
  23. const LONG_TEST_COLOR = _chalk().default.reset.bold.bgRed; // Explicitly reset for these messages since they can get written out in the
  24. // middle of error logging
  25. const FAIL_TEXT = 'FAIL';
  26. const PASS_TEXT = 'PASS';
  27. const FAIL = _chalk().default.supportsColor
  28. ? _chalk().default.reset.inverse.bold.red(` ${FAIL_TEXT} `)
  29. : FAIL_TEXT;
  30. const PASS = _chalk().default.supportsColor
  31. ? _chalk().default.reset.inverse.bold.green(` ${PASS_TEXT} `)
  32. : PASS_TEXT;
  33. var _default = (result, globalConfig, projectConfig) => {
  34. const testPath = result.testFilePath;
  35. const status =
  36. result.numFailingTests > 0 || result.testExecError ? FAIL : PASS;
  37. const runTime = result.perfStats
  38. ? (result.perfStats.end - result.perfStats.start) / 1000
  39. : null;
  40. const testDetail = [];
  41. if (runTime !== null && runTime > 5) {
  42. testDetail.push(LONG_TEST_COLOR(runTime + 's'));
  43. }
  44. if (result.memoryUsage) {
  45. const toMB = bytes => Math.floor(bytes / 1024 / 1024);
  46. testDetail.push(`${toMB(result.memoryUsage)} MB heap size`);
  47. }
  48. const projectDisplayName =
  49. projectConfig && projectConfig.displayName
  50. ? (0, _utils.printDisplayName)(projectConfig) + ' '
  51. : '';
  52. return (
  53. `${status} ${projectDisplayName}${(0, _utils.formatTestPath)(
  54. projectConfig ? projectConfig : globalConfig,
  55. testPath
  56. )}` + (testDetail.length ? ` (${testDetail.join(', ')})` : '')
  57. );
  58. };
  59. exports.default = _default;