jest-watch-typeahead 0.2.0 → 0.3.0
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.
- package/CHANGELOG.md +17 -0
- package/build/file_name_plugin/plugin.js +12 -9
- package/build/file_name_plugin/prompt.js +29 -25
- package/build/lib/pattern_mode_helpers.js +26 -20
- package/build/lib/scroll.js +8 -4
- package/build/lib/utils.js +58 -54
- package/build/test_name_plugin/plugin.js +12 -9
- package/build/test_name_plugin/prompt.js +22 -20
- package/build/test_utils/pluginTester.js +33 -9
- package/package.json +23 -19
- package/build/__tests__/pluginTester.js +0 -47
- package/build/file_name_pattern_prompt.js +0 -105
- package/build/file_name_plugin.js +0 -54
- package/build/shared/pattern_mode_helpers.js +0 -45
- package/build/shared/scroll.js +0 -30
- package/build/test_name_pattern_prompt.js +0 -91
- package/build/test_name_plugin.js +0 -54
package/CHANGELOG.md
CHANGED
@@ -1,5 +1,22 @@
|
|
1
1
|
## master
|
2
2
|
|
3
|
+
### Chore & Maintenance
|
4
|
+
|
5
|
+
- Bump dated dependencies ([#25](https://github.com/jest-community/jest-watch-typeahead/pull/25))
|
6
|
+
- Get better truncation for testname typeahead by truncating the start and not the end ([#28](https://github.com/jest-community/jest-watch-typeahead/pull/28))
|
7
|
+
|
8
|
+
### Fixes
|
9
|
+
|
10
|
+
- Use fullName(to show ancestor titles) for test name pattern plugin ([#26](https://github.com/jest-community/jest-watch-typeahead/pull/26))
|
11
|
+
|
12
|
+
## 0.2.1
|
13
|
+
|
14
|
+
- Fix cursor in terminal app ([#21](https://github.com/jest-community/jest-watch-typeahead/pull/21))
|
15
|
+
|
16
|
+
### Chore & Maintenance
|
17
|
+
|
18
|
+
- Bump dated dependencies ([#23](https://github.com/jest-community/jest-watch-typeahead/pull/23))
|
19
|
+
|
3
20
|
## 0.2.0
|
4
21
|
|
5
22
|
### Features
|
@@ -1,15 +1,12 @@
|
|
1
|
-
|
1
|
+
"use strict";
|
2
2
|
|
3
|
-
var _jestWatcher = require(
|
3
|
+
var _jestWatcher = require("jest-watcher");
|
4
4
|
|
5
|
-
var _prompt = require(
|
6
|
-
|
7
|
-
var _prompt2 = _interopRequireDefault(_prompt);
|
5
|
+
var _prompt = _interopRequireDefault(require("./prompt"));
|
8
6
|
|
9
7
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
10
8
|
|
11
9
|
class FileNamePlugin {
|
12
|
-
|
13
10
|
constructor({
|
14
11
|
stdin,
|
15
12
|
stdout,
|
@@ -26,7 +23,9 @@ class FileNamePlugin {
|
|
26
23
|
}
|
27
24
|
|
28
25
|
apply(jestHooks) {
|
29
|
-
jestHooks.onFileChange(({
|
26
|
+
jestHooks.onFileChange(({
|
27
|
+
projects
|
28
|
+
}) => {
|
30
29
|
this._projects = projects;
|
31
30
|
});
|
32
31
|
}
|
@@ -36,11 +35,14 @@ class FileNamePlugin {
|
|
36
35
|
}
|
37
36
|
|
38
37
|
run(globalConfig, updateConfigAndRun) {
|
39
|
-
const p = new
|
38
|
+
const p = new _prompt.default(this._stdout, this._prompt);
|
40
39
|
p.updateSearchSources(this._projects);
|
41
40
|
return new Promise((res, rej) => {
|
42
41
|
p.run(value => {
|
43
|
-
updateConfigAndRun({
|
42
|
+
updateConfigAndRun({
|
43
|
+
mode: 'watch',
|
44
|
+
testPathPattern: value
|
45
|
+
});
|
44
46
|
res();
|
45
47
|
}, rej);
|
46
48
|
});
|
@@ -49,6 +51,7 @@ class FileNamePlugin {
|
|
49
51
|
getUsageInfo() {
|
50
52
|
return this._usageInfo;
|
51
53
|
}
|
54
|
+
|
52
55
|
}
|
53
56
|
|
54
57
|
module.exports = FileNamePlugin;
|
@@ -1,31 +1,27 @@
|
|
1
|
-
|
1
|
+
"use strict";
|
2
2
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
4
4
|
value: true
|
5
5
|
});
|
6
|
+
exports.default = void 0;
|
6
7
|
|
7
|
-
var _chalk = require(
|
8
|
+
var _chalk = _interopRequireDefault(require("chalk"));
|
8
9
|
|
9
|
-
var
|
10
|
+
var _ansiEscapes = _interopRequireDefault(require("ansi-escapes"));
|
10
11
|
|
11
|
-
var _stringLength = require(
|
12
|
+
var _stringLength = _interopRequireDefault(require("string-length"));
|
12
13
|
|
13
|
-
var
|
14
|
+
var _jestWatcher = require("jest-watcher");
|
14
15
|
|
15
|
-
var
|
16
|
+
var _utils = require("../lib/utils");
|
16
17
|
|
17
|
-
var
|
18
|
+
var _pattern_mode_helpers = require("../lib/pattern_mode_helpers");
|
18
19
|
|
19
|
-
var
|
20
|
-
|
21
|
-
var _scroll2 = require('../lib/scroll');
|
22
|
-
|
23
|
-
var _scroll3 = _interopRequireDefault(_scroll2);
|
20
|
+
var _scroll2 = _interopRequireDefault(require("../lib/scroll"));
|
24
21
|
|
25
22
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
26
23
|
|
27
24
|
class FileNamePatternPrompt extends _jestWatcher.PatternPrompt {
|
28
|
-
|
29
25
|
constructor(pipe, prompt) {
|
30
26
|
super(pipe, prompt);
|
31
27
|
this._entityName = 'filenames';
|
@@ -34,34 +30,35 @@ class FileNamePatternPrompt extends _jestWatcher.PatternPrompt {
|
|
34
30
|
|
35
31
|
_onChange(pattern, options) {
|
36
32
|
super._onChange(pattern, options);
|
33
|
+
|
37
34
|
this._printTypeahead(pattern, options);
|
38
35
|
}
|
39
36
|
|
40
37
|
_printTypeahead(pattern, options) {
|
41
38
|
const matchedTests = this._getMatchedTests(pattern);
|
39
|
+
|
42
40
|
const total = matchedTests.length;
|
43
41
|
const pipe = this._pipe;
|
44
42
|
const prompt = this._prompt;
|
45
|
-
|
46
43
|
(0, _jestWatcher.printPatternCaret)(pattern, pipe);
|
44
|
+
pipe.write(_ansiEscapes.default.cursorLeft);
|
47
45
|
|
48
46
|
if (pattern) {
|
49
47
|
(0, _pattern_mode_helpers.printPatternMatches)(total, 'file', pipe);
|
50
|
-
|
51
|
-
const
|
52
|
-
const padding = (0, _stringLength2.default)(prefix) + 2;
|
48
|
+
const prefix = ` ${_chalk.default.dim('\u203A')} `;
|
49
|
+
const padding = (0, _stringLength.default)(prefix) + 2;
|
53
50
|
const width = (0, _utils.getTerminalWidth)(pipe);
|
54
51
|
|
55
|
-
|
56
|
-
|
57
|
-
const start = _scroll.start,
|
52
|
+
const _scroll = (0, _scroll2.default)(total, options),
|
53
|
+
start = _scroll.start,
|
58
54
|
end = _scroll.end,
|
59
55
|
index = _scroll.index;
|
60
56
|
|
61
|
-
|
62
57
|
prompt.setPromptLength(total);
|
63
|
-
|
64
|
-
|
58
|
+
matchedTests.slice(start, end).map(({
|
59
|
+
path,
|
60
|
+
context
|
61
|
+
}) => {
|
65
62
|
const filePath = (0, _utils.trimAndFormatPath)(padding, context.config, path, width);
|
66
63
|
return (0, _utils.highlight)(path, filePath, pattern, context.config.rootDir);
|
67
64
|
}).map((item, i) => (0, _pattern_mode_helpers.formatTypeaheadSelection)(item, i, index, prompt)).forEach(item => (0, _pattern_mode_helpers.printTypeaheadItem)(item, pipe));
|
@@ -85,10 +82,15 @@ class FileNamePatternPrompt extends _jestWatcher.PatternPrompt {
|
|
85
82
|
return [];
|
86
83
|
}
|
87
84
|
|
88
|
-
return this._searchSources.reduce((tests, {
|
85
|
+
return this._searchSources.reduce((tests, {
|
86
|
+
testPaths,
|
87
|
+
config
|
88
|
+
}) => {
|
89
89
|
return tests.concat(testPaths.filter(testPath => regex.test(testPath)).map(path => ({
|
90
90
|
path,
|
91
|
-
context: {
|
91
|
+
context: {
|
92
|
+
config
|
93
|
+
}
|
92
94
|
})));
|
93
95
|
}, []);
|
94
96
|
}
|
@@ -96,5 +98,7 @@ class FileNamePatternPrompt extends _jestWatcher.PatternPrompt {
|
|
96
98
|
updateSearchSources(searchSources) {
|
97
99
|
this._searchSources = searchSources;
|
98
100
|
}
|
101
|
+
|
99
102
|
}
|
103
|
+
|
100
104
|
exports.default = FileNamePatternPrompt;
|
@@ -1,45 +1,51 @@
|
|
1
|
-
|
1
|
+
"use strict";
|
2
2
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
4
4
|
value: true
|
5
5
|
});
|
6
|
-
exports.formatTypeaheadSelection = exports.printTypeaheadItem = exports.printMore = exports.printStartTyping = exports.printPatternMatches =
|
6
|
+
exports.formatTypeaheadSelection = exports.printTypeaheadItem = exports.printMore = exports.printStartTyping = exports.printPatternMatches = void 0;
|
7
7
|
|
8
|
-
var _chalk = require(
|
8
|
+
var _chalk = _interopRequireDefault(require("chalk"));
|
9
9
|
|
10
|
-
var
|
10
|
+
var _stripAnsi = _interopRequireDefault(require("strip-ansi"));
|
11
11
|
|
12
|
-
var
|
13
|
-
|
14
|
-
var _stripAnsi2 = _interopRequireDefault(_stripAnsi);
|
15
|
-
|
16
|
-
var _jestWatcher = require('jest-watcher');
|
12
|
+
var _jestWatcher = require("jest-watcher");
|
17
13
|
|
18
14
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
19
15
|
|
20
16
|
const pluralize = (count, text) => count === 1 ? text : `${text}s`;
|
21
17
|
|
22
|
-
const printPatternMatches =
|
18
|
+
const printPatternMatches = (count, entity, pipe, extraText = '') => {
|
23
19
|
const pluralized = pluralize(count, entity);
|
24
20
|
const result = count ? `\n\n Pattern matches ${count} ${pluralized}` : `\n\n Pattern matches no ${pluralized}`;
|
25
|
-
|
26
21
|
pipe.write(result + extraText);
|
27
22
|
};
|
28
23
|
|
29
|
-
|
30
|
-
|
24
|
+
exports.printPatternMatches = printPatternMatches;
|
25
|
+
|
26
|
+
const printStartTyping = (entity, pipe) => {
|
27
|
+
pipe.write(`\n\n ${_chalk.default.italic.yellow(`Start typing to filter by a ${entity} regex pattern.`)}`);
|
31
28
|
};
|
32
29
|
|
33
|
-
|
34
|
-
|
30
|
+
exports.printStartTyping = printStartTyping;
|
31
|
+
|
32
|
+
const printMore = (entity, pipe, more) => {
|
33
|
+
pipe.write(`\n ${_chalk.default.dim(`...and ${more} more ${pluralize(more, entity)}`)}`);
|
35
34
|
};
|
36
35
|
|
37
|
-
|
36
|
+
exports.printMore = printMore;
|
38
37
|
|
39
|
-
const
|
38
|
+
const printTypeaheadItem = (item, pipe) => pipe.write(`\n ${_chalk.default.dim('\u203A')} ${item}`);
|
39
|
+
|
40
|
+
exports.printTypeaheadItem = printTypeaheadItem;
|
41
|
+
|
42
|
+
const formatTypeaheadSelection = (item, index, activeIndex, prompt) => {
|
40
43
|
if (index === activeIndex) {
|
41
|
-
prompt.setPromptSelection((0,
|
42
|
-
return
|
44
|
+
prompt.setPromptSelection((0, _stripAnsi.default)(item));
|
45
|
+
return _chalk.default.black.bgYellow((0, _stripAnsi.default)(item));
|
43
46
|
}
|
47
|
+
|
44
48
|
return item;
|
45
|
-
};
|
49
|
+
};
|
50
|
+
|
51
|
+
exports.formatTypeaheadSelection = formatTypeaheadSelection;
|
package/build/lib/scroll.js
CHANGED
@@ -3,12 +3,14 @@
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
4
4
|
value: true
|
5
5
|
});
|
6
|
+
exports.default = void 0;
|
6
7
|
|
7
|
-
|
8
|
-
|
8
|
+
const scroll = (size, {
|
9
|
+
offset,
|
10
|
+
max
|
11
|
+
}) => {
|
9
12
|
let start = 0;
|
10
13
|
let index = Math.min(offset, size);
|
11
|
-
|
12
14
|
const halfScreen = max / 2;
|
13
15
|
|
14
16
|
if (index <= halfScreen) {
|
@@ -17,6 +19,7 @@ const scroll = (size, { offset, max }) => {
|
|
17
19
|
if (size >= max) {
|
18
20
|
start = Math.min(index - halfScreen - 1, size - max);
|
19
21
|
}
|
22
|
+
|
20
23
|
index = Math.min(index - start, size);
|
21
24
|
}
|
22
25
|
|
@@ -27,4 +30,5 @@ const scroll = (size, { offset, max }) => {
|
|
27
30
|
};
|
28
31
|
};
|
29
32
|
|
30
|
-
|
33
|
+
var _default = scroll;
|
34
|
+
exports.default = _default;
|
package/build/lib/utils.js
CHANGED
@@ -1,86 +1,86 @@
|
|
1
|
-
|
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 =
|
6
|
+
exports.formatTestNameByPattern = exports.highlight = exports.getTerminalWidth = exports.trimAndFormatPath = void 0;
|
7
7
|
|
8
|
-
var _path = require(
|
8
|
+
var _path = _interopRequireDefault(require("path"));
|
9
9
|
|
10
|
-
var
|
10
|
+
var _chalk = _interopRequireDefault(require("chalk"));
|
11
11
|
|
12
|
-
var
|
12
|
+
var _slash = _interopRequireDefault(require("slash"));
|
13
13
|
|
14
|
-
var
|
15
|
-
|
16
|
-
var _slash = require('slash');
|
17
|
-
|
18
|
-
var _slash2 = _interopRequireDefault(_slash);
|
19
|
-
|
20
|
-
var _stripAnsi = require('strip-ansi');
|
21
|
-
|
22
|
-
var _stripAnsi2 = _interopRequireDefault(_stripAnsi);
|
14
|
+
var _stripAnsi = _interopRequireDefault(require("strip-ansi"));
|
23
15
|
|
24
16
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
25
17
|
|
26
18
|
/* eslint-disable no-param-reassign */
|
27
19
|
const relativePath = (config, testPath) => {
|
28
|
-
testPath =
|
29
|
-
|
30
|
-
const
|
31
|
-
|
20
|
+
testPath = _path.default.relative(config.cwd || config.rootDir, testPath);
|
21
|
+
|
22
|
+
const dirname = _path.default.dirname(testPath);
|
23
|
+
|
24
|
+
const basename = _path.default.basename(testPath);
|
25
|
+
|
26
|
+
return {
|
27
|
+
basename,
|
28
|
+
dirname
|
29
|
+
};
|
32
30
|
};
|
33
31
|
|
34
|
-
const colorize = (str, start, end) =>
|
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));
|
35
33
|
|
36
|
-
const trimAndFormatPath =
|
34
|
+
const trimAndFormatPath = (pad, config, testPath, columns) => {
|
37
35
|
const maxLength = columns - pad;
|
38
36
|
const relative = relativePath(config, testPath);
|
39
37
|
const basename = relative.basename;
|
40
|
-
let dirname = relative.dirname;
|
38
|
+
let dirname = relative.dirname; // length is ok
|
41
39
|
|
42
|
-
|
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
|
43
43
|
|
44
|
-
if ((dirname + _path2.default.sep + basename).length <= maxLength) {
|
45
|
-
return (0, _slash2.default)(_chalk2.default.dim(dirname + _path2.default.sep) + _chalk2.default.bold(basename));
|
46
|
-
}
|
47
44
|
|
48
|
-
// we can fit trimmed dirname and full basename
|
49
45
|
const basenameLength = basename.length;
|
46
|
+
|
50
47
|
if (basenameLength + 4 < maxLength) {
|
51
48
|
const dirnameLength = maxLength - 4 - basenameLength;
|
52
49
|
dirname = `...${dirname.slice(dirname.length - dirnameLength, dirname.length)}`;
|
53
|
-
return (0,
|
50
|
+
return (0, _slash.default)(_chalk.default.dim(dirname + _path.default.sep) + _chalk.default.bold(basename));
|
54
51
|
}
|
55
52
|
|
56
53
|
if (basenameLength + 4 === maxLength) {
|
57
|
-
return (0,
|
58
|
-
}
|
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
|
59
56
|
|
60
|
-
|
61
|
-
return (0,
|
57
|
+
|
58
|
+
return (0, _slash.default)(_chalk.default.bold(`...${basename.slice(basename.length - maxLength - 4, basename.length)}`));
|
62
59
|
};
|
63
60
|
|
64
|
-
|
61
|
+
exports.trimAndFormatPath = trimAndFormatPath;
|
62
|
+
|
63
|
+
const getTerminalWidth = (pipe = process.stdout) => pipe.columns;
|
64
|
+
|
65
|
+
exports.getTerminalWidth = getTerminalWidth;
|
65
66
|
|
66
|
-
const highlight =
|
67
|
+
const highlight = (rawPath, filePath, pattern, rootDir) => {
|
67
68
|
const trim = '...';
|
68
69
|
const relativePathHead = './';
|
69
|
-
|
70
70
|
let regexp;
|
71
71
|
|
72
72
|
try {
|
73
73
|
regexp = new RegExp(pattern, 'i');
|
74
74
|
} catch (e) {
|
75
|
-
return
|
75
|
+
return _chalk.default.dim(filePath);
|
76
76
|
}
|
77
77
|
|
78
|
-
rawPath = (0,
|
79
|
-
filePath = (0,
|
78
|
+
rawPath = (0, _stripAnsi.default)(rawPath);
|
79
|
+
filePath = (0, _stripAnsi.default)(filePath);
|
80
80
|
const match = rawPath.match(regexp);
|
81
81
|
|
82
82
|
if (!match) {
|
83
|
-
return
|
83
|
+
return _chalk.default.dim(filePath);
|
84
84
|
}
|
85
85
|
|
86
86
|
let offset;
|
@@ -93,7 +93,7 @@ const highlight = exports.highlight = (rawPath, filePath, pattern, rootDir) => {
|
|
93
93
|
offset = rawPath.length - filePath.length;
|
94
94
|
trimLength = relativePathHead.length;
|
95
95
|
} else {
|
96
|
-
offset = rootDir.length +
|
96
|
+
offset = rootDir.length + _path.default.sep.length;
|
97
97
|
trimLength = 0;
|
98
98
|
}
|
99
99
|
|
@@ -102,42 +102,46 @@ const highlight = exports.highlight = (rawPath, filePath, pattern, rootDir) => {
|
|
102
102
|
return colorize(filePath, Math.max(start, 0), Math.max(end, trimLength));
|
103
103
|
};
|
104
104
|
|
105
|
+
exports.highlight = highlight;
|
105
106
|
const DOTS = '...';
|
106
107
|
const ENTER = '⏎';
|
107
108
|
|
108
|
-
const formatTestNameByPattern =
|
109
|
+
const formatTestNameByPattern = (testName, pattern, width) => {
|
109
110
|
const inlineTestName = testName.replace(/(\r\n|\n|\r)/gm, ENTER);
|
110
|
-
|
111
111
|
let regexp;
|
112
112
|
|
113
113
|
try {
|
114
114
|
regexp = new RegExp(pattern, 'i');
|
115
115
|
} catch (e) {
|
116
|
-
return
|
116
|
+
return _chalk.default.dim(inlineTestName);
|
117
117
|
}
|
118
118
|
|
119
119
|
const match = inlineTestName.match(regexp);
|
120
120
|
|
121
121
|
if (!match) {
|
122
|
-
return
|
123
|
-
}
|
122
|
+
return _chalk.default.dim(inlineTestName);
|
123
|
+
} // $FlowFixMe
|
124
|
+
|
124
125
|
|
125
|
-
// $FlowFixMe
|
126
126
|
const startPatternIndex = Math.max(match.index, 0);
|
127
127
|
const endPatternIndex = startPatternIndex + match[0].length;
|
128
|
+
const testNameFitsInTerminal = inlineTestName.length <= width;
|
128
129
|
|
129
|
-
if (
|
130
|
+
if (testNameFitsInTerminal) {
|
130
131
|
return colorize(inlineTestName, startPatternIndex, endPatternIndex);
|
131
132
|
}
|
132
133
|
|
133
|
-
const
|
134
|
+
const numberOfTruncatedChars = DOTS.length + inlineTestName.length - width;
|
135
|
+
const end = Math.max(endPatternIndex - numberOfTruncatedChars, 0);
|
136
|
+
const truncatedTestName = inlineTestName.slice(numberOfTruncatedChars);
|
137
|
+
const shouldHighlightDots = startPatternIndex <= numberOfTruncatedChars;
|
134
138
|
|
135
|
-
if (
|
136
|
-
|
137
|
-
return colorize(slicedTestName + DOTS, startPatternIndex, slicedTestName.length + DOTS.length);
|
138
|
-
}
|
139
|
-
return colorize(slicedTestName + DOTS, Math.min(startPatternIndex, slicedTestName.length), endPatternIndex);
|
139
|
+
if (shouldHighlightDots) {
|
140
|
+
return colorize(DOTS + truncatedTestName, 0, end + DOTS.length);
|
140
141
|
}
|
141
142
|
|
142
|
-
|
143
|
-
|
143
|
+
const start = startPatternIndex - numberOfTruncatedChars;
|
144
|
+
return colorize(DOTS + truncatedTestName, start + DOTS.length, end + DOTS.length);
|
145
|
+
};
|
146
|
+
|
147
|
+
exports.formatTestNameByPattern = formatTestNameByPattern;
|
@@ -1,15 +1,12 @@
|
|
1
|
-
|
1
|
+
"use strict";
|
2
2
|
|
3
|
-
var _jestWatcher = require(
|
3
|
+
var _jestWatcher = require("jest-watcher");
|
4
4
|
|
5
|
-
var _prompt = require(
|
6
|
-
|
7
|
-
var _prompt2 = _interopRequireDefault(_prompt);
|
5
|
+
var _prompt = _interopRequireDefault(require("./prompt"));
|
8
6
|
|
9
7
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
10
8
|
|
11
9
|
class TestNamePlugin {
|
12
|
-
|
13
10
|
constructor({
|
14
11
|
stdin,
|
15
12
|
stdout,
|
@@ -26,7 +23,9 @@ class TestNamePlugin {
|
|
26
23
|
}
|
27
24
|
|
28
25
|
apply(jestHooks) {
|
29
|
-
jestHooks.onTestRunComplete(({
|
26
|
+
jestHooks.onTestRunComplete(({
|
27
|
+
testResults
|
28
|
+
}) => {
|
30
29
|
this._testResults = testResults;
|
31
30
|
});
|
32
31
|
}
|
@@ -36,11 +35,14 @@ class TestNamePlugin {
|
|
36
35
|
}
|
37
36
|
|
38
37
|
run(globalConfig, updateConfigAndRun) {
|
39
|
-
const p = new
|
38
|
+
const p = new _prompt.default(this._stdout, this._prompt);
|
40
39
|
p.updateCachedTestResults(this._testResults);
|
41
40
|
return new Promise((res, rej) => {
|
42
41
|
p.run(value => {
|
43
|
-
updateConfigAndRun({
|
42
|
+
updateConfigAndRun({
|
43
|
+
mode: 'watch',
|
44
|
+
testNamePattern: value
|
45
|
+
});
|
44
46
|
res();
|
45
47
|
}, rej);
|
46
48
|
});
|
@@ -49,6 +51,7 @@ class TestNamePlugin {
|
|
49
51
|
getUsageInfo() {
|
50
52
|
return this._usageInfo;
|
51
53
|
}
|
54
|
+
|
52
55
|
}
|
53
56
|
|
54
57
|
module.exports = TestNamePlugin;
|
@@ -1,23 +1,20 @@
|
|
1
|
-
|
1
|
+
"use strict";
|
2
2
|
|
3
|
-
var _chalk = require(
|
3
|
+
var _chalk = _interopRequireDefault(require("chalk"));
|
4
4
|
|
5
|
-
var
|
5
|
+
var _ansiEscapes = _interopRequireDefault(require("ansi-escapes"));
|
6
6
|
|
7
|
-
var _jestWatcher = require(
|
7
|
+
var _jestWatcher = require("jest-watcher");
|
8
8
|
|
9
|
-
var _scroll2 = require(
|
9
|
+
var _scroll2 = _interopRequireDefault(require("../lib/scroll"));
|
10
10
|
|
11
|
-
var
|
11
|
+
var _utils = require("../lib/utils");
|
12
12
|
|
13
|
-
var
|
14
|
-
|
15
|
-
var _pattern_mode_helpers = require('../lib/pattern_mode_helpers');
|
13
|
+
var _pattern_mode_helpers = require("../lib/pattern_mode_helpers");
|
16
14
|
|
17
15
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
18
16
|
|
19
17
|
class TestNamePatternPrompt extends _jestWatcher.PatternPrompt {
|
20
|
-
|
21
18
|
constructor(pipe, prompt) {
|
22
19
|
super(pipe, prompt);
|
23
20
|
this._entityName = 'tests';
|
@@ -26,31 +23,29 @@ class TestNamePatternPrompt extends _jestWatcher.PatternPrompt {
|
|
26
23
|
|
27
24
|
_onChange(pattern, options) {
|
28
25
|
super._onChange(pattern, options);
|
26
|
+
|
29
27
|
this._printTypeahead(pattern, options);
|
30
28
|
}
|
31
29
|
|
32
30
|
_printTypeahead(pattern, options) {
|
33
31
|
const matchedTests = this._getMatchedTests(pattern);
|
32
|
+
|
34
33
|
const total = matchedTests.length;
|
35
34
|
const pipe = this._pipe;
|
36
35
|
const prompt = this._prompt;
|
37
|
-
|
38
36
|
(0, _jestWatcher.printPatternCaret)(pattern, pipe);
|
37
|
+
pipe.write(_ansiEscapes.default.cursorLeft);
|
39
38
|
|
40
39
|
if (pattern) {
|
41
|
-
(0, _pattern_mode_helpers.printPatternMatches)(total, 'test', pipe, ` from ${
|
42
|
-
|
40
|
+
(0, _pattern_mode_helpers.printPatternMatches)(total, 'test', pipe, ` from ${_chalk.default.yellow('cached')} test suites`);
|
43
41
|
const width = (0, _utils.getTerminalWidth)(pipe);
|
44
42
|
|
45
|
-
|
46
|
-
|
47
|
-
const start = _scroll.start,
|
43
|
+
const _scroll = (0, _scroll2.default)(total, options),
|
44
|
+
start = _scroll.start,
|
48
45
|
end = _scroll.end,
|
49
46
|
index = _scroll.index;
|
50
47
|
|
51
|
-
|
52
48
|
prompt.setPromptLength(total);
|
53
|
-
|
54
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));
|
55
50
|
|
56
51
|
if (total > end) {
|
@@ -72,14 +67,21 @@ class TestNamePatternPrompt extends _jestWatcher.PatternPrompt {
|
|
72
67
|
return [];
|
73
68
|
}
|
74
69
|
|
75
|
-
return this._cachedTestResults.reduce((matchedTests, {
|
76
|
-
|
70
|
+
return this._cachedTestResults.reduce((matchedTests, {
|
71
|
+
testResults
|
72
|
+
}) => {
|
73
|
+
return matchedTests.concat(testResults.filter(({
|
74
|
+
fullName
|
75
|
+
}) => regex.test(fullName)).map(({
|
76
|
+
fullName
|
77
|
+
}) => fullName));
|
77
78
|
}, []);
|
78
79
|
}
|
79
80
|
|
80
81
|
updateCachedTestResults(testResults = []) {
|
81
82
|
this._cachedTestResults = testResults;
|
82
83
|
}
|
84
|
+
|
83
85
|
}
|
84
86
|
|
85
87
|
module.exports = TestNamePatternPrompt;
|
@@ -1,25 +1,42 @@
|
|
1
|
-
|
1
|
+
"use strict";
|
2
2
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
4
4
|
value: true
|
5
5
|
});
|
6
|
+
exports.default = void 0;
|
6
7
|
|
7
|
-
var _jestWatcher = require(
|
8
|
+
var _jestWatcher = require("jest-watcher");
|
8
9
|
|
9
|
-
var _stripAnsi = require(
|
10
|
-
|
11
|
-
var _stripAnsi2 = _interopRequireDefault(_stripAnsi);
|
10
|
+
var _stripAnsi = _interopRequireDefault(require("strip-ansi"));
|
12
11
|
|
13
12
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
14
13
|
|
15
14
|
expect.addSnapshotSerializer({
|
16
15
|
test: val => typeof val === 'string',
|
17
|
-
print: val => (0,
|
16
|
+
print: val => (0, _stripAnsi.default)(val)
|
17
|
+
});
|
18
|
+
/**
|
19
|
+
* See https://github.com/facebook/jest/pull/7523 for more details
|
20
|
+
*/
|
21
|
+
|
22
|
+
const CLEAR = '\x1B[2J\x1B[3J\x1B[H';
|
23
|
+
expect.addSnapshotSerializer({
|
24
|
+
test: val => val.includes(CLEAR),
|
25
|
+
print: val => (0, _stripAnsi.default)(val.replace(CLEAR, '[MOCK - clear]'))
|
18
26
|
});
|
27
|
+
/**
|
28
|
+
* See https://github.com/facebook/jest/pull/7523 for more details
|
29
|
+
*/
|
19
30
|
|
31
|
+
const WINDOWS_CLEAR = '\x1B[2J\x1B[0f';
|
32
|
+
expect.addSnapshotSerializer({
|
33
|
+
test: val => val.includes(WINDOWS_CLEAR),
|
34
|
+
print: val => (0, _stripAnsi.default)(val.replace(WINDOWS_CLEAR, '[MOCK - clear]'))
|
35
|
+
});
|
20
36
|
jest.mock('ansi-escapes', () => ({
|
21
37
|
clearScreen: '[MOCK - clearScreen]',
|
22
38
|
cursorDown: (count = 1) => `[MOCK - cursorDown(${count})]`,
|
39
|
+
cursorLeft: '[MOCK - cursorLeft]',
|
23
40
|
cursorHide: '[MOCK - cursorHide]',
|
24
41
|
cursorRestorePosition: '[MOCK - cursorRestorePosition]',
|
25
42
|
cursorSavePosition: '[MOCK - cursorSavePosition]',
|
@@ -28,9 +45,15 @@ jest.mock('ansi-escapes', () => ({
|
|
28
45
|
}));
|
29
46
|
|
30
47
|
const pluginTester = (Plugin, config = {}) => {
|
31
|
-
const stdout = {
|
48
|
+
const stdout = {
|
49
|
+
columns: 80,
|
50
|
+
write: jest.fn()
|
51
|
+
};
|
32
52
|
const jestHooks = new _jestWatcher.JestHook();
|
33
|
-
const plugin = new Plugin({
|
53
|
+
const plugin = new Plugin({
|
54
|
+
stdout,
|
55
|
+
config
|
56
|
+
});
|
34
57
|
plugin.apply(jestHooks.getSubscriber());
|
35
58
|
|
36
59
|
const type = (...keys) => keys.forEach(key => plugin.onKey(key));
|
@@ -44,4 +67,5 @@ const pluginTester = (Plugin, config = {}) => {
|
|
44
67
|
};
|
45
68
|
};
|
46
69
|
|
47
|
-
|
70
|
+
var _default = pluginTester;
|
71
|
+
exports.default = _default;
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "jest-watch-typeahead",
|
3
|
-
"version": "0.
|
3
|
+
"version": "0.3.0",
|
4
4
|
"main": "build/index.js",
|
5
5
|
"author": "Rogelio Guzman <rogelioguzmanh@gmail.com>",
|
6
6
|
"description": "Jest plugin for filtering by filename or test name",
|
@@ -24,27 +24,31 @@
|
|
24
24
|
"format": "prettier --single-quote --trailing-comma all --write \"!(build)/**/*.js\""
|
25
25
|
},
|
26
26
|
"dependencies": {
|
27
|
+
"ansi-escapes": "^3.0.0",
|
27
28
|
"chalk": "^2.4.1",
|
28
|
-
"jest-watcher": "^
|
29
|
-
"slash": "^
|
29
|
+
"jest-watcher": "^24.3.0",
|
30
|
+
"slash": "^2.0.0",
|
30
31
|
"string-length": "^2.0.0",
|
31
|
-
"strip-ansi": "^
|
32
|
+
"strip-ansi": "^5.0.0"
|
32
33
|
},
|
33
34
|
"devDependencies": {
|
34
|
-
"babel
|
35
|
-
"babel
|
36
|
-
"babel
|
37
|
-
"babel
|
38
|
-
"
|
39
|
-
"eslint
|
40
|
-
"
|
41
|
-
"eslint
|
42
|
-
"eslint-
|
43
|
-
"eslint-
|
44
|
-
"eslint-plugin-
|
45
|
-
"
|
46
|
-
"jest": "
|
47
|
-
"prettier": "
|
35
|
+
"@babel/cli": "^7.0.0",
|
36
|
+
"@babel/core": "^7.0.0",
|
37
|
+
"@babel/preset-env": "^7.0.0",
|
38
|
+
"@babel/preset-flow": "^7.0.0",
|
39
|
+
"babel-core": "^7.0.0-bridge.0",
|
40
|
+
"babel-eslint": "^10.0.1",
|
41
|
+
"babel-jest": "^24.3.0",
|
42
|
+
"eslint": "^5.12.1",
|
43
|
+
"eslint-config-airbnb-base": "^13.1.0",
|
44
|
+
"eslint-config-prettier": "^4.1.0",
|
45
|
+
"eslint-plugin-flowtype": "^3.2.1",
|
46
|
+
"eslint-plugin-import": "^2.9.0",
|
47
|
+
"eslint-plugin-jest": "^22.1.3",
|
48
|
+
"eslint-plugin-prettier": "^3.0.1",
|
49
|
+
"flow-bin": "^0.94.0",
|
50
|
+
"jest": "^24.3.0",
|
51
|
+
"prettier": "^1.13.7"
|
48
52
|
},
|
49
53
|
"jest": {
|
50
54
|
"watchPlugins": [
|
@@ -52,7 +56,7 @@
|
|
52
56
|
"<rootDir>/testname"
|
53
57
|
],
|
54
58
|
"snapshotSerializers": [
|
55
|
-
"<rootDir>/node_modules/pretty-format/build/plugins/
|
59
|
+
"<rootDir>/node_modules/pretty-format/build/plugins/ConvertAnsi"
|
56
60
|
],
|
57
61
|
"testPathIgnorePatterns": [
|
58
62
|
"<rootDir>/build/.*",
|
@@ -1,47 +0,0 @@
|
|
1
|
-
'use strict';
|
2
|
-
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
4
|
-
value: true
|
5
|
-
});
|
6
|
-
|
7
|
-
var _jestWatcher = require('jest-watcher');
|
8
|
-
|
9
|
-
var _stripAnsi = require('strip-ansi');
|
10
|
-
|
11
|
-
var _stripAnsi2 = _interopRequireDefault(_stripAnsi);
|
12
|
-
|
13
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
14
|
-
|
15
|
-
expect.addSnapshotSerializer({
|
16
|
-
test: val => typeof val === 'string',
|
17
|
-
print: val => (0, _stripAnsi2.default)(val)
|
18
|
-
});
|
19
|
-
|
20
|
-
jest.mock('ansi-escapes', () => ({
|
21
|
-
clearScreen: '[MOCK - clearScreen]',
|
22
|
-
cursorDown: (count = 1) => `[MOCK - cursorDown(${count})]`,
|
23
|
-
cursorHide: '[MOCK - cursorHide]',
|
24
|
-
cursorRestorePosition: '[MOCK - cursorRestorePosition]',
|
25
|
-
cursorSavePosition: '[MOCK - cursorSavePosition]',
|
26
|
-
cursorShow: '[MOCK - cursorShow]',
|
27
|
-
cursorTo: (x, y) => `[MOCK - cursorTo(${x}, ${y})]`
|
28
|
-
}));
|
29
|
-
|
30
|
-
const pluginTester = (Plugin, config = {}) => {
|
31
|
-
const stdout = { columns: 80, write: jest.fn() };
|
32
|
-
const jestHooks = new _jestWatcher.JestHook();
|
33
|
-
const plugin = new Plugin({ stdout, config });
|
34
|
-
plugin.apply(jestHooks.getSubscriber());
|
35
|
-
|
36
|
-
const type = (...keys) => keys.forEach(key => plugin.onKey(key));
|
37
|
-
|
38
|
-
return {
|
39
|
-
stdout,
|
40
|
-
hookEmitter: jestHooks.getEmitter(),
|
41
|
-
updateConfigAndRun: jest.fn(),
|
42
|
-
plugin,
|
43
|
-
type
|
44
|
-
};
|
45
|
-
};
|
46
|
-
|
47
|
-
exports.default = pluginTester;
|
@@ -1,105 +0,0 @@
|
|
1
|
-
'use strict';
|
2
|
-
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
4
|
-
value: true
|
5
|
-
});
|
6
|
-
|
7
|
-
var _chalk = require('chalk');
|
8
|
-
|
9
|
-
var _chalk2 = _interopRequireDefault(_chalk);
|
10
|
-
|
11
|
-
var _stringLength = require('string-length');
|
12
|
-
|
13
|
-
var _stringLength2 = _interopRequireDefault(_stringLength);
|
14
|
-
|
15
|
-
var _jestWatcher = require('jest-watcher');
|
16
|
-
|
17
|
-
var _utils = require('./lib/utils');
|
18
|
-
|
19
|
-
var _pattern_mode_helpers = require('./shared/pattern_mode_helpers');
|
20
|
-
|
21
|
-
var _scroll2 = require('./shared/scroll');
|
22
|
-
|
23
|
-
var _scroll3 = _interopRequireDefault(_scroll2);
|
24
|
-
|
25
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
26
|
-
|
27
|
-
class FileNamePatternPrompt extends _jestWatcher.PatternPrompt {
|
28
|
-
|
29
|
-
constructor(pipe, prompt) {
|
30
|
-
super(pipe, prompt);
|
31
|
-
this._entityName = 'filenames';
|
32
|
-
this._searchSources = [];
|
33
|
-
}
|
34
|
-
|
35
|
-
_onChange(pattern, options) {
|
36
|
-
super._onChange(pattern, options);
|
37
|
-
this._printTypeahead(pattern, options);
|
38
|
-
}
|
39
|
-
|
40
|
-
_printTypeahead(pattern, options) {
|
41
|
-
const matchedTests = this._getMatchedTests(pattern);
|
42
|
-
const total = matchedTests.length;
|
43
|
-
const pipe = this._pipe;
|
44
|
-
const prompt = this._prompt;
|
45
|
-
|
46
|
-
(0, _jestWatcher.printPatternCaret)(pattern, pipe);
|
47
|
-
|
48
|
-
if (pattern) {
|
49
|
-
(0, _pattern_mode_helpers.printPatternMatches)(total, 'file', pipe);
|
50
|
-
|
51
|
-
const prefix = ` ${_chalk2.default.dim('\u203A')} `;
|
52
|
-
const padding = (0, _stringLength2.default)(prefix) + 2;
|
53
|
-
const width = (0, _utils.getTerminalWidth)(pipe);
|
54
|
-
|
55
|
-
var _scroll = (0, _scroll3.default)(total, options);
|
56
|
-
|
57
|
-
const start = _scroll.start,
|
58
|
-
end = _scroll.end,
|
59
|
-
index = _scroll.index;
|
60
|
-
|
61
|
-
|
62
|
-
prompt.setPromptLength(total);
|
63
|
-
|
64
|
-
matchedTests.slice(start, end).map(({ path, context }) => {
|
65
|
-
const filePath = (0, _utils.trimAndFormatPath)(padding, context.config, path, width);
|
66
|
-
return (0, _utils.highlight)(path, filePath, pattern, context.config.rootDir);
|
67
|
-
}).map((item, i) => (0, _pattern_mode_helpers.formatTypeaheadSelection)(item, i, index, prompt)).forEach(item => (0, _pattern_mode_helpers.printTypeaheadItem)(item, pipe));
|
68
|
-
|
69
|
-
if (total > end) {
|
70
|
-
(0, _pattern_mode_helpers.printMore)('file', pipe, total - end);
|
71
|
-
}
|
72
|
-
} else {
|
73
|
-
(0, _pattern_mode_helpers.printStartTyping)('filename', pipe);
|
74
|
-
}
|
75
|
-
|
76
|
-
(0, _jestWatcher.printRestoredPatternCaret)(pattern, this._currentUsageRows, pipe);
|
77
|
-
}
|
78
|
-
|
79
|
-
_getMatchedTests(pattern) {
|
80
|
-
let regex;
|
81
|
-
|
82
|
-
try {
|
83
|
-
regex = new RegExp(pattern, 'i');
|
84
|
-
} catch (e) {
|
85
|
-
regex = null;
|
86
|
-
}
|
87
|
-
|
88
|
-
let tests = [];
|
89
|
-
if (regex) {
|
90
|
-
this._searchSources.forEach(({ testPaths, config }) => {
|
91
|
-
tests = tests.concat(testPaths.filter(testPath => testPath.match(pattern)).map(path => ({
|
92
|
-
path,
|
93
|
-
context: { config }
|
94
|
-
})));
|
95
|
-
});
|
96
|
-
}
|
97
|
-
|
98
|
-
return tests;
|
99
|
-
}
|
100
|
-
|
101
|
-
updateSearchSources(searchSources) {
|
102
|
-
this._searchSources = searchSources;
|
103
|
-
}
|
104
|
-
}
|
105
|
-
exports.default = FileNamePatternPrompt;
|
@@ -1,54 +0,0 @@
|
|
1
|
-
'use strict';
|
2
|
-
|
3
|
-
var _jestWatcher = require('jest-watcher');
|
4
|
-
|
5
|
-
var _file_name_pattern_prompt = require('./file_name_pattern_prompt');
|
6
|
-
|
7
|
-
var _file_name_pattern_prompt2 = _interopRequireDefault(_file_name_pattern_prompt);
|
8
|
-
|
9
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
10
|
-
|
11
|
-
class FileNamePlugin {
|
12
|
-
|
13
|
-
constructor({
|
14
|
-
stdin,
|
15
|
-
stdout,
|
16
|
-
config = {}
|
17
|
-
}) {
|
18
|
-
this._stdin = stdin;
|
19
|
-
this._stdout = stdout;
|
20
|
-
this._prompt = new _jestWatcher.Prompt();
|
21
|
-
this._projects = [];
|
22
|
-
this._usageInfo = {
|
23
|
-
key: config.key || 'p',
|
24
|
-
prompt: config.prompt || 'filter by a filename regex pattern'
|
25
|
-
};
|
26
|
-
}
|
27
|
-
|
28
|
-
apply(jestHooks) {
|
29
|
-
jestHooks.onFileChange(({ projects }) => {
|
30
|
-
this._projects = projects;
|
31
|
-
});
|
32
|
-
}
|
33
|
-
|
34
|
-
onKey(key) {
|
35
|
-
this._prompt.put(key);
|
36
|
-
}
|
37
|
-
|
38
|
-
run(globalConfig, updateConfigAndRun) {
|
39
|
-
const p = new _file_name_pattern_prompt2.default(this._stdout, this._prompt);
|
40
|
-
p.updateSearchSources(this._projects);
|
41
|
-
return new Promise((res, rej) => {
|
42
|
-
p.run(value => {
|
43
|
-
updateConfigAndRun({ mode: 'watch', testPathPattern: value });
|
44
|
-
res();
|
45
|
-
}, rej);
|
46
|
-
});
|
47
|
-
}
|
48
|
-
|
49
|
-
getUsageInfo() {
|
50
|
-
return this._usageInfo;
|
51
|
-
}
|
52
|
-
}
|
53
|
-
|
54
|
-
module.exports = FileNamePlugin;
|
@@ -1,45 +0,0 @@
|
|
1
|
-
'use strict';
|
2
|
-
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
4
|
-
value: true
|
5
|
-
});
|
6
|
-
exports.formatTypeaheadSelection = exports.printTypeaheadItem = exports.printMore = exports.printStartTyping = exports.printPatternMatches = undefined;
|
7
|
-
|
8
|
-
var _chalk = require('chalk');
|
9
|
-
|
10
|
-
var _chalk2 = _interopRequireDefault(_chalk);
|
11
|
-
|
12
|
-
var _stripAnsi = require('strip-ansi');
|
13
|
-
|
14
|
-
var _stripAnsi2 = _interopRequireDefault(_stripAnsi);
|
15
|
-
|
16
|
-
var _jestWatcher = require('jest-watcher');
|
17
|
-
|
18
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
19
|
-
|
20
|
-
const pluralize = (count, text) => count === 1 ? text : `${text}s`;
|
21
|
-
|
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}`;
|
25
|
-
|
26
|
-
pipe.write(result + extraText);
|
27
|
-
};
|
28
|
-
|
29
|
-
const printStartTyping = exports.printStartTyping = (entity, pipe) => {
|
30
|
-
pipe.write(`\n\n ${_chalk2.default.italic.yellow(`Start typing to filter by a ${entity} regex pattern.`)}`);
|
31
|
-
};
|
32
|
-
|
33
|
-
const printMore = exports.printMore = (entity, pipe, more) => {
|
34
|
-
pipe.write(`\n ${_chalk2.default.dim(`...and ${more} more ${pluralize(more, entity)}`)}`);
|
35
|
-
};
|
36
|
-
|
37
|
-
const printTypeaheadItem = exports.printTypeaheadItem = (item, pipe) => pipe.write(`\n ${_chalk2.default.dim('\u203A')} ${item}`);
|
38
|
-
|
39
|
-
const formatTypeaheadSelection = exports.formatTypeaheadSelection = (item, index, activeIndex, prompt) => {
|
40
|
-
if (index === activeIndex) {
|
41
|
-
prompt.setPromptSelection((0, _stripAnsi2.default)(item));
|
42
|
-
return _chalk2.default.black.bgYellow((0, _stripAnsi2.default)(item));
|
43
|
-
}
|
44
|
-
return item;
|
45
|
-
};
|
package/build/shared/scroll.js
DELETED
@@ -1,30 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
4
|
-
value: true
|
5
|
-
});
|
6
|
-
|
7
|
-
|
8
|
-
const scroll = (size, { offset, max }) => {
|
9
|
-
let start = 0;
|
10
|
-
let index = Math.min(offset, size);
|
11
|
-
|
12
|
-
const halfScreen = max / 2;
|
13
|
-
|
14
|
-
if (index <= halfScreen) {
|
15
|
-
start = 0;
|
16
|
-
} else {
|
17
|
-
if (size >= max) {
|
18
|
-
start = Math.min(index - halfScreen - 1, size - max);
|
19
|
-
}
|
20
|
-
index = Math.min(index - start, size);
|
21
|
-
}
|
22
|
-
|
23
|
-
return {
|
24
|
-
end: Math.min(size, start + max),
|
25
|
-
index,
|
26
|
-
start
|
27
|
-
};
|
28
|
-
};
|
29
|
-
|
30
|
-
exports.default = scroll;
|
@@ -1,91 +0,0 @@
|
|
1
|
-
'use strict';
|
2
|
-
|
3
|
-
var _chalk = require('chalk');
|
4
|
-
|
5
|
-
var _chalk2 = _interopRequireDefault(_chalk);
|
6
|
-
|
7
|
-
var _jestWatcher = require('jest-watcher');
|
8
|
-
|
9
|
-
var _scroll2 = require('./shared/scroll');
|
10
|
-
|
11
|
-
var _scroll3 = _interopRequireDefault(_scroll2);
|
12
|
-
|
13
|
-
var _utils = require('./lib/utils');
|
14
|
-
|
15
|
-
var _pattern_mode_helpers = require('./shared/pattern_mode_helpers');
|
16
|
-
|
17
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
18
|
-
|
19
|
-
class TestNamePatternPrompt extends _jestWatcher.PatternPrompt {
|
20
|
-
|
21
|
-
constructor(pipe, prompt) {
|
22
|
-
super(pipe, prompt);
|
23
|
-
this._entityName = 'tests';
|
24
|
-
this._cachedTestResults = [];
|
25
|
-
}
|
26
|
-
|
27
|
-
_onChange(pattern, options) {
|
28
|
-
super._onChange(pattern, options);
|
29
|
-
this._printTypeahead(pattern, options);
|
30
|
-
}
|
31
|
-
|
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
|
-
|
38
|
-
(0, _jestWatcher.printPatternCaret)(pattern, pipe);
|
39
|
-
|
40
|
-
if (pattern) {
|
41
|
-
(0, _pattern_mode_helpers.printPatternMatches)(total, 'test', pipe, ` from ${_chalk2.default.yellow('cached')} test suites`);
|
42
|
-
|
43
|
-
const width = (0, _utils.getTerminalWidth)(pipe);
|
44
|
-
|
45
|
-
var _scroll = (0, _scroll3.default)(total, options);
|
46
|
-
|
47
|
-
const start = _scroll.start,
|
48
|
-
end = _scroll.end,
|
49
|
-
index = _scroll.index;
|
50
|
-
|
51
|
-
|
52
|
-
prompt.setPromptLength(total);
|
53
|
-
|
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));
|
55
|
-
|
56
|
-
if (total > end) {
|
57
|
-
(0, _pattern_mode_helpers.printMore)('test', pipe, total - end);
|
58
|
-
}
|
59
|
-
} else {
|
60
|
-
(0, _pattern_mode_helpers.printStartTyping)('test name', pipe);
|
61
|
-
}
|
62
|
-
|
63
|
-
(0, _jestWatcher.printRestoredPatternCaret)(pattern, this._currentUsageRows, pipe);
|
64
|
-
}
|
65
|
-
|
66
|
-
_getMatchedTests(pattern) {
|
67
|
-
let regex;
|
68
|
-
|
69
|
-
try {
|
70
|
-
regex = new RegExp(pattern, 'i');
|
71
|
-
} catch (e) {
|
72
|
-
return [];
|
73
|
-
}
|
74
|
-
|
75
|
-
const matchedTests = [];
|
76
|
-
|
77
|
-
this._cachedTestResults.forEach(({ testResults }) => testResults.forEach(({ title }) => {
|
78
|
-
if (regex.test(title)) {
|
79
|
-
matchedTests.push(title);
|
80
|
-
}
|
81
|
-
}));
|
82
|
-
|
83
|
-
return matchedTests;
|
84
|
-
}
|
85
|
-
|
86
|
-
updateCachedTestResults(testResults = []) {
|
87
|
-
this._cachedTestResults = testResults;
|
88
|
-
}
|
89
|
-
}
|
90
|
-
|
91
|
-
module.exports = TestNamePatternPrompt;
|
@@ -1,54 +0,0 @@
|
|
1
|
-
'use strict';
|
2
|
-
|
3
|
-
var _jestWatcher = require('jest-watcher');
|
4
|
-
|
5
|
-
var _test_name_pattern_prompt = require('./test_name_pattern_prompt');
|
6
|
-
|
7
|
-
var _test_name_pattern_prompt2 = _interopRequireDefault(_test_name_pattern_prompt);
|
8
|
-
|
9
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
10
|
-
|
11
|
-
class TestNamePlugin {
|
12
|
-
|
13
|
-
constructor({
|
14
|
-
stdin,
|
15
|
-
stdout,
|
16
|
-
config = {}
|
17
|
-
}) {
|
18
|
-
this._stdin = stdin;
|
19
|
-
this._stdout = stdout;
|
20
|
-
this._prompt = new _jestWatcher.Prompt();
|
21
|
-
this._testResults = [];
|
22
|
-
this._usageInfo = {
|
23
|
-
key: config.key || 't',
|
24
|
-
prompt: config.prompt || 'filter by a test name regex pattern'
|
25
|
-
};
|
26
|
-
}
|
27
|
-
|
28
|
-
apply(jestHooks) {
|
29
|
-
jestHooks.onTestRunComplete(({ testResults }) => {
|
30
|
-
this._testResults = testResults;
|
31
|
-
});
|
32
|
-
}
|
33
|
-
|
34
|
-
onKey(key) {
|
35
|
-
this._prompt.put(key);
|
36
|
-
}
|
37
|
-
|
38
|
-
run(globalConfig, updateConfigAndRun) {
|
39
|
-
const p = new _test_name_pattern_prompt2.default(this._stdout, this._prompt);
|
40
|
-
p.updateCachedTestResults(this._testResults);
|
41
|
-
return new Promise((res, rej) => {
|
42
|
-
p.run(value => {
|
43
|
-
updateConfigAndRun({ mode: 'watch', testNamePattern: value });
|
44
|
-
res();
|
45
|
-
}, rej);
|
46
|
-
});
|
47
|
-
}
|
48
|
-
|
49
|
-
getUsageInfo() {
|
50
|
-
return this._usageInfo;
|
51
|
-
}
|
52
|
-
}
|
53
|
-
|
54
|
-
module.exports = TestNamePlugin;
|