jest-watch-typeahead 0.2.0 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- package/build/file_name_pattern_prompt.js +1 -1
- package/build/file_name_plugin/plugin.js +12 -9
- package/build/file_name_plugin/prompt.js +29 -25
- package/build/file_name_plugin.js +6 -7
- package/build/lib/pattern_mode_helpers.js +26 -20
- package/build/lib/scroll.js +8 -4
- package/build/lib/utils.js +50 -47
- package/build/test_name_pattern_prompt.js +1 -1
- package/build/test_name_plugin/plugin.js +12 -9
- package/build/test_name_plugin/prompt.js +22 -20
- package/build/test_name_plugin.js +6 -7
- package/build/test_utils/pluginTester.js +16 -10
- package/package.json +21 -17
- package/build/__tests__/pluginTester.js +0 -47
@@ -50,7 +50,7 @@ class FileNamePatternPrompt extends _jestWatcher.PatternPrompt {
|
|
50
50
|
|
51
51
|
const prefix = ` ${_chalk2.default.dim('\u203A')} `;
|
52
52
|
const padding = (0, _stringLength2.default)(prefix) + 2;
|
53
|
-
const width = (0, _utils.getTerminalWidth)(
|
53
|
+
const width = (0, _utils.getTerminalWidth)();
|
54
54
|
|
55
55
|
var _scroll = (0, _scroll3.default)(total, options);
|
56
56
|
|
@@ -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;
|
@@ -12,17 +12,12 @@ class FileNamePlugin {
|
|
12
12
|
|
13
13
|
constructor({
|
14
14
|
stdin,
|
15
|
-
stdout
|
16
|
-
config = {}
|
15
|
+
stdout
|
17
16
|
}) {
|
18
17
|
this._stdin = stdin;
|
19
18
|
this._stdout = stdout;
|
20
19
|
this._prompt = new _jestWatcher.Prompt();
|
21
20
|
this._projects = [];
|
22
|
-
this._usageInfo = {
|
23
|
-
key: config.key || 'p',
|
24
|
-
prompt: config.prompt || 'filter by a filename regex pattern'
|
25
|
-
};
|
26
21
|
}
|
27
22
|
|
28
23
|
apply(jestHooks) {
|
@@ -46,8 +41,12 @@ class FileNamePlugin {
|
|
46
41
|
});
|
47
42
|
}
|
48
43
|
|
44
|
+
// eslint-disable-next-line class-methods-use-this
|
49
45
|
getUsageInfo() {
|
50
|
-
return
|
46
|
+
return {
|
47
|
+
key: 'p',
|
48
|
+
prompt: 'filter by a filename regex pattern'
|
49
|
+
};
|
51
50
|
}
|
52
51
|
}
|
53
52
|
|
@@ -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,27 +102,27 @@ 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
128
|
|
@@ -136,8 +136,11 @@ const formatTestNameByPattern = exports.formatTestNameByPattern = (testName, pat
|
|
136
136
|
if (endPatternIndex > slicedTestName.length) {
|
137
137
|
return colorize(slicedTestName + DOTS, startPatternIndex, slicedTestName.length + DOTS.length);
|
138
138
|
}
|
139
|
+
|
139
140
|
return colorize(slicedTestName + DOTS, Math.min(startPatternIndex, slicedTestName.length), endPatternIndex);
|
140
141
|
}
|
141
142
|
|
142
|
-
return `${
|
143
|
-
};
|
143
|
+
return `${_chalk.default.dim(slicedTestName)}${_chalk.default.reset(DOTS)}`;
|
144
|
+
};
|
145
|
+
|
146
|
+
exports.formatTestNameByPattern = formatTestNameByPattern;
|
@@ -40,7 +40,7 @@ class TestNamePatternPrompt extends _jestWatcher.PatternPrompt {
|
|
40
40
|
if (pattern) {
|
41
41
|
(0, _pattern_mode_helpers.printPatternMatches)(total, 'test', pipe, ` from ${_chalk2.default.yellow('cached')} test suites`);
|
42
42
|
|
43
|
-
const width = (0, _utils.getTerminalWidth)(
|
43
|
+
const width = (0, _utils.getTerminalWidth)();
|
44
44
|
|
45
45
|
var _scroll = (0, _scroll3.default)(total, options);
|
46
46
|
|
@@ -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
|
+
title
|
75
|
+
}) => regex.test(title)).map(({
|
76
|
+
title
|
77
|
+
}) => title));
|
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;
|
@@ -12,17 +12,12 @@ class TestNamePlugin {
|
|
12
12
|
|
13
13
|
constructor({
|
14
14
|
stdin,
|
15
|
-
stdout
|
16
|
-
config = {}
|
15
|
+
stdout
|
17
16
|
}) {
|
18
17
|
this._stdin = stdin;
|
19
18
|
this._stdout = stdout;
|
20
19
|
this._prompt = new _jestWatcher.Prompt();
|
21
20
|
this._testResults = [];
|
22
|
-
this._usageInfo = {
|
23
|
-
key: config.key || 't',
|
24
|
-
prompt: config.prompt || 'filter by a test name regex pattern'
|
25
|
-
};
|
26
21
|
}
|
27
22
|
|
28
23
|
apply(jestHooks) {
|
@@ -46,8 +41,12 @@ class TestNamePlugin {
|
|
46
41
|
});
|
47
42
|
}
|
48
43
|
|
44
|
+
// eslint-disable-next-line class-methods-use-this
|
49
45
|
getUsageInfo() {
|
50
|
-
return
|
46
|
+
return {
|
47
|
+
key: 't',
|
48
|
+
prompt: 'filter by a test name regex pattern'
|
49
|
+
};
|
51
50
|
}
|
52
51
|
}
|
53
52
|
|
@@ -1,25 +1,24 @@
|
|
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)
|
18
17
|
});
|
19
|
-
|
20
18
|
jest.mock('ansi-escapes', () => ({
|
21
19
|
clearScreen: '[MOCK - clearScreen]',
|
22
20
|
cursorDown: (count = 1) => `[MOCK - cursorDown(${count})]`,
|
21
|
+
cursorLeft: '[MOCK - cursorLeft]',
|
23
22
|
cursorHide: '[MOCK - cursorHide]',
|
24
23
|
cursorRestorePosition: '[MOCK - cursorRestorePosition]',
|
25
24
|
cursorSavePosition: '[MOCK - cursorSavePosition]',
|
@@ -28,9 +27,15 @@ jest.mock('ansi-escapes', () => ({
|
|
28
27
|
}));
|
29
28
|
|
30
29
|
const pluginTester = (Plugin, config = {}) => {
|
31
|
-
const stdout = {
|
30
|
+
const stdout = {
|
31
|
+
columns: 80,
|
32
|
+
write: jest.fn()
|
33
|
+
};
|
32
34
|
const jestHooks = new _jestWatcher.JestHook();
|
33
|
-
const plugin = new Plugin({
|
35
|
+
const plugin = new Plugin({
|
36
|
+
stdout,
|
37
|
+
config
|
38
|
+
});
|
34
39
|
plugin.apply(jestHooks.getSubscriber());
|
35
40
|
|
36
41
|
const type = (...keys) => keys.forEach(key => plugin.onKey(key));
|
@@ -44,4 +49,5 @@ const pluginTester = (Plugin, config = {}) => {
|
|
44
49
|
};
|
45
50
|
};
|
46
51
|
|
47
|
-
|
52
|
+
var _default = pluginTester;
|
53
|
+
exports.default = _default;
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "jest-watch-typeahead",
|
3
|
-
"version": "0.2.
|
3
|
+
"version": "0.2.1",
|
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
29
|
"jest-watcher": "^23.1.0",
|
29
|
-
"slash": "^
|
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": "^23.4.2",
|
42
|
+
"eslint": "^5.12.1",
|
43
|
+
"eslint-config-airbnb-base": "^13.1.0",
|
44
|
+
"eslint-config-prettier": "^3.6.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.91.0",
|
50
|
+
"jest": "^23.2.0",
|
51
|
+
"prettier": "^1.13.7"
|
48
52
|
},
|
49
53
|
"jest": {
|
50
54
|
"watchPlugins": [
|
@@ -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;
|