Jest plugin for filtering by filename or test name
—
Pending
Does it follow best practices?
Impact
Pending
No eval scenarios have been run
Pending
The risk profile of this skill
The test name plugin provides interactive test name-based filtering with typeahead functionality. Users can type partial test names to filter which individual tests run during Jest watch mode.
Main plugin class implementing Jest's WatchPlugin interface for test name-based filtering.
/**
* Jest watch plugin for filtering individual tests by test name patterns
*/
export default class TestNamePlugin implements WatchPlugin {
constructor(options: {
stdin: NodeJS.ReadStream;
stdout: NodeJS.WriteStream;
config?: PluginConfig;
});
/** Hook into Jest lifecycle events to receive test results */
apply(jestHooks: JestHookSubscriber): void;
/** Handle keypress events from user input */
onKey(key: string): void;
/** Execute plugin functionality and update Jest configuration */
run(
globalConfig: Config.GlobalConfig,
updateConfigAndRun: UpdateConfigCallback
): Promise<void>;
/** Return plugin usage information for Jest's help display */
getUsageInfo(): UsageData;
}Usage Example:
import TestNamePlugin from "jest-watch-typeahead/testname";
// Plugin is typically instantiated by Jest
const plugin = new TestNamePlugin({
stdin: process.stdin,
stdout: process.stdout,
config: {
key: 'n',
prompt: 'filter by test name'
}
});Interactive prompt class for test name pattern input and typeahead display.
/**
* Pattern prompt for test name-based filtering with typeahead functionality
*/
export default class TestNamePatternPrompt extends PatternPrompt {
constructor(pipe: NodeJS.WritableStream, prompt: Prompt);
/** Update cached test results from previous test runs */
updateCachedTestResults(results: Array<TestResult>): void;
/** Handle pattern changes and update display */
protected _onChange(pattern: string, options: ScrollOptions): void;
/** Display typeahead results for current pattern */
protected _printTypeahead(pattern: string, options: ScrollOptions): void;
/** Get test names matching the current pattern */
protected _getMatchedTests(pattern: string): Array<any>;
}The test name plugin uses regex-based pattern matching to filter individual tests:
Pattern Examples:
# Match tests containing "should"
should
# Match specific test descriptions
user.*authentication
# Match multiple test patterns
(login|signup).*success
# Match tests with specific keywords
error.*handling// jest.config.js
module.exports = {
watchPlugins: [
'jest-watch-typeahead/testname'
]
};The plugin integrates with Jest's hook system:
interface JestHookSubscriber {
/** Called when test runs complete */
onTestRunComplete(callback: (data: { testResults: Array<TestResult> }) => void): void;
}The test name plugin subscribes to onTestRunComplete to cache test results and extract available test names for filtering.
/**
* Format test names with pattern highlighting for terminal display
* @param testName - Original test name string
* @param pattern - Search pattern to highlight
* @param width - Terminal display width
* @returns Formatted test name with highlighting and truncation
*/
function formatTestNameByPattern(
testName: string,
pattern: string,
width: number
): string;Test Name Processing:
interface TestResult {
/** Test file path */
testFilePath: string;
/** Individual test results */
testResults: Array<{
title: string;
fullName: string;
status: 'passed' | 'failed' | 'pending' | 'skipped';
duration?: number;
}>;
}The plugin extracts test names from TestResult objects to build a searchable index of available tests.
/**
* Remove leading trimming dots from display strings
* @param value - Input string that may contain trimming dots
* @returns String with leading trimming dots removed
*/
function removeTrimmingDots(value: string): string;/**
* Print pattern match summary to terminal
* @param count - Number of matches found
* @param entity - Entity type being searched ("tests")
* @param pipe - Output stream for writing
* @param extraText - Additional text to append
*/
function printPatternMatches(
count: number,
entity: string,
pipe: NodeJS.WritableStream,
extraText?: string
): void;
/**
* Print start typing instruction message
* @param entity - Entity type being searched ("tests")
* @param pipe - Output stream for writing
*/
function printStartTyping(
entity: string,
pipe: NodeJS.WritableStream
): void;
/**
* Print indicator for additional hidden matches
* @param entity - Entity type being searched ("tests")
* @param pipe - Output stream for writing
* @param more - Number of additional matches
*/
function printMore(
entity: string,
pipe: NodeJS.WritableStream,
more: number
): void;
/**
* Print individual typeahead item to terminal
* @param item - Item text to display
* @param pipe - Output stream for writing
*/
function printTypeaheadItem(
item: string,
pipe: NodeJS.WritableStream
): void;
/**
* Format typeahead selection items with highlighting for active selection
* @param item - Item text to format
* @param index - Current item index
* @param activeIndex - Index of currently active selection
* @param prompt - Jest prompt instance for selection tracking
* @returns Formatted item string with selection highlighting
*/
function formatTypeaheadSelection(
item: string,
index: number,
activeIndex: number,
prompt: Prompt
): string;/**
* Calculate scroll positioning for long lists of test names
* @param size - Total number of items
* @param options - Scroll configuration with offset and max display items
* @returns Scroll position information with start, end, and current index
*/
function scroll(
size: number,
options: ScrollOptions
): {
index: number;
end: number;
start: number;
};The test name plugin supports keyboard navigation through long lists of matching tests:
interface UpdateConfigCallback {
(config: {
mode: 'watch';
testNamePattern: string;
}): void;
}
interface ScrollOptions {
/** Current scroll offset */
offset: number;
/** Maximum displayable items */
max: number;
}