jest-watch-typeahead 0.3.1 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- package/CHANGELOG.md +6 -0
- package/README.md +2 -3
- package/build/file_name_plugin/plugin.js +5 -1
- package/build/lib/utils.js +23 -13
- package/build/test_name_plugin/plugin.js +5 -1
- package/build/test_utils/pluginTester.js +3 -13
- package/package.json +23 -17
- package/build/file_name_pattern_prompt.js +0 -105
- package/build/file_name_plugin.js +0 -53
- 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 -53
package/CHANGELOG.md
CHANGED
package/README.md
CHANGED
@@ -1,9 +1,8 @@
|
|
1
1
|
[![Build Status](https://travis-ci.org/jest-community/jest-watch-typeahead.svg?branch=master)](https://travis-ci.org/jest-community/jest-watch-typeahead) [![npm version](https://badge.fury.io/js/jest-watch-typeahead.svg)](https://badge.fury.io/js/jest-watch-typeahead)
|
2
2
|
|
3
3
|
<div align="center">
|
4
|
-
|
5
|
-
|
6
|
-
<img width="150" height="150" vspace="" hspace="25" src="https://cdn.worldvectorlogo.com/logos/jest.svg">
|
4
|
+
<a href="https://jestjs.io/">
|
5
|
+
<img width="150" height="150" vspace="" hspace="25" src="https://jestjs.io/img/jest.png">
|
7
6
|
</a>
|
8
7
|
<h1>jest-watch-typeahead</h1>
|
9
8
|
<p>Filter your tests by file name or test name</p>
|
@@ -2,8 +2,12 @@
|
|
2
2
|
|
3
3
|
var _jestWatcher = require("jest-watcher");
|
4
4
|
|
5
|
+
var _jestRegexUtil = require("jest-regex-util");
|
6
|
+
|
5
7
|
var _prompt = _interopRequireDefault(require("./prompt"));
|
6
8
|
|
9
|
+
var _utils = require("../lib/utils");
|
10
|
+
|
7
11
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
8
12
|
|
9
13
|
class FileNamePlugin {
|
@@ -41,7 +45,7 @@ class FileNamePlugin {
|
|
41
45
|
p.run(value => {
|
42
46
|
updateConfigAndRun({
|
43
47
|
mode: 'watch',
|
44
|
-
testPathPattern: value
|
48
|
+
testPathPattern: (0, _utils.removeTrimmingDots)(value).split('/').map(_jestRegexUtil.escapeStrForRegex).join('/')
|
45
49
|
});
|
46
50
|
res();
|
47
51
|
}, rej);
|
package/build/lib/utils.js
CHANGED
@@ -3,7 +3,7 @@
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
4
4
|
value: true
|
5
5
|
});
|
6
|
-
exports.formatTestNameByPattern = exports.highlight = exports.getTerminalWidth = exports.trimAndFormatPath = void 0;
|
6
|
+
exports.removeTrimmingDots = exports.formatTestNameByPattern = exports.highlight = exports.getTerminalWidth = exports.trimAndFormatPath = void 0;
|
7
7
|
|
8
8
|
var _path = _interopRequireDefault(require("path"));
|
9
9
|
|
@@ -16,6 +16,9 @@ var _stripAnsi = _interopRequireDefault(require("strip-ansi"));
|
|
16
16
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
17
17
|
|
18
18
|
/* eslint-disable no-param-reassign */
|
19
|
+
const TRIMMING_DOTS = '...';
|
20
|
+
const ENTER = '⏎';
|
21
|
+
|
19
22
|
const relativePath = (config, testPath) => {
|
20
23
|
testPath = _path.default.relative(config.cwd || config.rootDir, testPath);
|
21
24
|
|
@@ -46,16 +49,16 @@ const trimAndFormatPath = (pad, config, testPath, columns) => {
|
|
46
49
|
|
47
50
|
if (basenameLength + 4 < maxLength) {
|
48
51
|
const dirnameLength = maxLength - 4 - basenameLength;
|
49
|
-
dirname =
|
52
|
+
dirname = `${TRIMMING_DOTS}${dirname.slice(dirname.length - dirnameLength, dirname.length)}`;
|
50
53
|
return (0, _slash.default)(_chalk.default.dim(dirname + _path.default.sep) + _chalk.default.bold(basename));
|
51
54
|
}
|
52
55
|
|
53
56
|
if (basenameLength + 4 === maxLength) {
|
54
|
-
return (0, _slash.default)(_chalk.default.dim(
|
57
|
+
return (0, _slash.default)(_chalk.default.dim(`${TRIMMING_DOTS}${_path.default.sep}`) + _chalk.default.bold(basename));
|
55
58
|
} // can't fit dirname, but can fit trimmed basename
|
56
59
|
|
57
60
|
|
58
|
-
return (0, _slash.default)(_chalk.default.bold(
|
61
|
+
return (0, _slash.default)(_chalk.default.bold(`${TRIMMING_DOTS}${basename.slice(-maxLength + 3)}`));
|
59
62
|
};
|
60
63
|
|
61
64
|
exports.trimAndFormatPath = trimAndFormatPath;
|
@@ -65,7 +68,6 @@ const getTerminalWidth = (pipe = process.stdout) => pipe.columns;
|
|
65
68
|
exports.getTerminalWidth = getTerminalWidth;
|
66
69
|
|
67
70
|
const highlight = (rawPath, filePath, pattern, rootDir) => {
|
68
|
-
const trim = '...';
|
69
71
|
const relativePathHead = './';
|
70
72
|
let regexp;
|
71
73
|
|
@@ -86,9 +88,9 @@ const highlight = (rawPath, filePath, pattern, rootDir) => {
|
|
86
88
|
let offset;
|
87
89
|
let trimLength;
|
88
90
|
|
89
|
-
if (filePath.startsWith(
|
91
|
+
if (filePath.startsWith(TRIMMING_DOTS)) {
|
90
92
|
offset = rawPath.length - filePath.length;
|
91
|
-
trimLength =
|
93
|
+
trimLength = TRIMMING_DOTS.length;
|
92
94
|
} else if (filePath.startsWith(relativePathHead)) {
|
93
95
|
offset = rawPath.length - filePath.length;
|
94
96
|
trimLength = relativePathHead.length;
|
@@ -103,8 +105,6 @@ const highlight = (rawPath, filePath, pattern, rootDir) => {
|
|
103
105
|
};
|
104
106
|
|
105
107
|
exports.highlight = highlight;
|
106
|
-
const DOTS = '...';
|
107
|
-
const ENTER = '⏎';
|
108
108
|
|
109
109
|
const formatTestNameByPattern = (testName, pattern, width) => {
|
110
110
|
const inlineTestName = testName.replace(/(\r\n|\n|\r)/gm, ENTER);
|
@@ -131,17 +131,27 @@ const formatTestNameByPattern = (testName, pattern, width) => {
|
|
131
131
|
return colorize(inlineTestName, startPatternIndex, endPatternIndex);
|
132
132
|
}
|
133
133
|
|
134
|
-
const numberOfTruncatedChars =
|
134
|
+
const numberOfTruncatedChars = TRIMMING_DOTS.length + inlineTestName.length - width;
|
135
135
|
const end = Math.max(endPatternIndex - numberOfTruncatedChars, 0);
|
136
136
|
const truncatedTestName = inlineTestName.slice(numberOfTruncatedChars);
|
137
137
|
const shouldHighlightDots = startPatternIndex <= numberOfTruncatedChars;
|
138
138
|
|
139
139
|
if (shouldHighlightDots) {
|
140
|
-
return colorize(
|
140
|
+
return colorize(TRIMMING_DOTS + truncatedTestName, 0, end + TRIMMING_DOTS.length);
|
141
141
|
}
|
142
142
|
|
143
143
|
const start = startPatternIndex - numberOfTruncatedChars;
|
144
|
-
return colorize(
|
144
|
+
return colorize(TRIMMING_DOTS + truncatedTestName, start + TRIMMING_DOTS.length, end + TRIMMING_DOTS.length);
|
145
|
+
};
|
146
|
+
|
147
|
+
exports.formatTestNameByPattern = formatTestNameByPattern;
|
148
|
+
|
149
|
+
const removeTrimmingDots = value => {
|
150
|
+
if (value.startsWith(TRIMMING_DOTS)) {
|
151
|
+
return value.slice(TRIMMING_DOTS.length);
|
152
|
+
}
|
153
|
+
|
154
|
+
return value;
|
145
155
|
};
|
146
156
|
|
147
|
-
exports.
|
157
|
+
exports.removeTrimmingDots = removeTrimmingDots;
|
@@ -2,8 +2,12 @@
|
|
2
2
|
|
3
3
|
var _jestWatcher = require("jest-watcher");
|
4
4
|
|
5
|
+
var _jestRegexUtil = require("jest-regex-util");
|
6
|
+
|
5
7
|
var _prompt = _interopRequireDefault(require("./prompt"));
|
6
8
|
|
9
|
+
var _utils = require("../lib/utils");
|
10
|
+
|
7
11
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
8
12
|
|
9
13
|
class TestNamePlugin {
|
@@ -41,7 +45,7 @@ class TestNamePlugin {
|
|
41
45
|
p.run(value => {
|
42
46
|
updateConfigAndRun({
|
43
47
|
mode: 'watch',
|
44
|
-
testNamePattern: value
|
48
|
+
testNamePattern: (0, _jestRegexUtil.escapeStrForRegex)((0, _utils.removeTrimmingDots)(value))
|
45
49
|
});
|
46
50
|
res();
|
47
51
|
}, rej);
|
@@ -33,26 +33,16 @@ expect.addSnapshotSerializer({
|
|
33
33
|
test: val => val.includes(WINDOWS_CLEAR),
|
34
34
|
print: val => (0, _stripAnsi.default)(val.replace(WINDOWS_CLEAR, '[MOCK - clear]'))
|
35
35
|
});
|
36
|
-
jest.mock('ansi-escapes', () => ({
|
37
|
-
clearScreen: '[MOCK - clearScreen]',
|
38
|
-
cursorDown: (count = 1) => `[MOCK - cursorDown(${count})]`,
|
39
|
-
cursorLeft: '[MOCK - cursorLeft]',
|
40
|
-
cursorHide: '[MOCK - cursorHide]',
|
41
|
-
cursorRestorePosition: '[MOCK - cursorRestorePosition]',
|
42
|
-
cursorSavePosition: '[MOCK - cursorSavePosition]',
|
43
|
-
cursorShow: '[MOCK - cursorShow]',
|
44
|
-
cursorTo: (x, y) => `[MOCK - cursorTo(${x}, ${y})]`
|
45
|
-
}));
|
46
36
|
|
47
|
-
const pluginTester = (Plugin,
|
37
|
+
const pluginTester = (Plugin, options = {}) => {
|
48
38
|
const stdout = {
|
49
|
-
columns: 80,
|
39
|
+
columns: (options.stdout || {}).columns || 80,
|
50
40
|
write: jest.fn()
|
51
41
|
};
|
52
42
|
const jestHooks = new _jestWatcher.JestHook();
|
53
43
|
const plugin = new Plugin({
|
54
44
|
stdout,
|
55
|
-
config
|
45
|
+
config: options.config
|
56
46
|
});
|
57
47
|
plugin.apply(jestHooks.getSubscriber());
|
58
48
|
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "jest-watch-typeahead",
|
3
|
-
"version": "0.
|
3
|
+
"version": "0.5.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",
|
@@ -19,36 +19,38 @@
|
|
19
19
|
"test": "jest",
|
20
20
|
"lint": "eslint .",
|
21
21
|
"watch": "babel src -w --ignore **/*.test.js,integration -d build",
|
22
|
+
"prebuild": "rimraf build",
|
22
23
|
"build": "babel src --ignore **/*.test.js,integration -d build",
|
23
24
|
"prepublish": "yarn build",
|
24
25
|
"format": "prettier --single-quote --trailing-comma all --write \"!(build)/**/*.js\""
|
25
26
|
},
|
26
27
|
"dependencies": {
|
27
|
-
"ansi-escapes": "^
|
28
|
-
"chalk": "^
|
29
|
-
"jest-
|
30
|
-
"
|
31
|
-
"
|
32
|
-
"
|
28
|
+
"ansi-escapes": "^4.2.1",
|
29
|
+
"chalk": "^3.0.0",
|
30
|
+
"jest-regex-util": "^25.2.1",
|
31
|
+
"jest-watcher": "^25.2.4",
|
32
|
+
"slash": "^3.0.0",
|
33
|
+
"string-length": "^3.1.0",
|
34
|
+
"strip-ansi": "^6.0.0"
|
33
35
|
},
|
34
36
|
"devDependencies": {
|
35
37
|
"@babel/cli": "^7.0.0",
|
36
38
|
"@babel/core": "^7.0.0",
|
37
39
|
"@babel/preset-env": "^7.0.0",
|
38
40
|
"@babel/preset-flow": "^7.0.0",
|
39
|
-
"babel-core": "^7.0.0-bridge.0",
|
40
41
|
"babel-eslint": "^10.0.1",
|
41
|
-
"babel-jest": "^
|
42
|
-
"eslint": "^
|
43
|
-
"eslint-config-airbnb-base": "^
|
44
|
-
"eslint-config-prettier": "^
|
45
|
-
"eslint-plugin-flowtype": "^
|
42
|
+
"babel-jest": "^25.2.4",
|
43
|
+
"eslint": "^6.2.0",
|
44
|
+
"eslint-config-airbnb-base": "^14.0.0",
|
45
|
+
"eslint-config-prettier": "^6.1.0",
|
46
|
+
"eslint-plugin-flowtype": "^4.2.0",
|
46
47
|
"eslint-plugin-import": "^2.9.0",
|
47
|
-
"eslint-plugin-jest": "^
|
48
|
+
"eslint-plugin-jest": "^23.8.2",
|
48
49
|
"eslint-plugin-prettier": "^3.0.1",
|
49
|
-
"flow-bin": "^0.
|
50
|
-
"jest": "^
|
51
|
-
"prettier": "^1.13.7"
|
50
|
+
"flow-bin": "^0.121.0",
|
51
|
+
"jest": "^25.2.4",
|
52
|
+
"prettier": "^1.13.7",
|
53
|
+
"rimraf": "^3.0.0"
|
52
54
|
},
|
53
55
|
"jest": {
|
54
56
|
"watchPlugins": [
|
@@ -61,6 +63,10 @@
|
|
61
63
|
"testPathIgnorePatterns": [
|
62
64
|
"<rootDir>/build/.*",
|
63
65
|
"<rootDir>/src/__tests__/pluginTester.js"
|
66
|
+
],
|
67
|
+
"transformIgnorePatterns": [
|
68
|
+
"/node_modules/",
|
69
|
+
"/__mocks__/"
|
64
70
|
]
|
65
71
|
}
|
66
72
|
}
|
@@ -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)();
|
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,53 +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
|
-
}) {
|
17
|
-
this._stdin = stdin;
|
18
|
-
this._stdout = stdout;
|
19
|
-
this._prompt = new _jestWatcher.Prompt();
|
20
|
-
this._projects = [];
|
21
|
-
}
|
22
|
-
|
23
|
-
apply(jestHooks) {
|
24
|
-
jestHooks.onFileChange(({ projects }) => {
|
25
|
-
this._projects = projects;
|
26
|
-
});
|
27
|
-
}
|
28
|
-
|
29
|
-
onKey(key) {
|
30
|
-
this._prompt.put(key);
|
31
|
-
}
|
32
|
-
|
33
|
-
run(globalConfig, updateConfigAndRun) {
|
34
|
-
const p = new _file_name_pattern_prompt2.default(this._stdout, this._prompt);
|
35
|
-
p.updateSearchSources(this._projects);
|
36
|
-
return new Promise((res, rej) => {
|
37
|
-
p.run(value => {
|
38
|
-
updateConfigAndRun({ mode: 'watch', testPathPattern: value });
|
39
|
-
res();
|
40
|
-
}, rej);
|
41
|
-
});
|
42
|
-
}
|
43
|
-
|
44
|
-
// eslint-disable-next-line class-methods-use-this
|
45
|
-
getUsageInfo() {
|
46
|
-
return {
|
47
|
-
key: 'p',
|
48
|
-
prompt: 'filter by a filename regex pattern'
|
49
|
-
};
|
50
|
-
}
|
51
|
-
}
|
52
|
-
|
53
|
-
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)();
|
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,53 +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
|
-
}) {
|
17
|
-
this._stdin = stdin;
|
18
|
-
this._stdout = stdout;
|
19
|
-
this._prompt = new _jestWatcher.Prompt();
|
20
|
-
this._testResults = [];
|
21
|
-
}
|
22
|
-
|
23
|
-
apply(jestHooks) {
|
24
|
-
jestHooks.onTestRunComplete(({ testResults }) => {
|
25
|
-
this._testResults = testResults;
|
26
|
-
});
|
27
|
-
}
|
28
|
-
|
29
|
-
onKey(key) {
|
30
|
-
this._prompt.put(key);
|
31
|
-
}
|
32
|
-
|
33
|
-
run(globalConfig, updateConfigAndRun) {
|
34
|
-
const p = new _test_name_pattern_prompt2.default(this._stdout, this._prompt);
|
35
|
-
p.updateCachedTestResults(this._testResults);
|
36
|
-
return new Promise((res, rej) => {
|
37
|
-
p.run(value => {
|
38
|
-
updateConfigAndRun({ mode: 'watch', testNamePattern: value });
|
39
|
-
res();
|
40
|
-
}, rej);
|
41
|
-
});
|
42
|
-
}
|
43
|
-
|
44
|
-
// eslint-disable-next-line class-methods-use-this
|
45
|
-
getUsageInfo() {
|
46
|
-
return {
|
47
|
-
key: 't',
|
48
|
-
prompt: 'filter by a test name regex pattern'
|
49
|
-
};
|
50
|
-
}
|
51
|
-
}
|
52
|
-
|
53
|
-
module.exports = TestNamePlugin;
|