Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(@jest/core, jest-watcher)!: rework and clean up PatternPrompt and its derived classes #12591

Merged
merged 2 commits into from
Mar 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
- `[jest-runtime]` Calling `jest.resetModules` function will clear FS and transform cache ([#12531](https://github.com/facebook/jest/pull/12531))
- `[@jest/schemas]` New module for JSON schemas for Jest's config ([#12384](https://github.com/facebook/jest/pull/12384))
- `[jest-test-result]` Add duration property to JSON test output ([#12518](https://github.com/facebook/jest/pull/12518))
- `[jest-watcher]` [**BREAKING**] Make `PatternPrompt` class to take `entityName` as third constructor parameter instead of `this._entityName` ([#12591](https://github.com/facebook/jest/pull/12591))
- `[jest-worker]` [**BREAKING**] Allow only absolute `workerPath` ([#12343](https://github.com/facebook/jest/pull/12343))
- `[pretty-format]` New `maxWidth` parameter ([#12402](https://github.com/facebook/jest/pull/12402))

Expand Down
16 changes: 3 additions & 13 deletions packages/jest-core/src/TestNamePatternPrompt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
* LICENSE file in the root directory of this source tree.
*/

import type {TestResult} from '@jest/test-result';
import {
PatternPrompt,
Prompt,
Expand All @@ -14,28 +13,19 @@ import {
printRestoredPatternCaret,
} from 'jest-watcher';

// TODO: Make underscored props `private`
export default class TestNamePatternPrompt extends PatternPrompt {
_cachedTestResults: Array<TestResult>;

constructor(pipe: NodeJS.WritableStream, prompt: Prompt) {
super(pipe, prompt);
this._entityName = 'tests';
this._cachedTestResults = [];
super(pipe, prompt, 'tests');
}

_onChange(pattern: string, options: ScrollOptions): void {
protected _onChange(pattern: string, options: ScrollOptions): void {
super._onChange(pattern, options);
this._printPrompt(pattern);
}

_printPrompt(pattern: string): void {
private _printPrompt(pattern: string): void {
const pipe = this._pipe;
printPatternCaret(pattern, pipe);
printRestoredPatternCaret(pattern, this._currentUsageRows, pipe);
}

updateCachedTestResults(testResults: Array<TestResult> = []): void {
this._cachedTestResults = testResults;
}
}
21 changes: 3 additions & 18 deletions packages/jest-core/src/TestPathPatternPrompt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,42 +5,27 @@
* LICENSE file in the root directory of this source tree.
*/

import type {Context} from 'jest-runtime';
import {
PatternPrompt,
Prompt,
ScrollOptions,
printPatternCaret,
printRestoredPatternCaret,
} from 'jest-watcher';
import type SearchSource from './SearchSource';

type SearchSources = Array<{
context: Context;
searchSource: SearchSource;
}>;

// TODO: Make underscored props `private`
export default class TestPathPatternPrompt extends PatternPrompt {
_searchSources?: SearchSources;

constructor(pipe: NodeJS.WritableStream, prompt: Prompt) {
super(pipe, prompt);
this._entityName = 'filenames';
super(pipe, prompt, 'filenames');
}

_onChange(pattern: string, options: ScrollOptions): void {
protected _onChange(pattern: string, options: ScrollOptions): void {
super._onChange(pattern, options);
this._printPrompt(pattern);
}

_printPrompt(pattern: string): void {
private _printPrompt(pattern: string): void {
const pipe = this._pipe;
printPatternCaret(pattern, pipe);
printRestoredPatternCaret(pattern, this._currentUsageRows, pipe);
}

updateSearchSources(searchSources: SearchSources): void {
this._searchSources = searchSources;
}
}
15 changes: 6 additions & 9 deletions packages/jest-watcher/src/PatternPrompt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,14 @@ const usage = (entity: string) =>

const usageRows = usage('').split('\n').length;

export default class PatternPrompt {
protected _pipe: NodeJS.WritableStream;
protected _prompt: Prompt;
protected _entityName: string;
export default abstract class PatternPrompt {
protected _currentUsageRows: number;

constructor(pipe: NodeJS.WritableStream, prompt: Prompt) {
// TODO: Should come in the constructor
this._entityName = '';
this._pipe = pipe;
this._prompt = prompt;
constructor(
protected _pipe: NodeJS.WritableStream,
protected _prompt: Prompt,
protected _entityName = '',
) {
this._currentUsageRows = usageRows;
}

Expand Down