From 5a3f9abfdc8923c2d461bf4a3cf5f7616cee33a7 Mon Sep 17 00:00:00 2001 From: Tom Mrazauskas Date: Mon, 21 Mar 2022 17:57:26 +0200 Subject: [PATCH 1/2] refactor: clean up PatternPrompt and derived --- .../jest-core/src/TestNamePatternPrompt.ts | 16 +++----------- .../jest-core/src/TestPathPatternPrompt.ts | 21 +++---------------- packages/jest-watcher/src/PatternPrompt.ts | 15 ++++++------- 3 files changed, 12 insertions(+), 40 deletions(-) diff --git a/packages/jest-core/src/TestNamePatternPrompt.ts b/packages/jest-core/src/TestNamePatternPrompt.ts index f69312c05c0a..426a8bc45956 100644 --- a/packages/jest-core/src/TestNamePatternPrompt.ts +++ b/packages/jest-core/src/TestNamePatternPrompt.ts @@ -5,7 +5,6 @@ * LICENSE file in the root directory of this source tree. */ -import type {TestResult} from '@jest/test-result'; import { PatternPrompt, Prompt, @@ -14,28 +13,19 @@ import { printRestoredPatternCaret, } from 'jest-watcher'; -// TODO: Make underscored props `private` export default class TestNamePatternPrompt extends PatternPrompt { - _cachedTestResults: Array; - 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 = []): void { - this._cachedTestResults = testResults; - } } diff --git a/packages/jest-core/src/TestPathPatternPrompt.ts b/packages/jest-core/src/TestPathPatternPrompt.ts index cea3f46514c8..6c9d948da346 100644 --- a/packages/jest-core/src/TestPathPatternPrompt.ts +++ b/packages/jest-core/src/TestPathPatternPrompt.ts @@ -5,7 +5,6 @@ * LICENSE file in the root directory of this source tree. */ -import type {Context} from 'jest-runtime'; import { PatternPrompt, Prompt, @@ -13,34 +12,20 @@ import { 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; - } } diff --git a/packages/jest-watcher/src/PatternPrompt.ts b/packages/jest-watcher/src/PatternPrompt.ts index a0267fcc98cf..aa201dffa7e2 100644 --- a/packages/jest-watcher/src/PatternPrompt.ts +++ b/packages/jest-watcher/src/PatternPrompt.ts @@ -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; } From e9e528291e107637cdee830ffd7099df79c4d37e Mon Sep 17 00:00:00 2001 From: Tom Mrazauskas Date: Mon, 21 Mar 2022 18:26:47 +0200 Subject: [PATCH 2/2] add changelog entry --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index f13f52c65058..273ced1968e9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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))