getConsoleOutput.js 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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 () {
  9. return data;
  10. };
  11. return data;
  12. }
  13. function _jestMessageUtil() {
  14. const data = require('jest-message-util');
  15. _jestMessageUtil = function () {
  16. return data;
  17. };
  18. return data;
  19. }
  20. function _interopRequireDefault(obj) {
  21. return obj && obj.__esModule ? obj : {default: obj};
  22. }
  23. /**
  24. * Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
  25. *
  26. * This source code is licensed under the MIT license found in the
  27. * LICENSE file in the root directory of this source tree.
  28. */
  29. var _default = (
  30. root,
  31. verbose,
  32. buffer, // TODO: make mandatory and take Config.ProjectConfig in 27
  33. config = {
  34. rootDir: root,
  35. testMatch: []
  36. },
  37. globalConfig
  38. ) => {
  39. const TITLE_INDENT = verbose ? ' ' : ' ';
  40. const CONSOLE_INDENT = TITLE_INDENT + ' ';
  41. const logEntries = buffer.reduce((output, {type, message, origin}) => {
  42. message = message
  43. .split(/\n/)
  44. .map(line => CONSOLE_INDENT + line)
  45. .join('\n');
  46. let typeMessage = 'console.' + type;
  47. let noStackTrace = true;
  48. let noCodeFrame = true;
  49. if (type === 'warn') {
  50. var _globalConfig$noStack;
  51. message = _chalk().default.yellow(message);
  52. typeMessage = _chalk().default.yellow(typeMessage);
  53. noStackTrace =
  54. (_globalConfig$noStack =
  55. globalConfig === null || globalConfig === void 0
  56. ? void 0
  57. : globalConfig.noStackTrace) !== null &&
  58. _globalConfig$noStack !== void 0
  59. ? _globalConfig$noStack
  60. : false;
  61. noCodeFrame = false;
  62. } else if (type === 'error') {
  63. var _globalConfig$noStack2;
  64. message = _chalk().default.red(message);
  65. typeMessage = _chalk().default.red(typeMessage);
  66. noStackTrace =
  67. (_globalConfig$noStack2 =
  68. globalConfig === null || globalConfig === void 0
  69. ? void 0
  70. : globalConfig.noStackTrace) !== null &&
  71. _globalConfig$noStack2 !== void 0
  72. ? _globalConfig$noStack2
  73. : false;
  74. noCodeFrame = false;
  75. }
  76. const options = {
  77. noCodeFrame,
  78. noStackTrace
  79. };
  80. const formattedStackTrace = (0, _jestMessageUtil().formatStackTrace)(
  81. origin,
  82. config,
  83. options
  84. );
  85. return (
  86. output +
  87. TITLE_INDENT +
  88. _chalk().default.dim(typeMessage) +
  89. '\n' +
  90. message.trimRight() +
  91. '\n' +
  92. _chalk().default.dim(formattedStackTrace.trimRight()) +
  93. '\n\n'
  94. );
  95. }, '');
  96. return logEntries.trimRight() + '\n';
  97. };
  98. exports.default = _default;