UpdateSnapshots.js 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. 'use strict';
  2. Object.defineProperty(exports, '__esModule', {
  3. value: true
  4. });
  5. exports.default = void 0;
  6. function _jestWatcher() {
  7. const data = require('jest-watcher');
  8. _jestWatcher = function () {
  9. return data;
  10. };
  11. return data;
  12. }
  13. function _defineProperty(obj, key, value) {
  14. if (key in obj) {
  15. Object.defineProperty(obj, key, {
  16. value: value,
  17. enumerable: true,
  18. configurable: true,
  19. writable: true
  20. });
  21. } else {
  22. obj[key] = value;
  23. }
  24. return obj;
  25. }
  26. class UpdateSnapshotsPlugin extends _jestWatcher().BaseWatchPlugin {
  27. constructor(options) {
  28. super(options);
  29. _defineProperty(this, '_hasSnapshotFailure', void 0);
  30. _defineProperty(this, 'isInternal', void 0);
  31. this.isInternal = true;
  32. this._hasSnapshotFailure = false;
  33. }
  34. run(_globalConfig, updateConfigAndRun) {
  35. updateConfigAndRun({
  36. updateSnapshot: 'all'
  37. });
  38. return Promise.resolve(false);
  39. }
  40. apply(hooks) {
  41. hooks.onTestRunComplete(results => {
  42. this._hasSnapshotFailure = results.snapshot.failure;
  43. });
  44. }
  45. getUsageInfo() {
  46. if (this._hasSnapshotFailure) {
  47. return {
  48. key: 'u',
  49. prompt: 'update failing snapshots'
  50. };
  51. }
  52. return null;
  53. }
  54. }
  55. var _default = UpdateSnapshotsPlugin;
  56. exports.default = _default;