1 | 'use strict';
|
2 |
|
3 | Object.defineProperty(exports, '__esModule', {
|
4 | value: true
|
5 | });
|
6 | exports.default = void 0;
|
7 |
|
8 | function _jestWatcher() {
|
9 | const data = require('jest-watcher');
|
10 |
|
11 | _jestWatcher = function () {
|
12 | return data;
|
13 | };
|
14 |
|
15 | return data;
|
16 | }
|
17 |
|
18 | function _SnapshotInteractiveMode() {
|
19 | const data = _interopRequireDefault(require('../SnapshotInteractiveMode'));
|
20 |
|
21 | _SnapshotInteractiveMode = function () {
|
22 | return data;
|
23 | };
|
24 |
|
25 | return data;
|
26 | }
|
27 |
|
28 | function _interopRequireDefault(obj) {
|
29 | return obj && obj.__esModule ? obj : {default: obj};
|
30 | }
|
31 |
|
32 | function _defineProperty(obj, key, value) {
|
33 | if (key in obj) {
|
34 | Object.defineProperty(obj, key, {
|
35 | value: value,
|
36 | enumerable: true,
|
37 | configurable: true,
|
38 | writable: true
|
39 | });
|
40 | } else {
|
41 | obj[key] = value;
|
42 | }
|
43 | return obj;
|
44 | }
|
45 |
|
46 | class UpdateSnapshotInteractivePlugin extends _jestWatcher().BaseWatchPlugin {
|
47 | constructor(...args) {
|
48 | super(...args);
|
49 |
|
50 | _defineProperty(
|
51 | this,
|
52 | '_snapshotInteractiveMode',
|
53 | new (_SnapshotInteractiveMode().default)(this._stdout)
|
54 | );
|
55 |
|
56 | _defineProperty(this, '_failedSnapshotTestAssertions', []);
|
57 |
|
58 | _defineProperty(this, 'isInternal', true);
|
59 | }
|
60 |
|
61 | getFailedSnapshotTestAssertions(testResults) {
|
62 | const failedTestPaths = [];
|
63 |
|
64 | if (testResults.numFailedTests === 0 || !testResults.testResults) {
|
65 | return failedTestPaths;
|
66 | }
|
67 |
|
68 | testResults.testResults.forEach(testResult => {
|
69 | if (testResult.snapshot && testResult.snapshot.unmatched) {
|
70 | testResult.testResults.forEach(result => {
|
71 | if (result.status === 'failed') {
|
72 | failedTestPaths.push({
|
73 | fullName: result.fullName,
|
74 | path: testResult.testFilePath
|
75 | });
|
76 | }
|
77 | });
|
78 | }
|
79 | });
|
80 | return failedTestPaths;
|
81 | }
|
82 |
|
83 | apply(hooks) {
|
84 | hooks.onTestRunComplete(results => {
|
85 | this._failedSnapshotTestAssertions =
|
86 | this.getFailedSnapshotTestAssertions(results);
|
87 |
|
88 | if (this._snapshotInteractiveMode.isActive()) {
|
89 | this._snapshotInteractiveMode.updateWithResults(results);
|
90 | }
|
91 | });
|
92 | }
|
93 |
|
94 | onKey(key) {
|
95 | if (this._snapshotInteractiveMode.isActive()) {
|
96 | this._snapshotInteractiveMode.put(key);
|
97 | }
|
98 | }
|
99 |
|
100 | run(_globalConfig, updateConfigAndRun) {
|
101 | if (this._failedSnapshotTestAssertions.length) {
|
102 | return new Promise(res => {
|
103 | this._snapshotInteractiveMode.run(
|
104 | this._failedSnapshotTestAssertions,
|
105 | (assertion, shouldUpdateSnapshot) => {
|
106 | updateConfigAndRun({
|
107 | mode: 'watch',
|
108 | testNamePattern: assertion ? `^${assertion.fullName}$` : '',
|
109 | testPathPattern: assertion ? assertion.path : '',
|
110 | updateSnapshot: shouldUpdateSnapshot ? 'all' : 'none'
|
111 | });
|
112 |
|
113 | if (!this._snapshotInteractiveMode.isActive()) {
|
114 | res();
|
115 | }
|
116 | }
|
117 | );
|
118 | });
|
119 | } else {
|
120 | return Promise.resolve();
|
121 | }
|
122 | }
|
123 |
|
124 | getUsageInfo() {
|
125 | var _this$_failedSnapshot;
|
126 |
|
127 | if (
|
128 | ((_this$_failedSnapshot = this._failedSnapshotTestAssertions) === null ||
|
129 | _this$_failedSnapshot === void 0
|
130 | ? void 0
|
131 | : _this$_failedSnapshot.length) > 0
|
132 | ) {
|
133 | return {
|
134 | key: 'i',
|
135 | prompt: 'update failing snapshots interactively'
|
136 | };
|
137 | }
|
138 |
|
139 | return null;
|
140 | }
|
141 | }
|
142 |
|
143 | var _default = UpdateSnapshotInteractivePlugin;
|
144 | exports.default = _default;
|