Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
_printTypeahead(pattern: string, options: ScrollOptions) {
const matchedTests = this._getMatchedTests(pattern);
const total = matchedTests.length;
const pipe = this._pipe;
const prompt = this._prompt;
printPatternCaret(pattern, pipe);
pipe.write(ansiEscapes.cursorLeft);
if (pattern) {
printPatternMatches(
total,
'test',
pipe,
` from ${chalk.yellow('cached')} test suites`,
);
const width = getTerminalWidth(pipe);
const { start, end, index } = scroll(total, options);
prompt.setPromptLength(total);
prompt.setPromptLength(total);
matchedTests
.slice(start, end)
.map(name => formatTestNameByPattern(name, pattern, width - 4))
.map((item, i) => formatTypeaheadSelection(item, i, index, prompt))
.forEach(item => printTypeaheadItem(item, pipe));
if (total > end) {
printMore('test', pipe, total - end);
}
} else {
printStartTyping('test name', pipe);
}
printRestoredPatternCaret(pattern, this._currentUsageRows, pipe);
}
const pluginTester = (Plugin, config = {}) => {
const stdout = {
columns: 80,
write: jest.fn()
};
const jestHooks = new _jestWatcher.JestHook();
const plugin = new Plugin({
stdout,
config
});
plugin.apply(jestHooks.getSubscriber());
const type = (...keys) => keys.forEach(key => plugin.onKey(key));
return {
stdout,
hookEmitter: jestHooks.getEmitter(),
updateConfigAndRun: jest.fn(),
plugin,
type
};
};
const pluginTester = (Plugin, options = {}) => {
const stdout = {
columns: (options.stdout || {}).columns || 80,
write: jest.fn(),
};
const jestHooks = new JestHook();
const plugin = new Plugin({ stdout, config: options.config });
plugin.apply(jestHooks.getSubscriber());
const type = (...keys) => keys.forEach(key => plugin.onKey(key));
return {
stdout,
hookEmitter: jestHooks.getEmitter(),
updateConfigAndRun: jest.fn(),
plugin,
type,
};
};
constructor({
stdin,
stdout,
config = {},
}: {
stdin: stream$Readable | tty$ReadStream,
stdout: stream$Writable | tty$WriteStream,
config: PluginConfig,
}) {
this._stdin = stdin;
this._stdout = stdout;
this._prompt = new Prompt();
this._testResults = [];
this._usageInfo = {
key: config.key || 't',
prompt: config.prompt || 'filter by a test name regex pattern',
};
}
_printTypeahead(pattern: string, options: ScrollOptions) {
const matchedTests = this._getMatchedTests(pattern);
const total = matchedTests.length;
const pipe = this._pipe;
const prompt = this._prompt;
printPatternCaret(pattern, pipe);
pipe.write(ansiEscapes.cursorLeft);
if (pattern) {
printPatternMatches(total, 'file', pipe);
const prefix = ` ${chalk.dim('\u203A')} `;
const padding = stringLength(prefix) + 2;
const width = getTerminalWidth(pipe);
const { start, end, index } = scroll(total, options);
prompt.setPromptLength(total);
matchedTests
.slice(start, end)
.map(({ path, context }) => {
path,
width,
);
return highlight(path, filePath, pattern, context.config.rootDir);
})
.map((item, i) => formatTypeaheadSelection(item, i, index, prompt))
.forEach(item => printTypeaheadItem(item, pipe));
if (total > end) {
printMore('file', pipe, total - end);
}
} else {
printStartTyping('filename', pipe);
}
printRestoredPatternCaret(pattern, this._currentUsageRows, pipe);
}
constructor({
stdin,
stdout,
config = {},
}: {
stdin: stream$Readable | tty$ReadStream,
stdout: stream$Writable | tty$WriteStream,
config: PluginConfig,
}) {
this._stdin = stdin;
this._stdout = stdout;
this._prompt = new Prompt();
this._projects = [];
this._usageInfo = {
key: config.key || 'p',
prompt: config.prompt || 'filter by a filename regex pattern',
};
}
stdin.on('data', (key: string) => {
if (key === KEYS.ENTER) {
resolve();
} else if (
[KEYS.ESCAPE, KEYS.CONTROL_C, KEYS.CONTROL_D].indexOf(key) !== -1
) {
reject();
}
});
} else {
stdin.on('data', (key: string) => {
if (key === KEYS.ENTER) {
resolve();
} else if (
[KEYS.ESCAPE, KEYS.CONTROL_C, KEYS.CONTROL_D].indexOf(key) !== -1
) {
reject();
}
});
} else {