UNPKG

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