Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

jest-watch-typeahead

Package Overview
Dependencies
Maintainers
2
Versions
30
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

jest-watch-typeahead - npm Package Compare versions

Comparing version 0.2.0 to 0.2.1

2

build/file_name_pattern_prompt.js

@@ -53,3 +53,3 @@ 'use strict';

const padding = (0, _stringLength2.default)(prefix) + 2;
const width = (0, _utils.getTerminalWidth)(pipe);
const width = (0, _utils.getTerminalWidth)();

@@ -56,0 +56,0 @@ var _scroll = (0, _scroll3.default)(total, options);

@@ -15,4 +15,3 @@ 'use strict';

stdin,
stdout,
config = {}
stdout
}) {

@@ -23,6 +22,2 @@ this._stdin = stdin;

this._projects = [];
this._usageInfo = {
key: config.key || 'p',
prompt: config.prompt || 'filter by a filename regex pattern'
};
}

@@ -51,4 +46,8 @@

// eslint-disable-next-line class-methods-use-this
getUsageInfo() {
return this._usageInfo;
return {
key: 'p',
prompt: 'filter by a filename regex pattern'
};
}

@@ -55,0 +54,0 @@ }

@@ -1,13 +0,10 @@

'use strict';
"use strict";
var _jestWatcher = require('jest-watcher');
var _jestWatcher = require("jest-watcher");
var _prompt = require('./prompt');
var _prompt = _interopRequireDefault(require("./prompt"));
var _prompt2 = _interopRequireDefault(_prompt);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
class FileNamePlugin {
constructor({

@@ -29,3 +26,5 @@ stdin,

apply(jestHooks) {
jestHooks.onFileChange(({ projects }) => {
jestHooks.onFileChange(({
projects
}) => {
this._projects = projects;

@@ -40,7 +39,10 @@ });

run(globalConfig, updateConfigAndRun) {
const p = new _prompt2.default(this._stdout, this._prompt);
const p = new _prompt.default(this._stdout, this._prompt);
p.updateSearchSources(this._projects);
return new Promise((res, rej) => {
p.run(value => {
updateConfigAndRun({ mode: 'watch', testPathPattern: value });
updateConfigAndRun({
mode: 'watch',
testPathPattern: value
});
res();

@@ -54,4 +56,5 @@ }, rej);

}
}
module.exports = FileNamePlugin;

@@ -1,2 +0,2 @@

'use strict';
"use strict";

@@ -6,25 +6,21 @@ Object.defineProperty(exports, "__esModule", {

});
exports.default = void 0;
var _chalk = require('chalk');
var _chalk = _interopRequireDefault(require("chalk"));
var _chalk2 = _interopRequireDefault(_chalk);
var _ansiEscapes = _interopRequireDefault(require("ansi-escapes"));
var _stringLength = require('string-length');
var _stringLength = _interopRequireDefault(require("string-length"));
var _stringLength2 = _interopRequireDefault(_stringLength);
var _jestWatcher = require("jest-watcher");
var _jestWatcher = require('jest-watcher');
var _utils = require("../lib/utils");
var _utils = require('../lib/utils');
var _pattern_mode_helpers = require("../lib/pattern_mode_helpers");
var _pattern_mode_helpers = require('../lib/pattern_mode_helpers');
var _scroll2 = _interopRequireDefault(require("../lib/scroll"));
var _scroll2 = require('../lib/scroll');
var _scroll3 = _interopRequireDefault(_scroll2);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
class FileNamePatternPrompt extends _jestWatcher.PatternPrompt {
constructor(pipe, prompt) {

@@ -38,2 +34,3 @@ super(pipe, prompt);

super._onChange(pattern, options);
this._printTypeahead(pattern, options);

@@ -44,25 +41,25 @@ }

const matchedTests = this._getMatchedTests(pattern);
const total = matchedTests.length;
const pipe = this._pipe;
const prompt = this._prompt;
(0, _jestWatcher.printPatternCaret)(pattern, pipe);
pipe.write(_ansiEscapes.default.cursorLeft);
if (pattern) {
(0, _pattern_mode_helpers.printPatternMatches)(total, 'file', pipe);
const prefix = ` ${_chalk2.default.dim('\u203A')} `;
const padding = (0, _stringLength2.default)(prefix) + 2;
const prefix = ` ${_chalk.default.dim('\u203A')} `;
const padding = (0, _stringLength.default)(prefix) + 2;
const width = (0, _utils.getTerminalWidth)(pipe);
var _scroll = (0, _scroll3.default)(total, options);
const start = _scroll.start,
const _scroll = (0, _scroll2.default)(total, options),
start = _scroll.start,
end = _scroll.end,
index = _scroll.index;
prompt.setPromptLength(total);
matchedTests.slice(start, end).map(({ path, context }) => {
matchedTests.slice(start, end).map(({
path,
context
}) => {
const filePath = (0, _utils.trimAndFormatPath)(padding, context.config, path, width);

@@ -91,6 +88,11 @@ return (0, _utils.highlight)(path, filePath, pattern, context.config.rootDir);

return this._searchSources.reduce((tests, { testPaths, config }) => {
return this._searchSources.reduce((tests, {
testPaths,
config
}) => {
return tests.concat(testPaths.filter(testPath => regex.test(testPath)).map(path => ({
path,
context: { config }
context: {
config
}
})));

@@ -103,3 +105,5 @@ }, []);

}
}
exports.default = FileNamePatternPrompt;

@@ -1,2 +0,2 @@

'use strict';
"use strict";

@@ -6,14 +6,10 @@ Object.defineProperty(exports, "__esModule", {

});
exports.formatTypeaheadSelection = exports.printTypeaheadItem = exports.printMore = exports.printStartTyping = exports.printPatternMatches = undefined;
exports.formatTypeaheadSelection = exports.printTypeaheadItem = exports.printMore = exports.printStartTyping = exports.printPatternMatches = void 0;
var _chalk = require('chalk');
var _chalk = _interopRequireDefault(require("chalk"));
var _chalk2 = _interopRequireDefault(_chalk);
var _stripAnsi = _interopRequireDefault(require("strip-ansi"));
var _stripAnsi = require('strip-ansi');
var _jestWatcher = require("jest-watcher");
var _stripAnsi2 = _interopRequireDefault(_stripAnsi);
var _jestWatcher = require('jest-watcher');
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

@@ -23,25 +19,35 @@

const printPatternMatches = exports.printPatternMatches = (count, entity, pipe, extraText = '') => {
const 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}`;
pipe.write(result + extraText);
};
const printStartTyping = exports.printStartTyping = (entity, pipe) => {
pipe.write(`\n\n ${_chalk2.default.italic.yellow(`Start typing to filter by a ${entity} regex pattern.`)}`);
exports.printPatternMatches = printPatternMatches;
const printStartTyping = (entity, pipe) => {
pipe.write(`\n\n ${_chalk.default.italic.yellow(`Start typing to filter by a ${entity} regex pattern.`)}`);
};
const printMore = exports.printMore = (entity, pipe, more) => {
pipe.write(`\n ${_chalk2.default.dim(`...and ${more} more ${pluralize(more, entity)}`)}`);
exports.printStartTyping = printStartTyping;
const printMore = (entity, pipe, more) => {
pipe.write(`\n ${_chalk.default.dim(`...and ${more} more ${pluralize(more, entity)}`)}`);
};
const printTypeaheadItem = exports.printTypeaheadItem = (item, pipe) => pipe.write(`\n ${_chalk2.default.dim('\u203A')} ${item}`);
exports.printMore = printMore;
const formatTypeaheadSelection = exports.formatTypeaheadSelection = (item, index, activeIndex, prompt) => {
const printTypeaheadItem = (item, pipe) => pipe.write(`\n ${_chalk.default.dim('\u203A')} ${item}`);
exports.printTypeaheadItem = printTypeaheadItem;
const formatTypeaheadSelection = (item, index, activeIndex, prompt) => {
if (index === activeIndex) {
prompt.setPromptSelection((0, _stripAnsi2.default)(item));
return _chalk2.default.black.bgYellow((0, _stripAnsi2.default)(item));
prompt.setPromptSelection((0, _stripAnsi.default)(item));
return _chalk.default.black.bgYellow((0, _stripAnsi.default)(item));
}
return item;
};
};
exports.formatTypeaheadSelection = formatTypeaheadSelection;

@@ -6,8 +6,10 @@ "use strict";

});
exports.default = void 0;
const scroll = (size, { offset, max }) => {
const scroll = (size, {
offset,
max
}) => {
let start = 0;
let index = Math.min(offset, size);
const halfScreen = max / 2;

@@ -21,2 +23,3 @@

}
index = Math.min(index - start, size);

@@ -32,2 +35,3 @@ }

exports.default = scroll;
var _default = scroll;
exports.default = _default;

@@ -1,2 +0,2 @@

'use strict';
"use strict";

@@ -6,66 +6,66 @@ Object.defineProperty(exports, "__esModule", {

});
exports.formatTestNameByPattern = exports.highlight = exports.getTerminalWidth = exports.trimAndFormatPath = undefined;
exports.formatTestNameByPattern = exports.highlight = exports.getTerminalWidth = exports.trimAndFormatPath = void 0;
var _path = require('path');
var _path = _interopRequireDefault(require("path"));
var _path2 = _interopRequireDefault(_path);
var _chalk = _interopRequireDefault(require("chalk"));
var _chalk = require('chalk');
var _slash = _interopRequireDefault(require("slash"));
var _chalk2 = _interopRequireDefault(_chalk);
var _stripAnsi = _interopRequireDefault(require("strip-ansi"));
var _slash = require('slash');
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
var _slash2 = _interopRequireDefault(_slash);
/* eslint-disable no-param-reassign */
const relativePath = (config, testPath) => {
testPath = _path.default.relative(config.cwd || config.rootDir, testPath);
var _stripAnsi = require('strip-ansi');
const dirname = _path.default.dirname(testPath);
var _stripAnsi2 = _interopRequireDefault(_stripAnsi);
const basename = _path.default.basename(testPath);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
/* eslint-disable no-param-reassign */
const relativePath = (config, testPath) => {
testPath = _path2.default.relative(config.cwd || config.rootDir, testPath);
const dirname = _path2.default.dirname(testPath);
const basename = _path2.default.basename(testPath);
return { basename, dirname };
return {
basename,
dirname
};
};
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));
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));
const trimAndFormatPath = exports.trimAndFormatPath = (pad, config, testPath, columns) => {
const trimAndFormatPath = (pad, config, testPath, columns) => {
const maxLength = columns - pad;
const relative = relativePath(config, testPath);
const basename = relative.basename;
let dirname = relative.dirname;
let dirname = relative.dirname; // length is ok
// length is ok
if ((dirname + _path.default.sep + basename).length <= maxLength) {
return (0, _slash.default)(_chalk.default.dim(dirname + _path.default.sep) + _chalk.default.bold(basename));
} // we can fit trimmed dirname and full basename
if ((dirname + _path2.default.sep + basename).length <= maxLength) {
return (0, _slash2.default)(_chalk2.default.dim(dirname + _path2.default.sep) + _chalk2.default.bold(basename));
}
// we can fit trimmed dirname and full basename
const basenameLength = basename.length;
if (basenameLength + 4 < maxLength) {
const dirnameLength = maxLength - 4 - basenameLength;
dirname = `...${dirname.slice(dirname.length - dirnameLength, dirname.length)}`;
return (0, _slash2.default)(_chalk2.default.dim(dirname + _path2.default.sep) + _chalk2.default.bold(basename));
return (0, _slash.default)(_chalk.default.dim(dirname + _path.default.sep) + _chalk.default.bold(basename));
}
if (basenameLength + 4 === maxLength) {
return (0, _slash2.default)(_chalk2.default.dim(`...${_path2.default.sep}`) + _chalk2.default.bold(basename));
}
return (0, _slash.default)(_chalk.default.dim(`...${_path.default.sep}`) + _chalk.default.bold(basename));
} // can't fit dirname, but can fit trimmed basename
// can't fit dirname, but can fit trimmed basename
return (0, _slash2.default)(_chalk2.default.bold(`...${basename.slice(basename.length - maxLength - 4, basename.length)}`));
return (0, _slash.default)(_chalk.default.bold(`...${basename.slice(basename.length - maxLength - 4, basename.length)}`));
};
const getTerminalWidth = exports.getTerminalWidth = (pipe = process.stdout) => pipe.columns;
exports.trimAndFormatPath = trimAndFormatPath;
const highlight = exports.highlight = (rawPath, filePath, pattern, rootDir) => {
const getTerminalWidth = (pipe = process.stdout) => pipe.columns;
exports.getTerminalWidth = getTerminalWidth;
const highlight = (rawPath, filePath, pattern, rootDir) => {
const trim = '...';
const relativePathHead = './';
let regexp;

@@ -76,11 +76,11 @@

} catch (e) {
return _chalk2.default.dim(filePath);
return _chalk.default.dim(filePath);
}
rawPath = (0, _stripAnsi2.default)(rawPath);
filePath = (0, _stripAnsi2.default)(filePath);
rawPath = (0, _stripAnsi.default)(rawPath);
filePath = (0, _stripAnsi.default)(filePath);
const match = rawPath.match(regexp);
if (!match) {
return _chalk2.default.dim(filePath);
return _chalk.default.dim(filePath);
}

@@ -98,3 +98,3 @@

} else {
offset = rootDir.length + _path2.default.sep.length;
offset = rootDir.length + _path.default.sep.length;
trimLength = 0;

@@ -108,8 +108,8 @@ }

exports.highlight = highlight;
const DOTS = '...';
const ENTER = '⏎';
const formatTestNameByPattern = exports.formatTestNameByPattern = (testName, pattern, width) => {
const formatTestNameByPattern = (testName, pattern, width) => {
const inlineTestName = testName.replace(/(\r\n|\n|\r)/gm, ENTER);
let regexp;

@@ -120,3 +120,3 @@

} catch (e) {
return _chalk2.default.dim(inlineTestName);
return _chalk.default.dim(inlineTestName);
}

@@ -127,6 +127,6 @@

if (!match) {
return _chalk2.default.dim(inlineTestName);
}
return _chalk.default.dim(inlineTestName);
} // $FlowFixMe
// $FlowFixMe
const startPatternIndex = Math.max(match.index, 0);

@@ -145,6 +145,9 @@ const endPatternIndex = startPatternIndex + match[0].length;

}
return colorize(slicedTestName + DOTS, Math.min(startPatternIndex, slicedTestName.length), endPatternIndex);
}
return `${_chalk2.default.dim(slicedTestName)}${_chalk2.default.reset(DOTS)}`;
};
return `${_chalk.default.dim(slicedTestName)}${_chalk.default.reset(DOTS)}`;
};
exports.formatTestNameByPattern = formatTestNameByPattern;

@@ -43,3 +43,3 @@ 'use strict';

const width = (0, _utils.getTerminalWidth)(pipe);
const width = (0, _utils.getTerminalWidth)();

@@ -46,0 +46,0 @@ var _scroll = (0, _scroll3.default)(total, options);

@@ -15,4 +15,3 @@ 'use strict';

stdin,
stdout,
config = {}
stdout
}) {

@@ -23,6 +22,2 @@ this._stdin = stdin;

this._testResults = [];
this._usageInfo = {
key: config.key || 't',
prompt: config.prompt || 'filter by a test name regex pattern'
};
}

@@ -51,4 +46,8 @@

// eslint-disable-next-line class-methods-use-this
getUsageInfo() {
return this._usageInfo;
return {
key: 't',
prompt: 'filter by a test name regex pattern'
};
}

@@ -55,0 +54,0 @@ }

@@ -1,13 +0,10 @@

'use strict';
"use strict";
var _jestWatcher = require('jest-watcher');
var _jestWatcher = require("jest-watcher");
var _prompt = require('./prompt');
var _prompt = _interopRequireDefault(require("./prompt"));
var _prompt2 = _interopRequireDefault(_prompt);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
class TestNamePlugin {
constructor({

@@ -29,3 +26,5 @@ stdin,

apply(jestHooks) {
jestHooks.onTestRunComplete(({ testResults }) => {
jestHooks.onTestRunComplete(({
testResults
}) => {
this._testResults = testResults;

@@ -40,7 +39,10 @@ });

run(globalConfig, updateConfigAndRun) {
const p = new _prompt2.default(this._stdout, this._prompt);
const p = new _prompt.default(this._stdout, this._prompt);
p.updateCachedTestResults(this._testResults);
return new Promise((res, rej) => {
p.run(value => {
updateConfigAndRun({ mode: 'watch', testNamePattern: value });
updateConfigAndRun({
mode: 'watch',
testNamePattern: value
});
res();

@@ -54,4 +56,5 @@ }, rej);

}
}
module.exports = TestNamePlugin;

@@ -1,21 +0,18 @@

'use strict';
"use strict";
var _chalk = require('chalk');
var _chalk = _interopRequireDefault(require("chalk"));
var _chalk2 = _interopRequireDefault(_chalk);
var _ansiEscapes = _interopRequireDefault(require("ansi-escapes"));
var _jestWatcher = require('jest-watcher');
var _jestWatcher = require("jest-watcher");
var _scroll2 = require('../lib/scroll');
var _scroll2 = _interopRequireDefault(require("../lib/scroll"));
var _scroll3 = _interopRequireDefault(_scroll2);
var _utils = require("../lib/utils");
var _utils = require('../lib/utils');
var _pattern_mode_helpers = require("../lib/pattern_mode_helpers");
var _pattern_mode_helpers = require('../lib/pattern_mode_helpers');
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
class TestNamePatternPrompt extends _jestWatcher.PatternPrompt {
constructor(pipe, prompt) {

@@ -29,2 +26,3 @@ super(pipe, prompt);

super._onChange(pattern, options);
this._printTypeahead(pattern, options);

@@ -35,22 +33,19 @@ }

const matchedTests = this._getMatchedTests(pattern);
const total = matchedTests.length;
const pipe = this._pipe;
const prompt = this._prompt;
(0, _jestWatcher.printPatternCaret)(pattern, pipe);
pipe.write(_ansiEscapes.default.cursorLeft);
if (pattern) {
(0, _pattern_mode_helpers.printPatternMatches)(total, 'test', pipe, ` from ${_chalk2.default.yellow('cached')} test suites`);
(0, _pattern_mode_helpers.printPatternMatches)(total, 'test', pipe, ` from ${_chalk.default.yellow('cached')} test suites`);
const width = (0, _utils.getTerminalWidth)(pipe);
var _scroll = (0, _scroll3.default)(total, options);
const start = _scroll.start,
const _scroll = (0, _scroll2.default)(total, options),
start = _scroll.start,
end = _scroll.end,
index = _scroll.index;
prompt.setPromptLength(total);
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));

@@ -77,4 +72,10 @@

return this._cachedTestResults.reduce((matchedTests, { testResults }) => {
return matchedTests.concat(testResults.filter(({ title }) => regex.test(title)).map(({ title }) => title));
return this._cachedTestResults.reduce((matchedTests, {
testResults
}) => {
return matchedTests.concat(testResults.filter(({
title
}) => regex.test(title)).map(({
title
}) => title));
}, []);

@@ -86,4 +87,5 @@ }

}
}
module.exports = TestNamePatternPrompt;

@@ -1,2 +0,2 @@

'use strict';
"use strict";

@@ -6,9 +6,8 @@ Object.defineProperty(exports, "__esModule", {

});
exports.default = void 0;
var _jestWatcher = require('jest-watcher');
var _jestWatcher = require("jest-watcher");
var _stripAnsi = require('strip-ansi');
var _stripAnsi = _interopRequireDefault(require("strip-ansi"));
var _stripAnsi2 = _interopRequireDefault(_stripAnsi);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

@@ -18,8 +17,8 @@

test: val => typeof val === 'string',
print: val => (0, _stripAnsi2.default)(val)
print: val => (0, _stripAnsi.default)(val)
});
jest.mock('ansi-escapes', () => ({
clearScreen: '[MOCK - clearScreen]',
cursorDown: (count = 1) => `[MOCK - cursorDown(${count})]`,
cursorLeft: '[MOCK - cursorLeft]',
cursorHide: '[MOCK - cursorHide]',

@@ -33,5 +32,11 @@ cursorRestorePosition: '[MOCK - cursorRestorePosition]',

const pluginTester = (Plugin, config = {}) => {
const stdout = { columns: 80, write: jest.fn() };
const stdout = {
columns: 80,
write: jest.fn()
};
const jestHooks = new _jestWatcher.JestHook();
const plugin = new Plugin({ stdout, config });
const plugin = new Plugin({
stdout,
config
});
plugin.apply(jestHooks.getSubscriber());

@@ -50,2 +55,3 @@

exports.default = pluginTester;
var _default = pluginTester;
exports.default = _default;
{
"name": "jest-watch-typeahead",
"version": "0.2.0",
"version": "0.2.1",
"main": "build/index.js",

@@ -27,23 +27,27 @@ "author": "Rogelio Guzman <rogelioguzmanh@gmail.com>",

"dependencies": {
"ansi-escapes": "^3.0.0",
"chalk": "^2.4.1",
"jest-watcher": "^23.1.0",
"slash": "^1.0.0",
"slash": "^2.0.0",
"string-length": "^2.0.0",
"strip-ansi": "^4.0.0"
"strip-ansi": "^5.0.0"
},
"devDependencies": {
"babel-cli": "6.26.0",
"babel-eslint": "^8.2.2",
"babel-preset-env": "1.6.1",
"babel-preset-flow": "^6.23.0",
"eslint": "4.18.1",
"eslint-config-airbnb-base": "12.1.0",
"eslint-config-prettier": "2.9.0",
"eslint-plugin-flowtype": "^2.46.1",
"eslint-plugin-import": "2.9.0",
"eslint-plugin-jest": "21.12.2",
"eslint-plugin-prettier": "2.6.0",
"flow-bin": "^0.66.0",
"jest": "23.2.0",
"prettier": "1.13.7"
"@babel/cli": "^7.0.0",
"@babel/core": "^7.0.0",
"@babel/preset-env": "^7.0.0",
"@babel/preset-flow": "^7.0.0",
"babel-core": "^7.0.0-bridge.0",
"babel-eslint": "^10.0.1",
"babel-jest": "^23.4.2",
"eslint": "^5.12.1",
"eslint-config-airbnb-base": "^13.1.0",
"eslint-config-prettier": "^3.6.0",
"eslint-plugin-flowtype": "^3.2.1",
"eslint-plugin-import": "^2.9.0",
"eslint-plugin-jest": "^22.1.3",
"eslint-plugin-prettier": "^3.0.1",
"flow-bin": "^0.91.0",
"jest": "^23.2.0",
"prettier": "^1.13.7"
},

@@ -50,0 +54,0 @@ "jest": {

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc