get_snapshot_summary.js 5.2 KB

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