1 | 'use strict';
|
2 |
|
3 | Object.defineProperty(exports, '__esModule', {
|
4 | value: true
|
5 | });
|
6 | exports.default = void 0;
|
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 _utils = require('./utils');
|
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 | var _default = (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 | ARROW +
|
66 | (0, _jestUtil().pluralize)('snapshot', snapshots.added) +
|
67 | ' written '
|
68 | ) +
|
69 | `from ${(0, _jestUtil().pluralize)(
|
70 | 'test suite',
|
71 | snapshots.filesAdded
|
72 | )}.`
|
73 | );
|
74 | }
|
75 |
|
76 | if (snapshots.unmatched) {
|
77 | summary.push(
|
78 | FAIL_COLOR(
|
79 | `${ARROW}${(0, _jestUtil().pluralize)(
|
80 | 'snapshot',
|
81 | snapshots.unmatched
|
82 | )} failed`
|
83 | ) +
|
84 | ` from ${(0, _jestUtil().pluralize)(
|
85 | 'test suite',
|
86 | snapshots.filesUnmatched
|
87 | )}. ` +
|
88 | SNAPSHOT_NOTE(
|
89 | 'Inspect your code changes or ' + updateCommand + ' to update them.'
|
90 | )
|
91 | );
|
92 | }
|
93 |
|
94 | if (snapshots.updated) {
|
95 | summary.push(
|
96 | SNAPSHOT_UPDATED(
|
97 | ARROW +
|
98 | (0, _jestUtil().pluralize)('snapshot', snapshots.updated) +
|
99 | ' updated '
|
100 | ) +
|
101 | `from ${(0, _jestUtil().pluralize)(
|
102 | 'test suite',
|
103 | snapshots.filesUpdated
|
104 | )}.`
|
105 | );
|
106 | }
|
107 |
|
108 | if (snapshots.filesRemoved) {
|
109 | if (snapshots.didUpdate) {
|
110 | summary.push(
|
111 | SNAPSHOT_REMOVED(
|
112 | `${ARROW}${(0, _jestUtil().pluralize)(
|
113 | 'snapshot file',
|
114 | snapshots.filesRemoved
|
115 | )} removed `
|
116 | ) +
|
117 | `from ${(0, _jestUtil().pluralize)(
|
118 | 'test suite',
|
119 | snapshots.filesRemoved
|
120 | )}.`
|
121 | );
|
122 | } else {
|
123 | summary.push(
|
124 | OBSOLETE_COLOR(
|
125 | `${ARROW}${(0, _jestUtil().pluralize)(
|
126 | 'snapshot file',
|
127 | snapshots.filesRemoved
|
128 | )} obsolete `
|
129 | ) +
|
130 | `from ${(0, _jestUtil().pluralize)(
|
131 | 'test suite',
|
132 | snapshots.filesRemoved
|
133 | )}. ` +
|
134 | SNAPSHOT_NOTE(
|
135 | `To remove ${
|
136 | snapshots.filesRemoved === 1 ? 'it' : 'them all'
|
137 | }, ${updateCommand}.`
|
138 | )
|
139 | );
|
140 | }
|
141 | }
|
142 |
|
143 | if (snapshots.filesRemovedList && snapshots.filesRemovedList.length) {
|
144 | const [head, ...tail] = snapshots.filesRemovedList;
|
145 | summary.push(
|
146 | ` ${DOWN_ARROW} ${DOT}${(0, _utils.formatTestPath)(globalConfig, head)}`
|
147 | );
|
148 | tail.forEach(key => {
|
149 | summary.push(
|
150 | ` ${DOT}${(0, _utils.formatTestPath)(globalConfig, key)}`
|
151 | );
|
152 | });
|
153 | }
|
154 |
|
155 | if (snapshots.unchecked) {
|
156 | if (snapshots.didUpdate) {
|
157 | summary.push(
|
158 | SNAPSHOT_REMOVED(
|
159 | `${ARROW}${(0, _jestUtil().pluralize)(
|
160 | 'snapshot',
|
161 | snapshots.unchecked
|
162 | )} removed `
|
163 | ) +
|
164 | `from ${(0, _jestUtil().pluralize)(
|
165 | 'test suite',
|
166 | snapshots.uncheckedKeysByFile.length
|
167 | )}.`
|
168 | );
|
169 | } else {
|
170 | summary.push(
|
171 | OBSOLETE_COLOR(
|
172 | `${ARROW}${(0, _jestUtil().pluralize)(
|
173 | 'snapshot',
|
174 | snapshots.unchecked
|
175 | )} obsolete `
|
176 | ) +
|
177 | `from ${(0, _jestUtil().pluralize)(
|
178 | 'test suite',
|
179 | snapshots.uncheckedKeysByFile.length
|
180 | )}. ` +
|
181 | SNAPSHOT_NOTE(
|
182 | `To remove ${
|
183 | snapshots.unchecked === 1 ? 'it' : 'them all'
|
184 | }, ${updateCommand}.`
|
185 | )
|
186 | );
|
187 | }
|
188 |
|
189 | snapshots.uncheckedKeysByFile.forEach(uncheckedFile => {
|
190 | summary.push(
|
191 | ` ${DOWN_ARROW}${(0, _utils.formatTestPath)(
|
192 | globalConfig,
|
193 | uncheckedFile.filePath
|
194 | )}`
|
195 | );
|
196 | uncheckedFile.keys.forEach(key => {
|
197 | summary.push(` ${DOT}${key}`);
|
198 | });
|
199 | });
|
200 | }
|
201 |
|
202 | return summary;
|
203 | };
|
204 |
|
205 | exports.default = _default;
|