Skip to content

Commit

Permalink
refactor(@jest/core, jest-watcher)!: rework and clean up `PatternProm…
Browse files Browse the repository at this point in the history
…pt` and its derived classes (#12591)
  • Loading branch information
mrazauskas authored Mar 22, 2022
1 parent bf2e4a0 commit abca0fe
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 40 deletions.
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

0 comments on commit abca0fe

Please sign in to comment.