UNPKG

2.6 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 _terminalLink() {
19 const data = _interopRequireDefault(require('terminal-link'));
20
21 _terminalLink = function () {
22 return data;
23 };
24
25 return data;
26}
27
28function _jestUtil() {
29 const data = require('jest-util');
30
31 _jestUtil = function () {
32 return data;
33 };
34
35 return data;
36}
37
38var _utils = require('./utils');
39
40function _interopRequireDefault(obj) {
41 return obj && obj.__esModule ? obj : {default: obj};
42}
43
44/**
45 * Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
46 *
47 * This source code is licensed under the MIT license found in the
48 * LICENSE file in the root directory of this source tree.
49 */
50const LONG_TEST_COLOR = _chalk().default.reset.bold.bgRed; // Explicitly reset for these messages since they can get written out in the
51// middle of error logging
52
53const FAIL_TEXT = 'FAIL';
54const PASS_TEXT = 'PASS';
55const FAIL = _chalk().default.supportsColor
56 ? _chalk().default.reset.inverse.bold.red(` ${FAIL_TEXT} `)
57 : FAIL_TEXT;
58const PASS = _chalk().default.supportsColor
59 ? _chalk().default.reset.inverse.bold.green(` ${PASS_TEXT} `)
60 : PASS_TEXT;
61
62var _default = (result, globalConfig, projectConfig) => {
63 var _result$perfStats;
64
65 const testPath = result.testFilePath;
66 const formattedTestPath = (0, _utils.formatTestPath)(
67 projectConfig ? projectConfig : globalConfig,
68 testPath
69 );
70 const fileLink = (0, _terminalLink().default)(
71 formattedTestPath,
72 `file://${testPath}`,
73 {
74 fallback: () => formattedTestPath
75 }
76 );
77 const status =
78 result.numFailingTests > 0 || result.testExecError ? FAIL : PASS;
79 const testDetail = [];
80
81 if (
82 (_result$perfStats = result.perfStats) !== null &&
83 _result$perfStats !== void 0 &&
84 _result$perfStats.slow
85 ) {
86 const runTime = result.perfStats.runtime / 1000;
87 testDetail.push(LONG_TEST_COLOR((0, _jestUtil().formatTime)(runTime, 0)));
88 }
89
90 if (result.memoryUsage) {
91 const toMB = bytes => Math.floor(bytes / 1024 / 1024);
92
93 testDetail.push(`${toMB(result.memoryUsage)} MB heap size`);
94 }
95
96 const projectDisplayName =
97 projectConfig && projectConfig.displayName
98 ? (0, _utils.printDisplayName)(projectConfig) + ' '
99 : '';
100 return (
101 `${status} ${projectDisplayName}${fileLink}` +
102 (testDetail.length ? ` (${testDetail.join(', ')})` : '')
103 );
104};
105
106exports.default = _default;