1 | 'use strict';
|
2 |
|
3 | Object.defineProperty(exports, '__esModule', {
|
4 | value: true
|
5 | });
|
6 | exports.default = void 0;
|
7 | function _ansiEscapes() {
|
8 | const data = _interopRequireDefault(require('ansi-escapes'));
|
9 | _ansiEscapes = function () {
|
10 | return data;
|
11 | };
|
12 | return data;
|
13 | }
|
14 | function _chalk() {
|
15 | const data = _interopRequireDefault(require('chalk'));
|
16 | _chalk = function () {
|
17 | return data;
|
18 | };
|
19 | return data;
|
20 | }
|
21 | function _jestUtil() {
|
22 | const data = require('jest-util');
|
23 | _jestUtil = function () {
|
24 | return data;
|
25 | };
|
26 | return data;
|
27 | }
|
28 | function _jestWatcher() {
|
29 | const data = require('jest-watcher');
|
30 | _jestWatcher = function () {
|
31 | return data;
|
32 | };
|
33 | return data;
|
34 | }
|
35 | function _interopRequireDefault(obj) {
|
36 | return obj && obj.__esModule ? obj : {default: obj};
|
37 | }
|
38 |
|
39 |
|
40 |
|
41 |
|
42 |
|
43 |
|
44 |
|
45 | const {ARROW, CLEAR} = _jestUtil().specialChars;
|
46 | function describeKey(key, description) {
|
47 | return `${_chalk().default.dim(
|
48 | `${ARROW}Press`
|
49 | )} ${key} ${_chalk().default.dim(description)}`;
|
50 | }
|
51 | const TestProgressLabel = _chalk().default.bold('Interactive Test Progress');
|
52 | class FailedTestsInteractiveMode {
|
53 | _isActive = false;
|
54 | _countPaths = 0;
|
55 | _skippedNum = 0;
|
56 | _testAssertions = [];
|
57 | _updateTestRunnerConfig;
|
58 | constructor(_pipe) {
|
59 | this._pipe = _pipe;
|
60 | }
|
61 | isActive() {
|
62 | return this._isActive;
|
63 | }
|
64 | put(key) {
|
65 | switch (key) {
|
66 | case 's':
|
67 | if (this._skippedNum === this._testAssertions.length) {
|
68 | break;
|
69 | }
|
70 | this._skippedNum += 1;
|
71 |
|
72 | this._testAssertions.push(this._testAssertions.shift());
|
73 | if (this._testAssertions.length - this._skippedNum > 0) {
|
74 | this._run();
|
75 | } else {
|
76 | this._drawUIDoneWithSkipped();
|
77 | }
|
78 | break;
|
79 | case 'q':
|
80 | case _jestWatcher().KEYS.ESCAPE:
|
81 | this.abort();
|
82 | break;
|
83 | case 'r':
|
84 | this.restart();
|
85 | break;
|
86 | case _jestWatcher().KEYS.ENTER:
|
87 | if (this._testAssertions.length === 0) {
|
88 | this.abort();
|
89 | } else {
|
90 | this._run();
|
91 | }
|
92 | break;
|
93 | default:
|
94 | }
|
95 | }
|
96 | run(failedTestAssertions, updateConfig) {
|
97 | if (failedTestAssertions.length === 0) return;
|
98 | this._testAssertions = [...failedTestAssertions];
|
99 | this._countPaths = this._testAssertions.length;
|
100 | this._updateTestRunnerConfig = updateConfig;
|
101 | this._isActive = true;
|
102 | this._run();
|
103 | }
|
104 | updateWithResults(results) {
|
105 | if (!results.snapshot.failure && results.numFailedTests > 0) {
|
106 | return this._drawUIOverlay();
|
107 | }
|
108 | this._testAssertions.shift();
|
109 | if (this._testAssertions.length === 0) {
|
110 | return this._drawUIOverlay();
|
111 | }
|
112 |
|
113 |
|
114 | return this._run();
|
115 | }
|
116 | _clearTestSummary() {
|
117 | this._pipe.write(_ansiEscapes().default.cursorUp(6));
|
118 | this._pipe.write(_ansiEscapes().default.eraseDown);
|
119 | }
|
120 | _drawUIDone() {
|
121 | this._pipe.write(CLEAR);
|
122 | const messages = [
|
123 | _chalk().default.bold('Watch Usage'),
|
124 | describeKey('Enter', 'to return to watch mode.')
|
125 | ];
|
126 | this._pipe.write(`${messages.join('\n')}\n`);
|
127 | }
|
128 | _drawUIDoneWithSkipped() {
|
129 | this._pipe.write(CLEAR);
|
130 | let stats = `${(0, _jestUtil().pluralize)(
|
131 | 'test',
|
132 | this._countPaths
|
133 | )} reviewed`;
|
134 | if (this._skippedNum > 0) {
|
135 | const skippedText = _chalk().default.bold.yellow(
|
136 | `${(0, _jestUtil().pluralize)('test', this._skippedNum)} skipped`
|
137 | );
|
138 | stats = `${stats}, ${skippedText}`;
|
139 | }
|
140 | const message = [
|
141 | TestProgressLabel,
|
142 | `${ARROW}${stats}`,
|
143 | '\n',
|
144 | _chalk().default.bold('Watch Usage'),
|
145 | describeKey('r', 'to restart Interactive Mode.'),
|
146 | describeKey('q', 'to quit Interactive Mode.'),
|
147 | describeKey('Enter', 'to return to watch mode.')
|
148 | ];
|
149 | this._pipe.write(`\n${message.join('\n')}`);
|
150 | }
|
151 | _drawUIProgress() {
|
152 | this._clearTestSummary();
|
153 | const numPass = this._countPaths - this._testAssertions.length;
|
154 | const numRemaining = this._countPaths - numPass - this._skippedNum;
|
155 | let stats = `${(0, _jestUtil().pluralize)('test', numRemaining)} remaining`;
|
156 | if (this._skippedNum > 0) {
|
157 | const skippedText = _chalk().default.bold.yellow(
|
158 | `${(0, _jestUtil().pluralize)('test', this._skippedNum)} skipped`
|
159 | );
|
160 | stats = `${stats}, ${skippedText}`;
|
161 | }
|
162 | const message = [
|
163 | TestProgressLabel,
|
164 | `${ARROW}${stats}`,
|
165 | '\n',
|
166 | _chalk().default.bold('Watch Usage'),
|
167 | describeKey('s', 'to skip the current test.'),
|
168 | describeKey('q', 'to quit Interactive Mode.'),
|
169 | describeKey('Enter', 'to return to watch mode.')
|
170 | ];
|
171 | this._pipe.write(`\n${message.join('\n')}`);
|
172 | }
|
173 | _drawUIOverlay() {
|
174 | if (this._testAssertions.length === 0) return this._drawUIDone();
|
175 | return this._drawUIProgress();
|
176 | }
|
177 | _run() {
|
178 | if (this._updateTestRunnerConfig) {
|
179 | this._updateTestRunnerConfig(this._testAssertions[0]);
|
180 | }
|
181 | }
|
182 | abort() {
|
183 | this._isActive = false;
|
184 | this._skippedNum = 0;
|
185 | if (this._updateTestRunnerConfig) {
|
186 | this._updateTestRunnerConfig();
|
187 | }
|
188 | }
|
189 | restart() {
|
190 | this._skippedNum = 0;
|
191 | this._countPaths = this._testAssertions.length;
|
192 | this._run();
|
193 | }
|
194 | }
|
195 | exports.default = FailedTestsInteractiveMode;
|