1 | 'use strict';
|
2 |
|
3 | Object.defineProperty(exports, '__esModule', {
|
4 | value: true
|
5 | });
|
6 | exports.default = getSnapshotSummary;
|
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 _jestUtil() {
|
19 | const data = require('jest-util');
|
20 |
|
21 | _jestUtil = function () {
|
22 | return data;
|
23 | };
|
24 |
|
25 | return data;
|
26 | }
|
27 |
|
28 | var _formatTestPath = _interopRequireDefault(require('./formatTestPath'));
|
29 |
|
30 | function _interopRequireDefault(obj) {
|
31 | return obj && obj.__esModule ? obj : {default: obj};
|
32 | }
|
33 |
|
34 |
|
35 |
|
36 |
|
37 |
|
38 |
|
39 |
|
40 | const ARROW = ' \u203A ';
|
41 | const DOWN_ARROW = ' \u21B3 ';
|
42 | const DOT = ' \u2022 ';
|
43 |
|
44 | const FAIL_COLOR = _chalk().default.bold.red;
|
45 |
|
46 | const OBSOLETE_COLOR = _chalk().default.bold.yellow;
|
47 |
|
48 | const SNAPSHOT_ADDED = _chalk().default.bold.green;
|
49 |
|
50 | const SNAPSHOT_NOTE = _chalk().default.dim;
|
51 |
|
52 | const SNAPSHOT_REMOVED = _chalk().default.bold.green;
|
53 |
|
54 | const SNAPSHOT_SUMMARY = _chalk().default.bold;
|
55 |
|
56 | const SNAPSHOT_UPDATED = _chalk().default.bold.green;
|
57 |
|
58 | function getSnapshotSummary(snapshots, globalConfig, updateCommand) {
|
59 | const summary = [];
|
60 | summary.push(SNAPSHOT_SUMMARY('Snapshot Summary'));
|
61 |
|
62 | if (snapshots.added) {
|
63 | summary.push(
|
64 | `${SNAPSHOT_ADDED(
|
65 | `${
|
66 | ARROW + (0, _jestUtil().pluralize)('snapshot', snapshots.added)
|
67 | } written `
|
68 | )}from ${(0, _jestUtil().pluralize)('test suite', snapshots.filesAdded)}.`
|
69 | );
|
70 | }
|
71 |
|
72 | if (snapshots.unmatched) {
|
73 | summary.push(
|
74 | `${FAIL_COLOR(
|
75 | `${ARROW}${(0, _jestUtil().pluralize)(
|
76 | 'snapshot',
|
77 | snapshots.unmatched
|
78 | )} failed`
|
79 | )} from ${(0, _jestUtil().pluralize)(
|
80 | 'test suite',
|
81 | snapshots.filesUnmatched
|
82 | )}. ${SNAPSHOT_NOTE(
|
83 | `Inspect your code changes or ${updateCommand} to update them.`
|
84 | )}`
|
85 | );
|
86 | }
|
87 |
|
88 | if (snapshots.updated) {
|
89 | summary.push(
|
90 | `${SNAPSHOT_UPDATED(
|
91 | `${
|
92 | ARROW + (0, _jestUtil().pluralize)('snapshot', snapshots.updated)
|
93 | } updated `
|
94 | )}from ${(0, _jestUtil().pluralize)(
|
95 | 'test suite',
|
96 | snapshots.filesUpdated
|
97 | )}.`
|
98 | );
|
99 | }
|
100 |
|
101 | if (snapshots.filesRemoved) {
|
102 | if (snapshots.didUpdate) {
|
103 | summary.push(
|
104 | `${SNAPSHOT_REMOVED(
|
105 | `${ARROW}${(0, _jestUtil().pluralize)(
|
106 | 'snapshot file',
|
107 | snapshots.filesRemoved
|
108 | )} removed `
|
109 | )}from ${(0, _jestUtil().pluralize)(
|
110 | 'test suite',
|
111 | snapshots.filesRemoved
|
112 | )}.`
|
113 | );
|
114 | } else {
|
115 | summary.push(
|
116 | `${OBSOLETE_COLOR(
|
117 | `${ARROW}${(0, _jestUtil().pluralize)(
|
118 | 'snapshot file',
|
119 | snapshots.filesRemoved
|
120 | )} obsolete `
|
121 | )}from ${(0, _jestUtil().pluralize)(
|
122 | 'test suite',
|
123 | snapshots.filesRemoved
|
124 | )}. ${SNAPSHOT_NOTE(
|
125 | `To remove ${
|
126 | snapshots.filesRemoved === 1 ? 'it' : 'them all'
|
127 | }, ${updateCommand}.`
|
128 | )}`
|
129 | );
|
130 | }
|
131 | }
|
132 |
|
133 | if (snapshots.filesRemovedList && snapshots.filesRemovedList.length) {
|
134 | const [head, ...tail] = snapshots.filesRemovedList;
|
135 | summary.push(
|
136 | ` ${DOWN_ARROW} ${DOT}${(0, _formatTestPath.default)(
|
137 | globalConfig,
|
138 | head
|
139 | )}`
|
140 | );
|
141 | tail.forEach(key => {
|
142 | summary.push(
|
143 | ` ${DOT}${(0, _formatTestPath.default)(globalConfig, key)}`
|
144 | );
|
145 | });
|
146 | }
|
147 |
|
148 | if (snapshots.unchecked) {
|
149 | if (snapshots.didUpdate) {
|
150 | summary.push(
|
151 | `${SNAPSHOT_REMOVED(
|
152 | `${ARROW}${(0, _jestUtil().pluralize)(
|
153 | 'snapshot',
|
154 | snapshots.unchecked
|
155 | )} removed `
|
156 | )}from ${(0, _jestUtil().pluralize)(
|
157 | 'test suite',
|
158 | snapshots.uncheckedKeysByFile.length
|
159 | )}.`
|
160 | );
|
161 | } else {
|
162 | summary.push(
|
163 | `${OBSOLETE_COLOR(
|
164 | `${ARROW}${(0, _jestUtil().pluralize)(
|
165 | 'snapshot',
|
166 | snapshots.unchecked
|
167 | )} obsolete `
|
168 | )}from ${(0, _jestUtil().pluralize)(
|
169 | 'test suite',
|
170 | snapshots.uncheckedKeysByFile.length
|
171 | )}. ${SNAPSHOT_NOTE(
|
172 | `To remove ${
|
173 | snapshots.unchecked === 1 ? 'it' : 'them all'
|
174 | }, ${updateCommand}.`
|
175 | )}`
|
176 | );
|
177 | }
|
178 |
|
179 | snapshots.uncheckedKeysByFile.forEach(uncheckedFile => {
|
180 | summary.push(
|
181 | ` ${DOWN_ARROW}${(0, _formatTestPath.default)(
|
182 | globalConfig,
|
183 | uncheckedFile.filePath
|
184 | )}`
|
185 | );
|
186 | uncheckedFile.keys.forEach(key => {
|
187 | summary.push(` ${DOT}${key}`);
|
188 | });
|
189 | });
|
190 | }
|
191 |
|
192 | return summary;
|
193 | }
|