UNPKG

2.61 kBJavaScriptView Raw
1'use strict';
2
3Object.defineProperty(exports, '__esModule', {
4 value: true
5});
6exports.default = void 0;
7
8function _chalk() {
9 const data = _interopRequireDefault(require('chalk'));
10
11 _chalk = function () {
12 return data;
13 };
14
15 return data;
16}
17
18function _jestMessageUtil() {
19 const data = require('jest-message-util');
20
21 _jestMessageUtil = function () {
22 return data;
23 };
24
25 return data;
26}
27
28function _interopRequireDefault(obj) {
29 return obj && obj.__esModule ? obj : {default: obj};
30}
31
32/**
33 * Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
34 *
35 * This source code is licensed under the MIT license found in the
36 * LICENSE file in the root directory of this source tree.
37 */
38var _default = (buffer, config, globalConfig) => {
39 const TITLE_INDENT = globalConfig.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
50 if (type === 'warn') {
51 var _globalConfig$noStack;
52
53 message = _chalk().default.yellow(message);
54 typeMessage = _chalk().default.yellow(typeMessage);
55 noStackTrace =
56 (_globalConfig$noStack =
57 globalConfig === null || globalConfig === void 0
58 ? void 0
59 : globalConfig.noStackTrace) !== null &&
60 _globalConfig$noStack !== void 0
61 ? _globalConfig$noStack
62 : false;
63 noCodeFrame = false;
64 } else if (type === 'error') {
65 var _globalConfig$noStack2;
66
67 message = _chalk().default.red(message);
68 typeMessage = _chalk().default.red(typeMessage);
69 noStackTrace =
70 (_globalConfig$noStack2 =
71 globalConfig === null || globalConfig === void 0
72 ? void 0
73 : globalConfig.noStackTrace) !== null &&
74 _globalConfig$noStack2 !== void 0
75 ? _globalConfig$noStack2
76 : false;
77 noCodeFrame = false;
78 }
79
80 const options = {
81 noCodeFrame,
82 noStackTrace
83 };
84 const formattedStackTrace = (0, _jestMessageUtil().formatStackTrace)(
85 origin,
86 config,
87 options
88 );
89 return (
90 output +
91 TITLE_INDENT +
92 _chalk().default.dim(typeMessage) +
93 '\n' +
94 message.trimRight() +
95 '\n' +
96 _chalk().default.dim(formattedStackTrace.trimRight()) +
97 '\n\n'
98 );
99 }, '');
100 return logEntries.trimRight() + '\n';
101};
102
103exports.default = _default;