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,147 +0,0 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
-
7
- 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; }; }();
8
-
9
- 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); } };
10
-
11
- var _chalk = require('chalk');
12
-
13
- var _chalk2 = _interopRequireDefault(_chalk);
14
-
15
- var _stringLength = require('string-length');
16
-
17
- var _stringLength2 = _interopRequireDefault(_stringLength);
18
-
19
- var _utils = require('./lib/utils');
20
-
21
- var _Prompt = require('./shared/Prompt');
22
-
23
- var _Prompt2 = _interopRequireDefault(_Prompt);
24
-
25
- var _pattern_mode_helpers = require('./shared/pattern_mode_helpers');
26
-
27
- var _scroll2 = require('./shared/scroll');
28
-
29
- var _scroll3 = _interopRequireDefault(_scroll2);
30
-
31
- var _pattern_prompt = require('./shared/pattern_prompt');
32
-
33
- var _pattern_prompt2 = _interopRequireDefault(_pattern_prompt);
34
-
35
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
36
-
37
- function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
38
-
39
- 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; }
40
-
41
- 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; }
42
-
43
- var TestPathPatternPrompt = function (_PatternPrompt) {
44
- _inherits(TestPathPatternPrompt, _PatternPrompt);
45
-
46
- function TestPathPatternPrompt(pipe, prompt) {
47
- _classCallCheck(this, TestPathPatternPrompt);
48
-
49
- var _this = _possibleConstructorReturn(this, (TestPathPatternPrompt.__proto__ || Object.getPrototypeOf(TestPathPatternPrompt)).call(this, pipe, prompt));
50
-
51
- _this._entityName = 'filenames';
52
- _this._searchSources = [];
53
- return _this;
54
- }
55
-
56
- _createClass(TestPathPatternPrompt, [{
57
- key: '_onChange',
58
- value: function _onChange(pattern, options) {
59
- _get(TestPathPatternPrompt.prototype.__proto__ || Object.getPrototypeOf(TestPathPatternPrompt.prototype), '_onChange', this).call(this, pattern, options);
60
- this._printTypeahead(pattern, options);
61
- }
62
- }, {
63
- key: '_printTypeahead',
64
- value: function _printTypeahead(pattern, options) {
65
- var matchedTests = this._getMatchedTests(pattern);
66
- var total = matchedTests.length;
67
- var pipe = this._pipe;
68
- var prompt = this._prompt;
69
-
70
- (0, _pattern_mode_helpers.printPatternCaret)(pattern, pipe);
71
-
72
- if (pattern) {
73
- (0, _pattern_mode_helpers.printPatternMatches)(total, 'file', pipe);
74
-
75
- var prefix = ` ${_chalk2.default.dim('\u203A')} `;
76
- var padding = (0, _stringLength2.default)(prefix) + 2;
77
- var width = (0, _utils.getTerminalWidth)();
78
-
79
- var _scroll = (0, _scroll3.default)(total, options),
80
- start = _scroll.start,
81
- end = _scroll.end,
82
- index = _scroll.index;
83
-
84
- prompt.setTypeaheadLength(total);
85
-
86
- matchedTests.slice(start, end).map(function (_ref) {
87
- var path = _ref.path,
88
- context = _ref.context;
89
-
90
- var filePath = (0, _utils.trimAndFormatPath)(padding, context.config, path, width);
91
- return (0, _utils.highlight)(path, filePath, pattern, context.config.rootDir);
92
- }).map(function (item, i) {
93
- return (0, _pattern_mode_helpers.formatTypeaheadSelection)(item, i, index, prompt);
94
- }).forEach(function (item) {
95
- return (0, _pattern_mode_helpers.printTypeaheadItem)(item, pipe);
96
- });
97
-
98
- if (total > end) {
99
- (0, _pattern_mode_helpers.printMore)('file', pipe, total - end);
100
- }
101
- } else {
102
- (0, _pattern_mode_helpers.printStartTyping)('filename', pipe);
103
- }
104
-
105
- (0, _pattern_mode_helpers.printRestoredPatternCaret)(pattern, this._currentUsageRows, pipe);
106
- }
107
- }, {
108
- key: '_getMatchedTests',
109
- value: function _getMatchedTests(pattern) {
110
- var regex = void 0;
111
-
112
- try {
113
- regex = new RegExp(pattern, 'i');
114
- } catch (e) {
115
- regex = null;
116
- }
117
-
118
- var tests = [];
119
- if (regex) {
120
- this._searchSources.forEach(function (_ref2) {
121
- var testPaths = _ref2.testPaths,
122
- config = _ref2.config;
123
-
124
- tests = tests.concat(testPaths.filter(function (testPath) {
125
- return testPath.match(pattern);
126
- }).map(function (path) {
127
- return {
128
- path,
129
- context: { config }
130
- };
131
- }));
132
- });
133
- }
134
-
135
- return tests;
136
- }
137
- }, {
138
- key: 'updateSearchSources',
139
- value: function updateSearchSources(searchSources) {
140
- this._searchSources = searchSources;
141
- }
142
- }]);
143
-
144
- return TestPathPatternPrompt;
145
- }(_pattern_prompt2.default);
146
-
147
- exports.default = TestPathPatternPrompt;
@@ -1,74 +0,0 @@
1
- 'use strict';
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 _Prompt = require('./shared/Prompt');
6
-
7
- var _Prompt2 = _interopRequireDefault(_Prompt);
8
-
9
- var _test_path_pattern_prompt = require('./test_path_pattern_prompt');
10
-
11
- var _test_path_pattern_prompt2 = _interopRequireDefault(_test_path_pattern_prompt);
12
-
13
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
14
-
15
- function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
16
-
17
- var TestPathPlugin = function () {
18
- function TestPathPlugin(_ref) {
19
- var stdin = _ref.stdin,
20
- stdout = _ref.stdout;
21
-
22
- _classCallCheck(this, TestPathPlugin);
23
-
24
- this._stdin = stdin;
25
- this._stdout = stdout;
26
- this._prompt = new _Prompt2.default();
27
- this._projects = [];
28
- }
29
-
30
- _createClass(TestPathPlugin, [{
31
- key: 'apply',
32
- value: function apply(jestHooks) {
33
- var _this = this;
34
-
35
- jestHooks.onFileChange(function (_ref2) {
36
- var projects = _ref2.projects;
37
-
38
- _this._projects = projects;
39
- });
40
- }
41
- }, {
42
- key: 'onKey',
43
- value: function onKey(key) {
44
- this._prompt.put(key);
45
- }
46
- }, {
47
- key: 'run',
48
- value: function run(globalConfig, updateConfigAndRun) {
49
- var p = new _test_path_pattern_prompt2.default(this._stdout, this._prompt);
50
- p.updateSearchSources(this._projects);
51
- return new Promise(function (res, rej) {
52
- p.run(function (value) {
53
- updateConfigAndRun({ mode: 'watch', testPathPattern: value });
54
- res();
55
- }, rej);
56
- });
57
- }
58
-
59
- // eslint-disable-next-line class-methods-use-this
60
-
61
- }, {
62
- key: 'getUsageInfo',
63
- value: function getUsageInfo() {
64
- return {
65
- key: 'p',
66
- prompt: 'filter by a filename regex pattern'
67
- };
68
- }
69
- }]);
70
-
71
- return TestPathPlugin;
72
- }();
73
-
74
- module.exports = TestPathPlugin;