jest-watch-typeahead 0.1.0-2 → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,95 +1,90 @@
1
- 'use strict';
1
+ "use strict";
2
2
 
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.formatTestNameByPattern = exports.highlight = exports.getTerminalWidth = exports.trimAndFormatPath = undefined;
6
+ exports.formatTestNameByPattern = exports.highlight = exports.getTerminalWidth = exports.trimAndFormatPath = void 0;
7
7
 
8
- var _path = require('path');
8
+ var _path = _interopRequireDefault(require("path"));
9
9
 
10
- var _path2 = _interopRequireDefault(_path);
10
+ var _chalk = _interopRequireDefault(require("chalk"));
11
11
 
12
- var _chalk = require('chalk');
12
+ var _slash = _interopRequireDefault(require("slash"));
13
13
 
14
- var _chalk2 = _interopRequireDefault(_chalk);
14
+ var _stripAnsi = _interopRequireDefault(require("strip-ansi"));
15
15
 
16
- var _slash = require('slash');
16
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
17
17
 
18
- var _slash2 = _interopRequireDefault(_slash);
18
+ /* eslint-disable no-param-reassign */
19
+ const relativePath = (config, testPath) => {
20
+ testPath = _path.default.relative(config.cwd || config.rootDir, testPath);
19
21
 
20
- var _stripAnsi = require('strip-ansi');
22
+ const dirname = _path.default.dirname(testPath);
21
23
 
22
- var _stripAnsi2 = _interopRequireDefault(_stripAnsi);
24
+ const basename = _path.default.basename(testPath);
23
25
 
24
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
25
-
26
- /* eslint-disable no-param-reassign */
27
- var relativePath = function relativePath(config, testPath) {
28
- testPath = _path2.default.relative(config.cwd || config.rootDir, testPath);
29
- var dirname = _path2.default.dirname(testPath);
30
- var basename = _path2.default.basename(testPath);
31
- return { basename, dirname };
26
+ return {
27
+ basename,
28
+ dirname
29
+ };
32
30
  };
33
31
 
34
- var colorize = function colorize(str, start, end) {
35
- return _chalk2.default.dim(str.slice(0, start)) + _chalk2.default.reset(str.slice(start, end)) + _chalk2.default.dim(str.slice(end));
36
- };
32
+ const colorize = (str, start, end) => _chalk.default.dim(str.slice(0, start)) + _chalk.default.reset(str.slice(start, end)) + _chalk.default.dim(str.slice(end));
37
33
 
38
- var trimAndFormatPath = exports.trimAndFormatPath = function trimAndFormatPath(pad, config, testPath, columns) {
39
- var maxLength = columns - pad;
40
- var relative = relativePath(config, testPath);
41
- var basename = relative.basename;
42
- var dirname = relative.dirname;
34
+ const trimAndFormatPath = (pad, config, testPath, columns) => {
35
+ const maxLength = columns - pad;
36
+ const relative = relativePath(config, testPath);
37
+ const basename = relative.basename;
38
+ let dirname = relative.dirname; // length is ok
43
39
 
44
- // length is ok
40
+ if ((dirname + _path.default.sep + basename).length <= maxLength) {
41
+ return (0, _slash.default)(_chalk.default.dim(dirname + _path.default.sep) + _chalk.default.bold(basename));
42
+ } // we can fit trimmed dirname and full basename
45
43
 
46
- if ((dirname + _path2.default.sep + basename).length <= maxLength) {
47
- return (0, _slash2.default)(_chalk2.default.dim(dirname + _path2.default.sep) + _chalk2.default.bold(basename));
48
- }
49
44
 
50
- // we can fit trimmed dirname and full basename
51
- var basenameLength = basename.length;
45
+ const basenameLength = basename.length;
46
+
52
47
  if (basenameLength + 4 < maxLength) {
53
- var dirnameLength = maxLength - 4 - basenameLength;
48
+ const dirnameLength = maxLength - 4 - basenameLength;
54
49
  dirname = `...${dirname.slice(dirname.length - dirnameLength, dirname.length)}`;
55
- return (0, _slash2.default)(_chalk2.default.dim(dirname + _path2.default.sep) + _chalk2.default.bold(basename));
50
+ return (0, _slash.default)(_chalk.default.dim(dirname + _path.default.sep) + _chalk.default.bold(basename));
56
51
  }
57
52
 
58
53
  if (basenameLength + 4 === maxLength) {
59
- return (0, _slash2.default)(_chalk2.default.dim(`...${_path2.default.sep}`) + _chalk2.default.bold(basename));
60
- }
54
+ return (0, _slash.default)(_chalk.default.dim(`...${_path.default.sep}`) + _chalk.default.bold(basename));
55
+ } // can't fit dirname, but can fit trimmed basename
61
56
 
62
- // can't fit dirname, but can fit trimmed basename
63
- return (0, _slash2.default)(_chalk2.default.bold(`...${basename.slice(basename.length - maxLength - 4, basename.length)}`));
64
- };
65
57
 
66
- // $FlowFixMe
67
- var getTerminalWidth = exports.getTerminalWidth = function getTerminalWidth() {
68
- return process.stdout.columns;
58
+ return (0, _slash.default)(_chalk.default.bold(`...${basename.slice(basename.length - maxLength - 4, basename.length)}`));
69
59
  };
70
60
 
71
- var highlight = exports.highlight = function highlight(rawPath, filePath, pattern, rootDir) {
72
- var trim = '...';
73
- var relativePathHead = './';
61
+ exports.trimAndFormatPath = trimAndFormatPath;
62
+
63
+ const getTerminalWidth = (pipe = process.stdout) => pipe.columns;
64
+
65
+ exports.getTerminalWidth = getTerminalWidth;
74
66
 
75
- var regexp = void 0;
67
+ const highlight = (rawPath, filePath, pattern, rootDir) => {
68
+ const trim = '...';
69
+ const relativePathHead = './';
70
+ let regexp;
76
71
 
77
72
  try {
78
73
  regexp = new RegExp(pattern, 'i');
79
74
  } catch (e) {
80
- return _chalk2.default.dim(filePath);
75
+ return _chalk.default.dim(filePath);
81
76
  }
82
77
 
83
- rawPath = (0, _stripAnsi2.default)(rawPath);
84
- filePath = (0, _stripAnsi2.default)(filePath);
85
- var match = rawPath.match(regexp);
78
+ rawPath = (0, _stripAnsi.default)(rawPath);
79
+ filePath = (0, _stripAnsi.default)(filePath);
80
+ const match = rawPath.match(regexp);
86
81
 
87
82
  if (!match) {
88
- return _chalk2.default.dim(filePath);
83
+ return _chalk.default.dim(filePath);
89
84
  }
90
85
 
91
- var offset = void 0;
92
- var trimLength = void 0;
86
+ let offset;
87
+ let trimLength;
93
88
 
94
89
  if (filePath.startsWith(trim)) {
95
90
  offset = rawPath.length - filePath.length;
@@ -98,51 +93,54 @@ var highlight = exports.highlight = function highlight(rawPath, filePath, patter
98
93
  offset = rawPath.length - filePath.length;
99
94
  trimLength = relativePathHead.length;
100
95
  } else {
101
- offset = rootDir.length + _path2.default.sep.length;
96
+ offset = rootDir.length + _path.default.sep.length;
102
97
  trimLength = 0;
103
98
  }
104
99
 
105
- var start = match.index - offset;
106
- var end = start + match[0].length;
100
+ const start = match.index - offset;
101
+ const end = start + match[0].length;
107
102
  return colorize(filePath, Math.max(start, 0), Math.max(end, trimLength));
108
103
  };
109
104
 
110
- var DOTS = '...';
111
- var ENTER = '';
105
+ exports.highlight = highlight;
106
+ const DOTS = '...';
107
+ const ENTER = '⏎';
112
108
 
113
- var formatTestNameByPattern = exports.formatTestNameByPattern = function formatTestNameByPattern(testName, pattern, width) {
114
- var inlineTestName = testName.replace(/(\r\n|\n|\r)/gm, ENTER);
115
-
116
- var regexp = void 0;
109
+ const formatTestNameByPattern = (testName, pattern, width) => {
110
+ const inlineTestName = testName.replace(/(\r\n|\n|\r)/gm, ENTER);
111
+ let regexp;
117
112
 
118
113
  try {
119
114
  regexp = new RegExp(pattern, 'i');
120
115
  } catch (e) {
121
- return _chalk2.default.dim(inlineTestName);
116
+ return _chalk.default.dim(inlineTestName);
122
117
  }
123
118
 
124
- var match = inlineTestName.match(regexp);
119
+ const match = inlineTestName.match(regexp);
125
120
 
126
121
  if (!match) {
127
- return _chalk2.default.dim(inlineTestName);
128
- }
122
+ return _chalk.default.dim(inlineTestName);
123
+ } // $FlowFixMe
129
124
 
130
- // $FlowFixMe
131
- var startPatternIndex = Math.max(match.index, 0);
132
- var endPatternIndex = startPatternIndex + match[0].length;
125
+
126
+ const startPatternIndex = Math.max(match.index, 0);
127
+ const endPatternIndex = startPatternIndex + match[0].length;
133
128
 
134
129
  if (inlineTestName.length <= width) {
135
130
  return colorize(inlineTestName, startPatternIndex, endPatternIndex);
136
131
  }
137
132
 
138
- var slicedTestName = inlineTestName.slice(0, width - DOTS.length);
133
+ const slicedTestName = inlineTestName.slice(0, width - DOTS.length);
139
134
 
140
135
  if (startPatternIndex < slicedTestName.length) {
141
136
  if (endPatternIndex > slicedTestName.length) {
142
137
  return colorize(slicedTestName + DOTS, startPatternIndex, slicedTestName.length + DOTS.length);
143
138
  }
139
+
144
140
  return colorize(slicedTestName + DOTS, Math.min(startPatternIndex, slicedTestName.length), endPatternIndex);
145
141
  }
146
142
 
147
- return `${_chalk2.default.dim(slicedTestName)}${_chalk2.default.reset(DOTS)}`;
148
- };
143
+ return `${_chalk.default.dim(slicedTestName)}${_chalk.default.reset(DOTS)}`;
144
+ };
145
+
146
+ exports.formatTestNameByPattern = formatTestNameByPattern;
@@ -3,73 +3,42 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.formatTypeaheadSelection = exports.printTypeaheadItem = exports.printMore = exports.printStartTyping = exports.printRestoredPatternCaret = exports.printPatternCaret = exports.printPatternMatches = undefined;
6
+ exports.formatTypeaheadSelection = exports.printTypeaheadItem = exports.printMore = exports.printStartTyping = exports.printPatternMatches = undefined;
7
7
 
8
8
  var _chalk = require('chalk');
9
9
 
10
10
  var _chalk2 = _interopRequireDefault(_chalk);
11
11
 
12
- var _ansiEscapes = require('ansi-escapes');
13
-
14
- var _ansiEscapes2 = _interopRequireDefault(_ansiEscapes);
15
-
16
- var _stringLength = require('string-length');
17
-
18
- var _stringLength2 = _interopRequireDefault(_stringLength);
19
-
20
12
  var _stripAnsi = require('strip-ansi');
21
13
 
22
14
  var _stripAnsi2 = _interopRequireDefault(_stripAnsi);
23
15
 
24
- var _Prompt = require('../shared/Prompt');
25
-
26
- var _Prompt2 = _interopRequireDefault(_Prompt);
16
+ var _jestWatcher = require('jest-watcher');
27
17
 
28
18
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
29
19
 
30
- var pluralize = function pluralize(count, text) {
31
- return count === 1 ? text : `${text}s`;
32
- };
33
-
34
- var printPatternMatches = exports.printPatternMatches = function printPatternMatches(count, entity, pipe) {
35
- var extraText = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : '';
20
+ const pluralize = (count, text) => count === 1 ? text : `${text}s`;
36
21
 
37
- var pluralized = pluralize(count, entity);
38
- var result = count ? `\n\n Pattern matches ${count} ${pluralized}` : `\n\n Pattern matches no ${pluralized}`;
22
+ const printPatternMatches = exports.printPatternMatches = (count, entity, pipe, extraText = '') => {
23
+ const pluralized = pluralize(count, entity);
24
+ const result = count ? `\n\n Pattern matches ${count} ${pluralized}` : `\n\n Pattern matches no ${pluralized}`;
39
25
 
40
26
  pipe.write(result + extraText);
41
27
  };
42
28
 
43
- var printPatternCaret = exports.printPatternCaret = function printPatternCaret(pattern, pipe) {
44
- var inputText = `${_chalk2.default.dim(' pattern \u203A')} ${pattern}`;
45
-
46
- pipe.write(_ansiEscapes2.default.eraseDown);
47
- pipe.write(inputText);
48
- pipe.write(_ansiEscapes2.default.cursorSavePosition);
49
- };
50
-
51
- var printRestoredPatternCaret = exports.printRestoredPatternCaret = function printRestoredPatternCaret(pattern, currentUsageRows, pipe) {
52
- var inputText = `${_chalk2.default.dim(' pattern \u203A')} ${pattern}`;
53
-
54
- pipe.write(_ansiEscapes2.default.cursorTo((0, _stringLength2.default)(inputText), currentUsageRows - 1));
55
- pipe.write(_ansiEscapes2.default.cursorRestorePosition);
56
- };
57
-
58
- var printStartTyping = exports.printStartTyping = function printStartTyping(entity, pipe) {
29
+ const printStartTyping = exports.printStartTyping = (entity, pipe) => {
59
30
  pipe.write(`\n\n ${_chalk2.default.italic.yellow(`Start typing to filter by a ${entity} regex pattern.`)}`);
60
31
  };
61
32
 
62
- var printMore = exports.printMore = function printMore(entity, pipe, more) {
33
+ const printMore = exports.printMore = (entity, pipe, more) => {
63
34
  pipe.write(`\n ${_chalk2.default.dim(`...and ${more} more ${pluralize(more, entity)}`)}`);
64
35
  };
65
36
 
66
- var printTypeaheadItem = exports.printTypeaheadItem = function printTypeaheadItem(item, pipe) {
67
- return pipe.write(`\n ${_chalk2.default.dim('\u203A')} ${item}`);
68
- };
37
+ const printTypeaheadItem = exports.printTypeaheadItem = (item, pipe) => pipe.write(`\n ${_chalk2.default.dim('\u203A')} ${item}`);
69
38
 
70
- var formatTypeaheadSelection = exports.formatTypeaheadSelection = function formatTypeaheadSelection(item, index, activeIndex, prompt) {
39
+ const formatTypeaheadSelection = exports.formatTypeaheadSelection = (item, index, activeIndex, prompt) => {
71
40
  if (index === activeIndex) {
72
- prompt.setTypheadheadSelection((0, _stripAnsi2.default)(item));
41
+ prompt.setPromptSelection((0, _stripAnsi2.default)(item));
73
42
  return _chalk2.default.black.bgYellow((0, _stripAnsi2.default)(item));
74
43
  }
75
44
  return item;
@@ -5,14 +5,11 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
 
7
7
 
8
- var scroll = function scroll(size, _ref) {
9
- var offset = _ref.offset,
10
- max = _ref.max;
8
+ const scroll = (size, { offset, max }) => {
9
+ let start = 0;
10
+ let index = Math.min(offset, size);
11
11
 
12
- var start = 0;
13
- var index = Math.min(offset, size);
14
-
15
- var halfScreen = max / 2;
12
+ const halfScreen = max / 2;
16
13
 
17
14
  if (index <= halfScreen) {
18
15
  start = 0;
@@ -1,131 +1,91 @@
1
1
  'use strict';
2
2
 
3
- var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
4
-
5
- var _get = function get(object, property, receiver) { if (object === null) object = Function.prototype; var desc = Object.getOwnPropertyDescriptor(object, property); if (desc === undefined) { var parent = Object.getPrototypeOf(object); if (parent === null) { return undefined; } else { return get(parent, property, receiver); } } else if ("value" in desc) { return desc.value; } else { var getter = desc.get; if (getter === undefined) { return undefined; } return getter.call(receiver); } };
6
-
7
3
  var _chalk = require('chalk');
8
4
 
9
5
  var _chalk2 = _interopRequireDefault(_chalk);
10
6
 
7
+ var _jestWatcher = require('jest-watcher');
8
+
11
9
  var _scroll2 = require('./shared/scroll');
12
10
 
13
11
  var _scroll3 = _interopRequireDefault(_scroll2);
14
12
 
15
13
  var _utils = require('./lib/utils');
16
14
 
17
- var _Prompt = require('./shared/Prompt');
18
-
19
- var _Prompt2 = _interopRequireDefault(_Prompt);
20
-
21
15
  var _pattern_mode_helpers = require('./shared/pattern_mode_helpers');
22
16
 
23
- var _pattern_prompt = require('./shared/pattern_prompt');
24
-
25
- var _pattern_prompt2 = _interopRequireDefault(_pattern_prompt);
26
-
27
17
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
28
18
 
29
- function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
19
+ class TestNamePatternPrompt extends _jestWatcher.PatternPrompt {
30
20
 
31
- function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
21
+ constructor(pipe, prompt) {
22
+ super(pipe, prompt);
23
+ this._entityName = 'tests';
24
+ this._cachedTestResults = [];
25
+ }
32
26
 
33
- function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
27
+ _onChange(pattern, options) {
28
+ super._onChange(pattern, options);
29
+ this._printTypeahead(pattern, options);
30
+ }
34
31
 
35
- var TestNamePatternPrompt = function (_PatternPrompt) {
36
- _inherits(TestNamePatternPrompt, _PatternPrompt);
32
+ _printTypeahead(pattern, options) {
33
+ const matchedTests = this._getMatchedTests(pattern);
34
+ const total = matchedTests.length;
35
+ const pipe = this._pipe;
36
+ const prompt = this._prompt;
37
37
 
38
- function TestNamePatternPrompt(pipe, prompt) {
39
- _classCallCheck(this, TestNamePatternPrompt);
38
+ (0, _jestWatcher.printPatternCaret)(pattern, pipe);
40
39
 
41
- var _this = _possibleConstructorReturn(this, (TestNamePatternPrompt.__proto__ || Object.getPrototypeOf(TestNamePatternPrompt)).call(this, pipe, prompt));
40
+ if (pattern) {
41
+ (0, _pattern_mode_helpers.printPatternMatches)(total, 'test', pipe, ` from ${_chalk2.default.yellow('cached')} test suites`);
42
42
 
43
- _this._entityName = 'tests';
44
- _this._cachedTestResults = [];
45
- return _this;
46
- }
43
+ const width = (0, _utils.getTerminalWidth)();
47
44
 
48
- _createClass(TestNamePatternPrompt, [{
49
- key: '_onChange',
50
- value: function _onChange(pattern, options) {
51
- _get(TestNamePatternPrompt.prototype.__proto__ || Object.getPrototypeOf(TestNamePatternPrompt.prototype), '_onChange', this).call(this, pattern, options);
52
- this._printTypeahead(pattern, options);
53
- }
54
- }, {
55
- key: '_printTypeahead',
56
- value: function _printTypeahead(pattern, options) {
57
- var matchedTests = this._getMatchedTests(pattern);
58
- var total = matchedTests.length;
59
- var pipe = this._pipe;
60
- var prompt = this._prompt;
45
+ var _scroll = (0, _scroll3.default)(total, options);
61
46
 
62
- (0, _pattern_mode_helpers.printPatternCaret)(pattern, pipe);
47
+ const start = _scroll.start,
48
+ end = _scroll.end,
49
+ index = _scroll.index;
63
50
 
64
- if (pattern) {
65
- (0, _pattern_mode_helpers.printPatternMatches)(total, 'test', pipe, ` from ${_chalk2.default.yellow('cached')} test suites`);
66
51
 
67
- var width = (0, _utils.getTerminalWidth)();
52
+ prompt.setPromptLength(total);
68
53
 
69
- var _scroll = (0, _scroll3.default)(total, options),
70
- start = _scroll.start,
71
- end = _scroll.end,
72
- index = _scroll.index;
54
+ matchedTests.slice(start, end).map(name => (0, _utils.formatTestNameByPattern)(name, pattern, width - 4)).map((item, i) => (0, _pattern_mode_helpers.formatTypeaheadSelection)(item, i, index, prompt)).forEach(item => (0, _pattern_mode_helpers.printTypeaheadItem)(item, pipe));
73
55
 
74
- prompt.setTypeaheadLength(total);
75
-
76
- matchedTests.slice(start, end).map(function (name) {
77
- return (0, _utils.formatTestNameByPattern)(name, pattern, width - 4);
78
- }).map(function (item, i) {
79
- return (0, _pattern_mode_helpers.formatTypeaheadSelection)(item, i, index, prompt);
80
- }).forEach(function (item) {
81
- return (0, _pattern_mode_helpers.printTypeaheadItem)(item, pipe);
82
- });
83
-
84
- if (total > end) {
85
- (0, _pattern_mode_helpers.printMore)('test', pipe, total - end);
86
- }
87
- } else {
88
- (0, _pattern_mode_helpers.printStartTyping)('test name', pipe);
56
+ if (total > end) {
57
+ (0, _pattern_mode_helpers.printMore)('test', pipe, total - end);
89
58
  }
90
-
91
- (0, _pattern_mode_helpers.printRestoredPatternCaret)(pattern, this._currentUsageRows, pipe);
59
+ } else {
60
+ (0, _pattern_mode_helpers.printStartTyping)('test name', pipe);
92
61
  }
93
- }, {
94
- key: '_getMatchedTests',
95
- value: function _getMatchedTests(pattern) {
96
- var regex = void 0;
97
-
98
- try {
99
- regex = new RegExp(pattern, 'i');
100
- } catch (e) {
101
- return [];
102
- }
103
-
104
- var matchedTests = [];
105
62
 
106
- this._cachedTestResults.forEach(function (_ref) {
107
- var testResults = _ref.testResults;
108
- return testResults.forEach(function (_ref2) {
109
- var title = _ref2.title;
63
+ (0, _jestWatcher.printRestoredPatternCaret)(pattern, this._currentUsageRows, pipe);
64
+ }
110
65
 
111
- if (regex.test(title)) {
112
- matchedTests.push(title);
113
- }
114
- });
115
- });
66
+ _getMatchedTests(pattern) {
67
+ let regex;
116
68
 
117
- return matchedTests;
69
+ try {
70
+ regex = new RegExp(pattern, 'i');
71
+ } catch (e) {
72
+ return [];
118
73
  }
119
- }, {
120
- key: 'updateCachedTestResults',
121
- value: function updateCachedTestResults() {
122
- var testResults = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
123
74
 
124
- this._cachedTestResults = testResults;
125
- }
126
- }]);
75
+ const matchedTests = [];
76
+
77
+ this._cachedTestResults.forEach(({ testResults }) => testResults.forEach(({ title }) => {
78
+ if (regex.test(title)) {
79
+ matchedTests.push(title);
80
+ }
81
+ }));
127
82
 
128
- return TestNamePatternPrompt;
129
- }(_pattern_prompt2.default);
83
+ return matchedTests;
84
+ }
85
+
86
+ updateCachedTestResults(testResults = []) {
87
+ this._cachedTestResults = testResults;
88
+ }
89
+ }
130
90
 
131
91
  module.exports = TestNamePatternPrompt;
@@ -0,0 +1,57 @@
1
+ "use strict";
2
+
3
+ var _jestWatcher = require("jest-watcher");
4
+
5
+ var _prompt = _interopRequireDefault(require("./prompt"));
6
+
7
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
8
+
9
+ class TestNamePlugin {
10
+ constructor({
11
+ stdin,
12
+ stdout,
13
+ config = {}
14
+ }) {
15
+ this._stdin = stdin;
16
+ this._stdout = stdout;
17
+ this._prompt = new _jestWatcher.Prompt();
18
+ this._testResults = [];
19
+ this._usageInfo = {
20
+ key: config.key || 't',
21
+ prompt: config.prompt || 'filter by a test name regex pattern'
22
+ };
23
+ }
24
+
25
+ apply(jestHooks) {
26
+ jestHooks.onTestRunComplete(({
27
+ testResults
28
+ }) => {
29
+ this._testResults = testResults;
30
+ });
31
+ }
32
+
33
+ onKey(key) {
34
+ this._prompt.put(key);
35
+ }
36
+
37
+ run(globalConfig, updateConfigAndRun) {
38
+ const p = new _prompt.default(this._stdout, this._prompt);
39
+ p.updateCachedTestResults(this._testResults);
40
+ return new Promise((res, rej) => {
41
+ p.run(value => {
42
+ updateConfigAndRun({
43
+ mode: 'watch',
44
+ testNamePattern: value
45
+ });
46
+ res();
47
+ }, rej);
48
+ });
49
+ }
50
+
51
+ getUsageInfo() {
52
+ return this._usageInfo;
53
+ }
54
+
55
+ }
56
+
57
+ module.exports = TestNamePlugin;
@@ -0,0 +1,87 @@
1
+ "use strict";
2
+
3
+ var _chalk = _interopRequireDefault(require("chalk"));
4
+
5
+ var _ansiEscapes = _interopRequireDefault(require("ansi-escapes"));
6
+
7
+ var _jestWatcher = require("jest-watcher");
8
+
9
+ var _scroll2 = _interopRequireDefault(require("../lib/scroll"));
10
+
11
+ var _utils = require("../lib/utils");
12
+
13
+ var _pattern_mode_helpers = require("../lib/pattern_mode_helpers");
14
+
15
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
16
+
17
+ class TestNamePatternPrompt extends _jestWatcher.PatternPrompt {
18
+ constructor(pipe, prompt) {
19
+ super(pipe, prompt);
20
+ this._entityName = 'tests';
21
+ this._cachedTestResults = [];
22
+ }
23
+
24
+ _onChange(pattern, options) {
25
+ super._onChange(pattern, options);
26
+
27
+ this._printTypeahead(pattern, options);
28
+ }
29
+
30
+ _printTypeahead(pattern, options) {
31
+ const matchedTests = this._getMatchedTests(pattern);
32
+
33
+ const total = matchedTests.length;
34
+ const pipe = this._pipe;
35
+ const prompt = this._prompt;
36
+ (0, _jestWatcher.printPatternCaret)(pattern, pipe);
37
+ pipe.write(_ansiEscapes.default.cursorLeft);
38
+
39
+ if (pattern) {
40
+ (0, _pattern_mode_helpers.printPatternMatches)(total, 'test', pipe, ` from ${_chalk.default.yellow('cached')} test suites`);
41
+ const width = (0, _utils.getTerminalWidth)(pipe);
42
+
43
+ const _scroll = (0, _scroll2.default)(total, options),
44
+ start = _scroll.start,
45
+ end = _scroll.end,
46
+ index = _scroll.index;
47
+
48
+ prompt.setPromptLength(total);
49
+ matchedTests.slice(start, end).map(name => (0, _utils.formatTestNameByPattern)(name, pattern, width - 4)).map((item, i) => (0, _pattern_mode_helpers.formatTypeaheadSelection)(item, i, index, prompt)).forEach(item => (0, _pattern_mode_helpers.printTypeaheadItem)(item, pipe));
50
+
51
+ if (total > end) {
52
+ (0, _pattern_mode_helpers.printMore)('test', pipe, total - end);
53
+ }
54
+ } else {
55
+ (0, _pattern_mode_helpers.printStartTyping)('test name', pipe);
56
+ }
57
+
58
+ (0, _jestWatcher.printRestoredPatternCaret)(pattern, this._currentUsageRows, pipe);
59
+ }
60
+
61
+ _getMatchedTests(pattern) {
62
+ let regex;
63
+
64
+ try {
65
+ regex = new RegExp(pattern, 'i');
66
+ } catch (e) {
67
+ return [];
68
+ }
69
+
70
+ return this._cachedTestResults.reduce((matchedTests, {
71
+ testResults
72
+ }) => {
73
+ return matchedTests.concat(testResults.filter(({
74
+ title
75
+ }) => regex.test(title)).map(({
76
+ title
77
+ }) => title));
78
+ }, []);
79
+ }
80
+
81
+ updateCachedTestResults(testResults = []) {
82
+ this._cachedTestResults = testResults;
83
+ }
84
+
85
+ }
86
+
87
+ module.exports = TestNamePatternPrompt;