1 | 'use strict';
|
2 |
|
3 | Object.defineProperty(exports, '__esModule', {
|
4 | value: true
|
5 | });
|
6 | exports.default = getResultHeader;
|
7 |
|
8 | function _chalk() {
|
9 | const data = _interopRequireDefault(require('chalk'));
|
10 |
|
11 | _chalk = function () {
|
12 | return data;
|
13 | };
|
14 |
|
15 | return data;
|
16 | }
|
17 |
|
18 | function _terminalLink() {
|
19 | const data = _interopRequireDefault(require('terminal-link'));
|
20 |
|
21 | _terminalLink = function () {
|
22 | return data;
|
23 | };
|
24 |
|
25 | return data;
|
26 | }
|
27 |
|
28 | function _jestUtil() {
|
29 | const data = require('jest-util');
|
30 |
|
31 | _jestUtil = function () {
|
32 | return data;
|
33 | };
|
34 |
|
35 | return data;
|
36 | }
|
37 |
|
38 | var _formatTestPath = _interopRequireDefault(require('./formatTestPath'));
|
39 |
|
40 | var _printDisplayName = _interopRequireDefault(require('./printDisplayName'));
|
41 |
|
42 | function _interopRequireDefault(obj) {
|
43 | return obj && obj.__esModule ? obj : {default: obj};
|
44 | }
|
45 |
|
46 |
|
47 |
|
48 |
|
49 |
|
50 |
|
51 |
|
52 | const LONG_TEST_COLOR = _chalk().default.reset.bold.bgRed;
|
53 |
|
54 |
|
55 | const FAIL_TEXT = 'FAIL';
|
56 | const PASS_TEXT = 'PASS';
|
57 | const FAIL = _chalk().default.supportsColor
|
58 | ? _chalk().default.reset.inverse.bold.red(` ${FAIL_TEXT} `)
|
59 | : FAIL_TEXT;
|
60 | const PASS = _chalk().default.supportsColor
|
61 | ? _chalk().default.reset.inverse.bold.green(` ${PASS_TEXT} `)
|
62 | : PASS_TEXT;
|
63 |
|
64 | function 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 | }
|