jest-watch-typeahead
Advanced tools
Comparing version 0.1.0 to 0.2.0
@@ -7,6 +7,2 @@ 'use strict'; | ||
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); | ||
var _get = function get(object, property, receiver) { if (object === null) object = Function.prototype; var desc = Object.getOwnPropertyDescriptor(object, property); if (desc === undefined) { var parent = Object.getPrototypeOf(object); if (parent === null) { return undefined; } else { return get(parent, property, receiver); } } else if ("value" in desc) { return desc.value; } else { var getter = desc.get; if (getter === undefined) { return undefined; } return getter.call(receiver); } }; | ||
var _chalk = require('chalk'); | ||
@@ -20,8 +16,6 @@ | ||
var _jestWatcher = require('jest-watcher'); | ||
var _utils = require('./lib/utils'); | ||
var _Prompt = require('./shared/Prompt'); | ||
var _Prompt2 = _interopRequireDefault(_Prompt); | ||
var _pattern_mode_helpers = require('./shared/pattern_mode_helpers'); | ||
@@ -33,118 +27,82 @@ | ||
var _pattern_prompt = require('./shared/pattern_prompt'); | ||
var _pattern_prompt2 = _interopRequireDefault(_pattern_prompt); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
class FileNamePatternPrompt extends _jestWatcher.PatternPrompt { | ||
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; } | ||
constructor(pipe, prompt) { | ||
super(pipe, prompt); | ||
this._entityName = 'filenames'; | ||
this._searchSources = []; | ||
} | ||
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } | ||
_onChange(pattern, options) { | ||
super._onChange(pattern, options); | ||
this._printTypeahead(pattern, options); | ||
} | ||
var FileNamePatternPrompt = function (_PatternPrompt) { | ||
_inherits(FileNamePatternPrompt, _PatternPrompt); | ||
_printTypeahead(pattern, options) { | ||
const matchedTests = this._getMatchedTests(pattern); | ||
const total = matchedTests.length; | ||
const pipe = this._pipe; | ||
const prompt = this._prompt; | ||
function FileNamePatternPrompt(pipe, prompt) { | ||
_classCallCheck(this, FileNamePatternPrompt); | ||
(0, _jestWatcher.printPatternCaret)(pattern, pipe); | ||
var _this = _possibleConstructorReturn(this, (FileNamePatternPrompt.__proto__ || Object.getPrototypeOf(FileNamePatternPrompt)).call(this, pipe, prompt)); | ||
if (pattern) { | ||
(0, _pattern_mode_helpers.printPatternMatches)(total, 'file', pipe); | ||
_this._entityName = 'filenames'; | ||
_this._searchSources = []; | ||
return _this; | ||
} | ||
const prefix = ` ${_chalk2.default.dim('\u203A')} `; | ||
const padding = (0, _stringLength2.default)(prefix) + 2; | ||
const width = (0, _utils.getTerminalWidth)(pipe); | ||
_createClass(FileNamePatternPrompt, [{ | ||
key: '_onChange', | ||
value: function _onChange(pattern, options) { | ||
_get(FileNamePatternPrompt.prototype.__proto__ || Object.getPrototypeOf(FileNamePatternPrompt.prototype), '_onChange', this).call(this, pattern, options); | ||
this._printTypeahead(pattern, options); | ||
} | ||
}, { | ||
key: '_printTypeahead', | ||
value: function _printTypeahead(pattern, options) { | ||
var matchedTests = this._getMatchedTests(pattern); | ||
var total = matchedTests.length; | ||
var pipe = this._pipe; | ||
var prompt = this._prompt; | ||
var _scroll = (0, _scroll3.default)(total, options); | ||
(0, _pattern_mode_helpers.printPatternCaret)(pattern, pipe); | ||
if (pattern) { | ||
(0, _pattern_mode_helpers.printPatternMatches)(total, 'file', pipe); | ||
var prefix = ` ${_chalk2.default.dim('\u203A')} `; | ||
var padding = (0, _stringLength2.default)(prefix) + 2; | ||
var width = (0, _utils.getTerminalWidth)(); | ||
var _scroll = (0, _scroll3.default)(total, options), | ||
start = _scroll.start, | ||
const start = _scroll.start, | ||
end = _scroll.end, | ||
index = _scroll.index; | ||
prompt.setTypeaheadLength(total); | ||
matchedTests.slice(start, end).map(function (_ref) { | ||
var path = _ref.path, | ||
context = _ref.context; | ||
prompt.setPromptLength(total); | ||
var filePath = (0, _utils.trimAndFormatPath)(padding, context.config, path, width); | ||
return (0, _utils.highlight)(path, filePath, pattern, context.config.rootDir); | ||
}).map(function (item, i) { | ||
return (0, _pattern_mode_helpers.formatTypeaheadSelection)(item, i, index, prompt); | ||
}).forEach(function (item) { | ||
return (0, _pattern_mode_helpers.printTypeaheadItem)(item, pipe); | ||
}); | ||
matchedTests.slice(start, end).map(({ path, context }) => { | ||
const filePath = (0, _utils.trimAndFormatPath)(padding, context.config, path, width); | ||
return (0, _utils.highlight)(path, filePath, pattern, context.config.rootDir); | ||
}).map((item, i) => (0, _pattern_mode_helpers.formatTypeaheadSelection)(item, i, index, prompt)).forEach(item => (0, _pattern_mode_helpers.printTypeaheadItem)(item, pipe)); | ||
if (total > end) { | ||
(0, _pattern_mode_helpers.printMore)('file', pipe, total - end); | ||
} | ||
} else { | ||
(0, _pattern_mode_helpers.printStartTyping)('filename', pipe); | ||
if (total > end) { | ||
(0, _pattern_mode_helpers.printMore)('file', pipe, total - end); | ||
} | ||
(0, _pattern_mode_helpers.printRestoredPatternCaret)(pattern, this._currentUsageRows, pipe); | ||
} else { | ||
(0, _pattern_mode_helpers.printStartTyping)('filename', pipe); | ||
} | ||
}, { | ||
key: '_getMatchedTests', | ||
value: function _getMatchedTests(pattern) { | ||
var regex = void 0; | ||
try { | ||
regex = new RegExp(pattern, 'i'); | ||
} catch (e) { | ||
regex = null; | ||
} | ||
(0, _jestWatcher.printRestoredPatternCaret)(pattern, this._currentUsageRows, pipe); | ||
} | ||
var tests = []; | ||
if (regex) { | ||
this._searchSources.forEach(function (_ref2) { | ||
var testPaths = _ref2.testPaths, | ||
config = _ref2.config; | ||
_getMatchedTests(pattern) { | ||
let regex; | ||
tests = tests.concat(testPaths.filter(function (testPath) { | ||
return testPath.match(pattern); | ||
}).map(function (path) { | ||
return { | ||
path, | ||
context: { config } | ||
}; | ||
})); | ||
}); | ||
} | ||
try { | ||
regex = new RegExp(pattern, 'i'); | ||
} catch (e) { | ||
regex = null; | ||
} | ||
return tests; | ||
let tests = []; | ||
if (regex) { | ||
this._searchSources.forEach(({ testPaths, config }) => { | ||
tests = tests.concat(testPaths.filter(testPath => testPath.match(pattern)).map(path => ({ | ||
path, | ||
context: { config } | ||
}))); | ||
}); | ||
} | ||
}, { | ||
key: 'updateSearchSources', | ||
value: function updateSearchSources(searchSources) { | ||
this._searchSources = searchSources; | ||
} | ||
}]); | ||
return FileNamePatternPrompt; | ||
}(_pattern_prompt2.default); | ||
return tests; | ||
} | ||
updateSearchSources(searchSources) { | ||
this._searchSources = searchSources; | ||
} | ||
} | ||
exports.default = FileNamePatternPrompt; |
'use strict'; | ||
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); | ||
var _jestWatcher = require('jest-watcher'); | ||
var _Prompt = require('./shared/Prompt'); | ||
var _Prompt2 = _interopRequireDefault(_Prompt); | ||
var _file_name_pattern_prompt = require('./file_name_pattern_prompt'); | ||
@@ -15,61 +11,45 @@ | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
class FileNamePlugin { | ||
var FileNamePlugin = function () { | ||
function FileNamePlugin(_ref) { | ||
var stdin = _ref.stdin, | ||
stdout = _ref.stdout; | ||
_classCallCheck(this, FileNamePlugin); | ||
constructor({ | ||
stdin, | ||
stdout, | ||
config = {} | ||
}) { | ||
this._stdin = stdin; | ||
this._stdout = stdout; | ||
this._prompt = new _Prompt2.default(); | ||
this._prompt = new _jestWatcher.Prompt(); | ||
this._projects = []; | ||
this._usageInfo = { | ||
key: config.key || 'p', | ||
prompt: config.prompt || 'filter by a filename regex pattern' | ||
}; | ||
} | ||
_createClass(FileNamePlugin, [{ | ||
key: 'apply', | ||
value: function apply(jestHooks) { | ||
var _this = this; | ||
apply(jestHooks) { | ||
jestHooks.onFileChange(({ projects }) => { | ||
this._projects = projects; | ||
}); | ||
} | ||
jestHooks.onFileChange(function (_ref2) { | ||
var projects = _ref2.projects; | ||
onKey(key) { | ||
this._prompt.put(key); | ||
} | ||
_this._projects = projects; | ||
}); | ||
} | ||
}, { | ||
key: 'onKey', | ||
value: function onKey(key) { | ||
this._prompt.put(key); | ||
} | ||
}, { | ||
key: 'run', | ||
value: function run(globalConfig, updateConfigAndRun) { | ||
var p = new _file_name_pattern_prompt2.default(this._stdout, this._prompt); | ||
p.updateSearchSources(this._projects); | ||
return new Promise(function (res, rej) { | ||
p.run(function (value) { | ||
updateConfigAndRun({ mode: 'watch', testPathPattern: value }); | ||
res(); | ||
}, rej); | ||
}); | ||
} | ||
run(globalConfig, updateConfigAndRun) { | ||
const p = new _file_name_pattern_prompt2.default(this._stdout, this._prompt); | ||
p.updateSearchSources(this._projects); | ||
return new Promise((res, rej) => { | ||
p.run(value => { | ||
updateConfigAndRun({ mode: 'watch', testPathPattern: value }); | ||
res(); | ||
}, rej); | ||
}); | ||
} | ||
// eslint-disable-next-line class-methods-use-this | ||
getUsageInfo() { | ||
return this._usageInfo; | ||
} | ||
} | ||
}, { | ||
key: 'getUsageInfo', | ||
value: function getUsageInfo() { | ||
return { | ||
key: 'p', | ||
prompt: 'filter by a filename regex pattern' | ||
}; | ||
} | ||
}]); | ||
return FileNamePlugin; | ||
}(); | ||
module.exports = FileNamePlugin; |
@@ -27,18 +27,16 @@ 'use strict'; | ||
/* eslint-disable no-param-reassign */ | ||
var relativePath = function relativePath(config, testPath) { | ||
const relativePath = (config, testPath) => { | ||
testPath = _path2.default.relative(config.cwd || config.rootDir, testPath); | ||
var dirname = _path2.default.dirname(testPath); | ||
var basename = _path2.default.basename(testPath); | ||
const dirname = _path2.default.dirname(testPath); | ||
const basename = _path2.default.basename(testPath); | ||
return { basename, dirname }; | ||
}; | ||
var colorize = function colorize(str, start, end) { | ||
return _chalk2.default.dim(str.slice(0, start)) + _chalk2.default.reset(str.slice(start, end)) + _chalk2.default.dim(str.slice(end)); | ||
}; | ||
const colorize = (str, start, end) => _chalk2.default.dim(str.slice(0, start)) + _chalk2.default.reset(str.slice(start, end)) + _chalk2.default.dim(str.slice(end)); | ||
var trimAndFormatPath = exports.trimAndFormatPath = function trimAndFormatPath(pad, config, testPath, columns) { | ||
var maxLength = columns - pad; | ||
var relative = relativePath(config, testPath); | ||
var basename = relative.basename; | ||
var dirname = relative.dirname; | ||
const trimAndFormatPath = exports.trimAndFormatPath = (pad, config, testPath, columns) => { | ||
const maxLength = columns - pad; | ||
const relative = relativePath(config, testPath); | ||
const basename = relative.basename; | ||
let dirname = relative.dirname; | ||
@@ -52,5 +50,5 @@ // length is ok | ||
// we can fit trimmed dirname and full basename | ||
var basenameLength = basename.length; | ||
const basenameLength = basename.length; | ||
if (basenameLength + 4 < maxLength) { | ||
var dirnameLength = maxLength - 4 - basenameLength; | ||
const dirnameLength = maxLength - 4 - basenameLength; | ||
dirname = `...${dirname.slice(dirname.length - dirnameLength, dirname.length)}`; | ||
@@ -68,12 +66,9 @@ return (0, _slash2.default)(_chalk2.default.dim(dirname + _path2.default.sep) + _chalk2.default.bold(basename)); | ||
// $FlowFixMe | ||
var getTerminalWidth = exports.getTerminalWidth = function getTerminalWidth() { | ||
return process.stdout.columns; | ||
}; | ||
const getTerminalWidth = exports.getTerminalWidth = (pipe = process.stdout) => pipe.columns; | ||
var highlight = exports.highlight = function highlight(rawPath, filePath, pattern, rootDir) { | ||
var trim = '...'; | ||
var relativePathHead = './'; | ||
const highlight = exports.highlight = (rawPath, filePath, pattern, rootDir) => { | ||
const trim = '...'; | ||
const relativePathHead = './'; | ||
var regexp = void 0; | ||
let regexp; | ||
@@ -88,3 +83,3 @@ try { | ||
filePath = (0, _stripAnsi2.default)(filePath); | ||
var match = rawPath.match(regexp); | ||
const match = rawPath.match(regexp); | ||
@@ -95,4 +90,4 @@ if (!match) { | ||
var offset = void 0; | ||
var trimLength = void 0; | ||
let offset; | ||
let trimLength; | ||
@@ -110,14 +105,14 @@ if (filePath.startsWith(trim)) { | ||
var start = match.index - offset; | ||
var end = start + match[0].length; | ||
const start = match.index - offset; | ||
const end = start + match[0].length; | ||
return colorize(filePath, Math.max(start, 0), Math.max(end, trimLength)); | ||
}; | ||
var DOTS = '...'; | ||
var ENTER = '⏎'; | ||
const DOTS = '...'; | ||
const ENTER = '⏎'; | ||
var formatTestNameByPattern = exports.formatTestNameByPattern = function formatTestNameByPattern(testName, pattern, width) { | ||
var inlineTestName = testName.replace(/(\r\n|\n|\r)/gm, ENTER); | ||
const formatTestNameByPattern = exports.formatTestNameByPattern = (testName, pattern, width) => { | ||
const inlineTestName = testName.replace(/(\r\n|\n|\r)/gm, ENTER); | ||
var regexp = void 0; | ||
let regexp; | ||
@@ -130,3 +125,3 @@ try { | ||
var match = inlineTestName.match(regexp); | ||
const match = inlineTestName.match(regexp); | ||
@@ -138,4 +133,4 @@ if (!match) { | ||
// $FlowFixMe | ||
var startPatternIndex = Math.max(match.index, 0); | ||
var endPatternIndex = startPatternIndex + match[0].length; | ||
const startPatternIndex = Math.max(match.index, 0); | ||
const endPatternIndex = startPatternIndex + match[0].length; | ||
@@ -146,3 +141,3 @@ if (inlineTestName.length <= width) { | ||
var slicedTestName = inlineTestName.slice(0, width - DOTS.length); | ||
const slicedTestName = inlineTestName.slice(0, width - DOTS.length); | ||
@@ -149,0 +144,0 @@ if (startPatternIndex < slicedTestName.length) { |
@@ -6,3 +6,3 @@ 'use strict'; | ||
}); | ||
exports.formatTypeaheadSelection = exports.printTypeaheadItem = exports.printMore = exports.printStartTyping = exports.printRestoredPatternCaret = exports.printPatternCaret = exports.printPatternMatches = undefined; | ||
exports.formatTypeaheadSelection = exports.printTypeaheadItem = exports.printMore = exports.printStartTyping = exports.printPatternMatches = undefined; | ||
@@ -13,10 +13,2 @@ var _chalk = require('chalk'); | ||
var _ansiEscapes = require('ansi-escapes'); | ||
var _ansiEscapes2 = _interopRequireDefault(_ansiEscapes); | ||
var _stringLength = require('string-length'); | ||
var _stringLength2 = _interopRequireDefault(_stringLength); | ||
var _stripAnsi = require('strip-ansi'); | ||
@@ -26,51 +18,28 @@ | ||
var _Prompt = require('../shared/Prompt'); | ||
var _jestWatcher = require('jest-watcher'); | ||
var _Prompt2 = _interopRequireDefault(_Prompt); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
var pluralize = function pluralize(count, text) { | ||
return count === 1 ? text : `${text}s`; | ||
}; | ||
const pluralize = (count, text) => count === 1 ? text : `${text}s`; | ||
var printPatternMatches = exports.printPatternMatches = function printPatternMatches(count, entity, pipe) { | ||
var extraText = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : ''; | ||
const printPatternMatches = exports.printPatternMatches = (count, entity, pipe, extraText = '') => { | ||
const pluralized = pluralize(count, entity); | ||
const result = count ? `\n\n Pattern matches ${count} ${pluralized}` : `\n\n Pattern matches no ${pluralized}`; | ||
var pluralized = pluralize(count, entity); | ||
var result = count ? `\n\n Pattern matches ${count} ${pluralized}` : `\n\n Pattern matches no ${pluralized}`; | ||
pipe.write(result + extraText); | ||
}; | ||
var printPatternCaret = exports.printPatternCaret = function printPatternCaret(pattern, pipe) { | ||
var inputText = `${_chalk2.default.dim(' pattern \u203A')} ${pattern}`; | ||
pipe.write(_ansiEscapes2.default.eraseDown); | ||
pipe.write(inputText); | ||
pipe.write(_ansiEscapes2.default.cursorSavePosition); | ||
}; | ||
var printRestoredPatternCaret = exports.printRestoredPatternCaret = function printRestoredPatternCaret(pattern, currentUsageRows, pipe) { | ||
var inputText = `${_chalk2.default.dim(' pattern \u203A')} ${pattern}`; | ||
pipe.write(_ansiEscapes2.default.cursorTo((0, _stringLength2.default)(inputText), currentUsageRows - 1)); | ||
pipe.write(_ansiEscapes2.default.cursorRestorePosition); | ||
}; | ||
var printStartTyping = exports.printStartTyping = function printStartTyping(entity, pipe) { | ||
const printStartTyping = exports.printStartTyping = (entity, pipe) => { | ||
pipe.write(`\n\n ${_chalk2.default.italic.yellow(`Start typing to filter by a ${entity} regex pattern.`)}`); | ||
}; | ||
var printMore = exports.printMore = function printMore(entity, pipe, more) { | ||
const printMore = exports.printMore = (entity, pipe, more) => { | ||
pipe.write(`\n ${_chalk2.default.dim(`...and ${more} more ${pluralize(more, entity)}`)}`); | ||
}; | ||
var printTypeaheadItem = exports.printTypeaheadItem = function printTypeaheadItem(item, pipe) { | ||
return pipe.write(`\n ${_chalk2.default.dim('\u203A')} ${item}`); | ||
}; | ||
const printTypeaheadItem = exports.printTypeaheadItem = (item, pipe) => pipe.write(`\n ${_chalk2.default.dim('\u203A')} ${item}`); | ||
var formatTypeaheadSelection = exports.formatTypeaheadSelection = function formatTypeaheadSelection(item, index, activeIndex, prompt) { | ||
const formatTypeaheadSelection = exports.formatTypeaheadSelection = (item, index, activeIndex, prompt) => { | ||
if (index === activeIndex) { | ||
prompt.setTypheadheadSelection((0, _stripAnsi2.default)(item)); | ||
prompt.setPromptSelection((0, _stripAnsi2.default)(item)); | ||
return _chalk2.default.black.bgYellow((0, _stripAnsi2.default)(item)); | ||
@@ -77,0 +46,0 @@ } |
@@ -8,11 +8,8 @@ "use strict"; | ||
var scroll = function scroll(size, _ref) { | ||
var offset = _ref.offset, | ||
max = _ref.max; | ||
const scroll = (size, { offset, max }) => { | ||
let start = 0; | ||
let index = Math.min(offset, size); | ||
var start = 0; | ||
var index = Math.min(offset, size); | ||
const halfScreen = max / 2; | ||
var halfScreen = max / 2; | ||
if (index <= halfScreen) { | ||
@@ -19,0 +16,0 @@ start = 0; |
'use strict'; | ||
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); | ||
var _get = function get(object, property, receiver) { if (object === null) object = Function.prototype; var desc = Object.getOwnPropertyDescriptor(object, property); if (desc === undefined) { var parent = Object.getPrototypeOf(object); if (parent === null) { return undefined; } else { return get(parent, property, receiver); } } else if ("value" in desc) { return desc.value; } else { var getter = desc.get; if (getter === undefined) { return undefined; } return getter.call(receiver); } }; | ||
var _chalk = require('chalk'); | ||
@@ -11,2 +7,4 @@ | ||
var _jestWatcher = require('jest-watcher'); | ||
var _scroll2 = require('./shared/scroll'); | ||
@@ -18,116 +16,78 @@ | ||
var _Prompt = require('./shared/Prompt'); | ||
var _Prompt2 = _interopRequireDefault(_Prompt); | ||
var _pattern_mode_helpers = require('./shared/pattern_mode_helpers'); | ||
var _pattern_prompt = require('./shared/pattern_prompt'); | ||
var _pattern_prompt2 = _interopRequireDefault(_pattern_prompt); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
class TestNamePatternPrompt extends _jestWatcher.PatternPrompt { | ||
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; } | ||
constructor(pipe, prompt) { | ||
super(pipe, prompt); | ||
this._entityName = 'tests'; | ||
this._cachedTestResults = []; | ||
} | ||
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } | ||
_onChange(pattern, options) { | ||
super._onChange(pattern, options); | ||
this._printTypeahead(pattern, options); | ||
} | ||
var TestNamePatternPrompt = function (_PatternPrompt) { | ||
_inherits(TestNamePatternPrompt, _PatternPrompt); | ||
_printTypeahead(pattern, options) { | ||
const matchedTests = this._getMatchedTests(pattern); | ||
const total = matchedTests.length; | ||
const pipe = this._pipe; | ||
const prompt = this._prompt; | ||
function TestNamePatternPrompt(pipe, prompt) { | ||
_classCallCheck(this, TestNamePatternPrompt); | ||
(0, _jestWatcher.printPatternCaret)(pattern, pipe); | ||
var _this = _possibleConstructorReturn(this, (TestNamePatternPrompt.__proto__ || Object.getPrototypeOf(TestNamePatternPrompt)).call(this, pipe, prompt)); | ||
if (pattern) { | ||
(0, _pattern_mode_helpers.printPatternMatches)(total, 'test', pipe, ` from ${_chalk2.default.yellow('cached')} test suites`); | ||
_this._entityName = 'tests'; | ||
_this._cachedTestResults = []; | ||
return _this; | ||
} | ||
const width = (0, _utils.getTerminalWidth)(pipe); | ||
_createClass(TestNamePatternPrompt, [{ | ||
key: '_onChange', | ||
value: function _onChange(pattern, options) { | ||
_get(TestNamePatternPrompt.prototype.__proto__ || Object.getPrototypeOf(TestNamePatternPrompt.prototype), '_onChange', this).call(this, pattern, options); | ||
this._printTypeahead(pattern, options); | ||
} | ||
}, { | ||
key: '_printTypeahead', | ||
value: function _printTypeahead(pattern, options) { | ||
var matchedTests = this._getMatchedTests(pattern); | ||
var total = matchedTests.length; | ||
var pipe = this._pipe; | ||
var prompt = this._prompt; | ||
var _scroll = (0, _scroll3.default)(total, options); | ||
(0, _pattern_mode_helpers.printPatternCaret)(pattern, pipe); | ||
if (pattern) { | ||
(0, _pattern_mode_helpers.printPatternMatches)(total, 'test', pipe, ` from ${_chalk2.default.yellow('cached')} test suites`); | ||
var width = (0, _utils.getTerminalWidth)(); | ||
var _scroll = (0, _scroll3.default)(total, options), | ||
start = _scroll.start, | ||
const start = _scroll.start, | ||
end = _scroll.end, | ||
index = _scroll.index; | ||
prompt.setTypeaheadLength(total); | ||
matchedTests.slice(start, end).map(function (name) { | ||
return (0, _utils.formatTestNameByPattern)(name, pattern, width - 4); | ||
}).map(function (item, i) { | ||
return (0, _pattern_mode_helpers.formatTypeaheadSelection)(item, i, index, prompt); | ||
}).forEach(function (item) { | ||
return (0, _pattern_mode_helpers.printTypeaheadItem)(item, pipe); | ||
}); | ||
prompt.setPromptLength(total); | ||
if (total > end) { | ||
(0, _pattern_mode_helpers.printMore)('test', pipe, total - end); | ||
} | ||
} else { | ||
(0, _pattern_mode_helpers.printStartTyping)('test name', pipe); | ||
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)); | ||
if (total > end) { | ||
(0, _pattern_mode_helpers.printMore)('test', pipe, total - end); | ||
} | ||
(0, _pattern_mode_helpers.printRestoredPatternCaret)(pattern, this._currentUsageRows, pipe); | ||
} else { | ||
(0, _pattern_mode_helpers.printStartTyping)('test name', pipe); | ||
} | ||
}, { | ||
key: '_getMatchedTests', | ||
value: function _getMatchedTests(pattern) { | ||
var regex = void 0; | ||
try { | ||
regex = new RegExp(pattern, 'i'); | ||
} catch (e) { | ||
return []; | ||
} | ||
(0, _jestWatcher.printRestoredPatternCaret)(pattern, this._currentUsageRows, pipe); | ||
} | ||
var matchedTests = []; | ||
_getMatchedTests(pattern) { | ||
let regex; | ||
this._cachedTestResults.forEach(function (_ref) { | ||
var testResults = _ref.testResults; | ||
return testResults.forEach(function (_ref2) { | ||
var title = _ref2.title; | ||
try { | ||
regex = new RegExp(pattern, 'i'); | ||
} catch (e) { | ||
return []; | ||
} | ||
if (regex.test(title)) { | ||
matchedTests.push(title); | ||
} | ||
}); | ||
}); | ||
const matchedTests = []; | ||
return matchedTests; | ||
} | ||
}, { | ||
key: 'updateCachedTestResults', | ||
value: function updateCachedTestResults() { | ||
var testResults = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : []; | ||
this._cachedTestResults.forEach(({ testResults }) => testResults.forEach(({ title }) => { | ||
if (regex.test(title)) { | ||
matchedTests.push(title); | ||
} | ||
})); | ||
this._cachedTestResults = testResults; | ||
} | ||
}]); | ||
return matchedTests; | ||
} | ||
return TestNamePatternPrompt; | ||
}(_pattern_prompt2.default); | ||
updateCachedTestResults(testResults = []) { | ||
this._cachedTestResults = testResults; | ||
} | ||
} | ||
module.exports = TestNamePatternPrompt; |
'use strict'; | ||
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); | ||
var _jestWatcher = require('jest-watcher'); | ||
var _Prompt = require('./shared/Prompt'); | ||
var _Prompt2 = _interopRequireDefault(_Prompt); | ||
var _test_name_pattern_prompt = require('./test_name_pattern_prompt'); | ||
@@ -15,61 +11,45 @@ | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
class TestNamePlugin { | ||
var TestNamePlugin = function () { | ||
function TestNamePlugin(_ref) { | ||
var stdin = _ref.stdin, | ||
stdout = _ref.stdout; | ||
_classCallCheck(this, TestNamePlugin); | ||
constructor({ | ||
stdin, | ||
stdout, | ||
config = {} | ||
}) { | ||
this._stdin = stdin; | ||
this._stdout = stdout; | ||
this._prompt = new _Prompt2.default(); | ||
this._prompt = new _jestWatcher.Prompt(); | ||
this._testResults = []; | ||
this._usageInfo = { | ||
key: config.key || 't', | ||
prompt: config.prompt || 'filter by a test name regex pattern' | ||
}; | ||
} | ||
_createClass(TestNamePlugin, [{ | ||
key: 'apply', | ||
value: function apply(jestHooks) { | ||
var _this = this; | ||
apply(jestHooks) { | ||
jestHooks.onTestRunComplete(({ testResults }) => { | ||
this._testResults = testResults; | ||
}); | ||
} | ||
jestHooks.onTestRunComplete(function (_ref2) { | ||
var testResults = _ref2.testResults; | ||
onKey(key) { | ||
this._prompt.put(key); | ||
} | ||
_this._testResults = testResults; | ||
}); | ||
} | ||
}, { | ||
key: 'onKey', | ||
value: function onKey(key) { | ||
this._prompt.put(key); | ||
} | ||
}, { | ||
key: 'run', | ||
value: function run(globalConfig, updateConfigAndRun) { | ||
var p = new _test_name_pattern_prompt2.default(this._stdout, this._prompt); | ||
p.updateCachedTestResults(this._testResults); | ||
return new Promise(function (res, rej) { | ||
p.run(function (value) { | ||
updateConfigAndRun({ mode: 'watch', testNamePattern: value }); | ||
res(); | ||
}, rej); | ||
}); | ||
} | ||
run(globalConfig, updateConfigAndRun) { | ||
const p = new _test_name_pattern_prompt2.default(this._stdout, this._prompt); | ||
p.updateCachedTestResults(this._testResults); | ||
return new Promise((res, rej) => { | ||
p.run(value => { | ||
updateConfigAndRun({ mode: 'watch', testNamePattern: value }); | ||
res(); | ||
}, rej); | ||
}); | ||
} | ||
// eslint-disable-next-line class-methods-use-this | ||
getUsageInfo() { | ||
return this._usageInfo; | ||
} | ||
} | ||
}, { | ||
key: 'getUsageInfo', | ||
value: function getUsageInfo() { | ||
return { | ||
key: 't', | ||
prompt: 'filter by a test name regex pattern' | ||
}; | ||
} | ||
}]); | ||
return TestNamePlugin; | ||
}(); | ||
module.exports = TestNamePlugin; |
## master | ||
## 0.2.0 | ||
### Features | ||
* Add test name typeahead ([#1](https://github.com/jest-community/jest-watch-typeahead/pull/1)) | ||
* Rename to jest-watch-typeahead | ||
- Add support for plugin config ([#13](https://github.com/jest-community/jest-watch-typeahead/pull/13)) | ||
### 0.0.1 | ||
### Fixes | ||
- Make matching case insensitive ([#18](https://github.com/jest-community/jest-watch-typeahead/pull/18)) | ||
- fix: migrate to use jest-watcher ([#6](https://github.com/jest-community/jest-watch-typeahead/pull/6)) | ||
### Chore & Maintenance | ||
- Upgrade Prettier to 1.13.7 ([#17](https://github.com/jest-community/jest-watch-typeahead/pull/17)) | ||
- New directory structure ([#14](https://github.com/jest-community/jest-watch-typeahead/pull/14)) | ||
- Move ansi-escapes to dependencies _23f22d4_ | ||
- Setup Travis and add tests ([#12](https://github.com/jest-community/jest-watch-typeahead/pull/12)) | ||
## 0.1.0 | ||
### Features | ||
- Add test name typeahead ([#1](https://github.com/jest-community/jest-watch-typeahead/pull/1)) | ||
- Rename to jest-watch-typeahead | ||
## 0.0.1 | ||
Initial Release |
@@ -1,3 +0,3 @@ | ||
const FileNamePlugin = require('./build/file_name_plugin'); | ||
const FileNamePlugin = require('./build/file_name_plugin/plugin'); | ||
module.exports = FileNamePlugin; |
{ | ||
"name": "jest-watch-typeahead", | ||
"version": "0.1.0", | ||
"version": "0.2.0", | ||
"main": "build/index.js", | ||
@@ -27,5 +27,4 @@ "author": "Rogelio Guzman <rogelioguzmanh@gmail.com>", | ||
"dependencies": { | ||
"ansi-escapes": "^3.0.0", | ||
"chalk": "^2.3.1", | ||
"lodash": "4.17.5", | ||
"chalk": "^2.4.1", | ||
"jest-watcher": "^23.1.0", | ||
"slash": "^1.0.0", | ||
@@ -48,5 +47,18 @@ "string-length": "^2.0.0", | ||
"flow-bin": "^0.66.0", | ||
"jest": "22.4.2", | ||
"prettier": "1.11.1" | ||
"jest": "23.2.0", | ||
"prettier": "1.13.7" | ||
}, | ||
"jest": { | ||
"watchPlugins": [ | ||
"<rootDir>/filename", | ||
"<rootDir>/testname" | ||
], | ||
"snapshotSerializers": [ | ||
"<rootDir>/node_modules/pretty-format/build/plugins/convert_ansi" | ||
], | ||
"testPathIgnorePatterns": [ | ||
"<rootDir>/build/.*", | ||
"<rootDir>/src/__tests__/pluginTester.js" | ||
] | ||
} | ||
} |
@@ -54,2 +54,18 @@ [![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) | ||
### Configuring your key and prompt name | ||
```js | ||
module.exports = { | ||
watchPlugins: [ | ||
[ | ||
'jest-watch-typeahead/filename', | ||
{ | ||
key: 'k', | ||
prompt: 'do something with my custom prompt', | ||
}, | ||
], | ||
], | ||
}; | ||
``` | ||
### Run Jest in watch mode | ||
@@ -56,0 +72,0 @@ |
@@ -1,3 +0,3 @@ | ||
const TestNamePlugin = require('./build/test_name_plugin'); | ||
const TestNamePlugin = require('./build/test_name_plugin/plugin'); | ||
module.exports = TestNamePlugin; |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
5
22
75
32790
712
1
+ Addedjest-watcher@^23.1.0
+ Addedjest-watcher@23.4.0(transitive)
- Removedansi-escapes@^3.0.0
- Removedlodash@4.17.5
- Removedlodash@4.17.5(transitive)
Updatedchalk@^2.4.1