From 842f38980d6d4f05a5c86afacdbde11f8b28bd0b Mon Sep 17 00:00:00 2001 From: Simen Bekkhus Date: Sun, 10 Feb 2019 10:47:18 +0100 Subject: [PATCH] chore: migrate jest-watcher to TypeScript (#7843) --- CHANGELOG.md | 1 + docs/WatchPlugins.md | 1 + .../jest-cli/src/lib/update_global_config.js | 2 - packages/jest-cli/src/plugins/quit.js | 1 - packages/jest-types/src/Config.ts | 10 ++- packages/jest-watcher/package.json | 2 + packages/jest-watcher/src/BaseWatchPlugin.js | 43 ---------- packages/jest-watcher/src/BaseWatchPlugin.ts | 38 +++++++++ .../src/{JestHooks.js => JestHooks.ts} | 23 +++-- .../{PatternPrompt.js => PatternPrompt.ts} | 16 ++-- .../src/{constants.js => constants.ts} | 2 - .../jest-watcher/src/{index.js => index.ts} | 2 - .../src/lib/{Prompt.js => Prompt.ts} | 32 ++++--- ...p => formatTestNameByPattern.test.ts.snap} | 0 ...est.js => formatTestNameByPattern.test.ts} | 4 - .../{prompt.test.js => prompt.test.ts} | 2 - .../{scroll.test.js => scroll.test.ts} | 0 .../src/lib/{colorize.js => colorize.ts} | 2 - ...yPattern.js => formatTestNameByPattern.ts} | 4 +- ...rnModeHelpers.js => patternModeHelpers.ts} | 8 +- .../src/lib/{scroll.js => scroll.ts} | 6 +- packages/jest-watcher/src/types.js | 26 ------ packages/jest-watcher/src/types.ts | 83 +++++++++++++++++++ packages/jest-watcher/tsconfig.json | 8 ++ .../version-23.x/WatchPlugins.md | 1 + .../version-24.0/WatchPlugins.md | 1 + 26 files changed, 185 insertions(+), 133 deletions(-) delete mode 100644 packages/jest-watcher/src/BaseWatchPlugin.js create mode 100644 packages/jest-watcher/src/BaseWatchPlugin.ts rename packages/jest-watcher/src/{JestHooks.js => JestHooks.ts} (80%) rename packages/jest-watcher/src/{PatternPrompt.js => PatternPrompt.ts} (82%) rename packages/jest-watcher/src/{constants.js => constants.ts} (97%) rename packages/jest-watcher/src/{index.js => index.ts} (97%) rename packages/jest-watcher/src/lib/{Prompt.js => Prompt.ts} (79%) rename packages/jest-watcher/src/lib/__tests__/__snapshots__/{formatTestNameByPattern.test.js.snap => formatTestNameByPattern.test.ts.snap} (100%) rename packages/jest-watcher/src/lib/__tests__/{formatTestNameByPattern.test.js => formatTestNameByPattern.test.ts} (98%) rename packages/jest-watcher/src/lib/__tests__/{prompt.test.js => prompt.test.ts} (99%) rename packages/jest-watcher/src/lib/__tests__/{scroll.test.js => scroll.test.ts} (100%) rename packages/jest-watcher/src/lib/{colorize.js => colorize.ts} (97%) rename packages/jest-watcher/src/lib/{formatTestNameByPattern.js => formatTestNameByPattern.ts} (95%) rename packages/jest-watcher/src/lib/{patternModeHelpers.js => patternModeHelpers.ts} (88%) rename packages/jest-watcher/src/lib/{scroll.js => scroll.ts} (89%) delete mode 100644 packages/jest-watcher/src/types.js create mode 100644 packages/jest-watcher/src/types.ts create mode 100644 packages/jest-watcher/tsconfig.json diff --git a/CHANGELOG.md b/CHANGELOG.md index ea78999740ca..f0a5fbc41f6e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -22,6 +22,7 @@ - `[jest-message-util]`: Migrate to TypeScript ([#7834](https://github.com/facebook/jest/pull/7834)) - `[@jest/types]`: New package to handle shared types ([#7834](https://github.com/facebook/jest/pull/7834)) - `[jest-util]`: Migrate to TypeScript ([#7844](https://github.com/facebook/jest/pull/7844)) +- `[jest-watcher]`: Migrate to TypeScript ([#7843](https://github.com/facebook/jest/pull/7843)) ### Performance diff --git a/docs/WatchPlugins.md b/docs/WatchPlugins.md index 05818e95b555..6047382eefc0 100644 --- a/docs/WatchPlugins.md +++ b/docs/WatchPlugins.md @@ -155,6 +155,7 @@ class MyWatchPlugin { For stability and safety reasons, only part of the global configuration keys can be updated with `updateConfigAndRun`. The current white list is as follows: - [`bail`](configuration.html#bail-number-boolean) +- [`changedSince`](cli.html#changedsince) - [`collectCoverage`](configuration.html#collectcoverage-boolean) - [`collectCoverageFrom`](configuration.html#collectcoveragefrom-array) - [`collectCoverageOnlyFrom`](configuration.html#collectcoverageonlyfrom-array) diff --git a/packages/jest-cli/src/lib/update_global_config.js b/packages/jest-cli/src/lib/update_global_config.js index 5b0047f8a6b1..beee59cd77b5 100644 --- a/packages/jest-cli/src/lib/update_global_config.js +++ b/packages/jest-cli/src/lib/update_global_config.js @@ -23,11 +23,9 @@ export type Options = { coverageDirectory?: $PropertyType, coverageReporters?: $PropertyType, mode?: 'watch' | 'watchAll', - noSCM?: $PropertyType, notify?: $PropertyType, notifyMode?: $PropertyType, onlyFailures?: $PropertyType, - passWithNoTests?: $PropertyType, reporters?: $PropertyType, testNamePattern?: $PropertyType, testPathPattern?: $PropertyType, diff --git a/packages/jest-cli/src/plugins/quit.js b/packages/jest-cli/src/plugins/quit.js index 0c7d63d5930e..68a336cf203e 100644 --- a/packages/jest-cli/src/plugins/quit.js +++ b/packages/jest-cli/src/plugins/quit.js @@ -21,7 +21,6 @@ class QuitPlugin extends BaseWatchPlugin { async run() { if (typeof this._stdin.setRawMode === 'function') { - // $FlowFixMe this._stdin.setRawMode(false); } this._stdout.write('\n'); diff --git a/packages/jest-types/src/Config.ts b/packages/jest-types/src/Config.ts index bd74d87c6b8b..85a5db4df75f 100644 --- a/packages/jest-types/src/Config.ts +++ b/packages/jest-types/src/Config.ts @@ -213,6 +213,14 @@ export type InitialOptions = { export type SnapshotUpdateState = 'all' | 'new' | 'none'; +type NotifyMode = + | 'always' + | 'failure' + | 'success' + | 'change' + | 'success-change' + | 'failure-change'; + export type GlobalConfig = { bail: number; changedSince: string; @@ -260,7 +268,7 @@ export type GlobalConfig = { nonFlagArgs: Array; noSCM: boolean | null | undefined; notify: boolean; - notifyMode: string; + notifyMode: NotifyMode; outputFile: Path | null | undefined; onlyChanged: boolean; onlyFailures: boolean; diff --git a/packages/jest-watcher/package.json b/packages/jest-watcher/package.json index 351a6c7ec3da..95b9ceda6fc3 100644 --- a/packages/jest-watcher/package.json +++ b/packages/jest-watcher/package.json @@ -4,6 +4,8 @@ "version": "24.0.0", "main": "build/index.js", "dependencies": { + "@jest/types": "^24.1.0", + "@types/node": "*", "ansi-escapes": "^3.0.0", "chalk": "^2.0.1", "jest-util": "^24.0.0", diff --git a/packages/jest-watcher/src/BaseWatchPlugin.js b/packages/jest-watcher/src/BaseWatchPlugin.js deleted file mode 100644 index ea239925c459..000000000000 --- a/packages/jest-watcher/src/BaseWatchPlugin.js +++ /dev/null @@ -1,43 +0,0 @@ -/** - * Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - * - * @flow - */ -import type {GlobalConfig} from 'types/Config'; -import type {JestHookSubscriber} from 'types/JestHooks'; -import type {WatchPlugin, UsageData} from './types'; - -class BaseWatchPlugin implements WatchPlugin { - _stdin: stream$Readable | tty$ReadStream; - _stdout: stream$Writable | tty$WriteStream; - constructor({ - stdin, - stdout, - }: { - stdin: stream$Readable | tty$ReadStream, - stdout: stream$Writable | tty$WriteStream, - }) { - this._stdin = stdin; - this._stdout = stdout; - } - - apply(hooks: JestHookSubscriber) {} - - getUsageInfo(globalConfig: GlobalConfig): ?UsageData { - return null; - } - - onKey(value: string) {} - - run( - globalConfig: GlobalConfig, - updateConfigAndRun: Function, - ): Promise { - return Promise.resolve(); - } -} - -export default BaseWatchPlugin; diff --git a/packages/jest-watcher/src/BaseWatchPlugin.ts b/packages/jest-watcher/src/BaseWatchPlugin.ts new file mode 100644 index 000000000000..f9e6d31b0bdd --- /dev/null +++ b/packages/jest-watcher/src/BaseWatchPlugin.ts @@ -0,0 +1,38 @@ +/** + * Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ + +import {WatchPlugin} from './types'; + +class BaseWatchPlugin implements WatchPlugin { + _stdin: NodeJS.ReadableStream; + _stdout: NodeJS.WritableStream; + + constructor({ + stdin, + stdout, + }: { + stdin: NodeJS.ReadableStream; + stdout: NodeJS.WritableStream; + }) { + this._stdin = stdin; + this._stdout = stdout; + } + + apply() {} + + getUsageInfo() { + return null; + } + + onKey() {} + + run() { + return Promise.resolve(); + } +} + +export default BaseWatchPlugin; diff --git a/packages/jest-watcher/src/JestHooks.js b/packages/jest-watcher/src/JestHooks.ts similarity index 80% rename from packages/jest-watcher/src/JestHooks.js rename to packages/jest-watcher/src/JestHooks.ts index 22d5ccfb0e23..6525b8782038 100644 --- a/packages/jest-watcher/src/JestHooks.js +++ b/packages/jest-watcher/src/JestHooks.ts @@ -3,17 +3,15 @@ * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. - * - * @flow */ -import type { +import { JestHookSubscriber, JestHookEmitter, FileChange, ShouldRunTestSuite, TestRunComplete, -} from 'types/JestHooks'; +} from './types'; type AvailableHooks = | 'onFileChange' @@ -22,9 +20,9 @@ type AvailableHooks = class JestHooks { _listeners: { - onFileChange: Array, - onTestRunComplete: Array, - shouldRunTestSuite: Array, + onFileChange: Array; + onTestRunComplete: Array; + shouldRunTestSuite: Array; }; constructor() { @@ -61,14 +59,15 @@ class JestHooks { this._listeners.onTestRunComplete.forEach(listener => listener(results), ), - shouldRunTestSuite: async testSuiteInfo => - Promise.all( + shouldRunTestSuite: async testSuiteInfo => { + const result = await Promise.all( this._listeners.shouldRunTestSuite.map(listener => listener(testSuiteInfo), ), - ).then(result => - result.every(shouldRunTestSuite => shouldRunTestSuite), - ), + ); + + return result.every(Boolean); + }, }; } } diff --git a/packages/jest-watcher/src/PatternPrompt.js b/packages/jest-watcher/src/PatternPrompt.ts similarity index 82% rename from packages/jest-watcher/src/PatternPrompt.js rename to packages/jest-watcher/src/PatternPrompt.ts index 314edb87130e..61593b8615d7 100644 --- a/packages/jest-watcher/src/PatternPrompt.js +++ b/packages/jest-watcher/src/PatternPrompt.ts @@ -3,14 +3,8 @@ * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. - * - * @flow */ -'use strict'; - -import type {ScrollOptions} from 'types/Watch'; - import chalk from 'chalk'; import ansiEscapes from 'ansi-escapes'; import {specialChars} from 'jest-util'; @@ -28,18 +22,20 @@ const usage = (entity: string) => const usageRows = usage('').split('\n').length; export default class PatternPrompt { - _pipe: stream$Writable | tty$WriteStream; + _pipe: NodeJS.WritableStream; _prompt: Prompt; _entityName: string; _currentUsageRows: number; - constructor(pipe: stream$Writable | tty$WriteStream, prompt: Prompt) { + constructor(pipe: NodeJS.WritableStream, prompt: Prompt) { + // TODO: Should come in the constructor + this._entityName = ''; this._pipe = pipe; this._prompt = prompt; this._currentUsageRows = usageRows; } - run(onSuccess: Function, onCancel: Function, options?: {header: string}) { + run(onSuccess: () => void, onCancel: () => void, options?: {header: string}) { this._pipe.write(ansiEscapes.cursorHide); this._pipe.write(CLEAR); @@ -56,7 +52,7 @@ export default class PatternPrompt { this._prompt.enter(this._onChange.bind(this), onSuccess, onCancel); } - _onChange(pattern: string, options: ScrollOptions) { + protected _onChange() { this._pipe.write(ansiEscapes.eraseLine); this._pipe.write(ansiEscapes.cursorLeft); } diff --git a/packages/jest-watcher/src/constants.js b/packages/jest-watcher/src/constants.ts similarity index 97% rename from packages/jest-watcher/src/constants.js rename to packages/jest-watcher/src/constants.ts index 5e9b2e73296b..d1a29c337421 100644 --- a/packages/jest-watcher/src/constants.js +++ b/packages/jest-watcher/src/constants.ts @@ -3,8 +3,6 @@ * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. - * - * @flow */ const isWindows = process.platform === 'win32'; diff --git a/packages/jest-watcher/src/index.js b/packages/jest-watcher/src/index.ts similarity index 97% rename from packages/jest-watcher/src/index.js rename to packages/jest-watcher/src/index.ts index 5a50fc7e909f..766fba239f10 100644 --- a/packages/jest-watcher/src/index.js +++ b/packages/jest-watcher/src/index.ts @@ -3,8 +3,6 @@ * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. - * - * @flow */ export {default as BaseWatchPlugin} from './BaseWatchPlugin'; diff --git a/packages/jest-watcher/src/lib/Prompt.js b/packages/jest-watcher/src/lib/Prompt.ts similarity index 79% rename from packages/jest-watcher/src/lib/Prompt.js rename to packages/jest-watcher/src/lib/Prompt.ts index 295d4b8db557..8db199284d1e 100644 --- a/packages/jest-watcher/src/lib/Prompt.js +++ b/packages/jest-watcher/src/lib/Prompt.ts @@ -3,36 +3,44 @@ * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. - * - * @flow */ -import type {ScrollOptions} from 'types/Watch'; - +import {ScrollOptions} from '../types'; import {KEYS} from '../constants'; export default class Prompt { _entering: boolean; _value: string; - _onChange: Function; - _onSuccess: Function; - _onCancel: Function; + _onChange: () => void; + _onSuccess: (value?: string) => void; + _onCancel: (value?: string) => void; _offset: number; _promptLength: number; _selection: string | null; constructor() { - (this: any)._onResize = this._onResize.bind(this); + // Copied from `enter` to satisfy TS + this._entering = true; + this._value = ''; + this._selection = null; + this._offset = -1; + this._promptLength = 0; + + this._onChange = () => {}; + this._onSuccess = () => {}; + this._onCancel = () => {}; + + this._onResize = this._onResize.bind(this); } - _onResize() { - this._onChange(this._value); + private _onResize() { + this._onChange(); } enter( onChange: (pattern: string, options: ScrollOptions) => void, - onSuccess: Function, - onCancel: Function, + onSuccess: () => void, + onCancel: () => void, ) { this._entering = true; this._value = ''; diff --git a/packages/jest-watcher/src/lib/__tests__/__snapshots__/formatTestNameByPattern.test.js.snap b/packages/jest-watcher/src/lib/__tests__/__snapshots__/formatTestNameByPattern.test.ts.snap similarity index 100% rename from packages/jest-watcher/src/lib/__tests__/__snapshots__/formatTestNameByPattern.test.js.snap rename to packages/jest-watcher/src/lib/__tests__/__snapshots__/formatTestNameByPattern.test.ts.snap diff --git a/packages/jest-watcher/src/lib/__tests__/formatTestNameByPattern.test.js b/packages/jest-watcher/src/lib/__tests__/formatTestNameByPattern.test.ts similarity index 98% rename from packages/jest-watcher/src/lib/__tests__/formatTestNameByPattern.test.js rename to packages/jest-watcher/src/lib/__tests__/formatTestNameByPattern.test.ts index afa7611b43ef..9a491f8a601d 100644 --- a/packages/jest-watcher/src/lib/__tests__/formatTestNameByPattern.test.js +++ b/packages/jest-watcher/src/lib/__tests__/formatTestNameByPattern.test.ts @@ -3,12 +3,8 @@ * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. - * - * @flow */ -'use strict'; - import formatTestNameByPattern from '../formatTestNameByPattern'; describe('for multiline test name returns', () => { diff --git a/packages/jest-watcher/src/lib/__tests__/prompt.test.js b/packages/jest-watcher/src/lib/__tests__/prompt.test.ts similarity index 99% rename from packages/jest-watcher/src/lib/__tests__/prompt.test.js rename to packages/jest-watcher/src/lib/__tests__/prompt.test.ts index aa3e3ef0d039..1ade9d33331c 100644 --- a/packages/jest-watcher/src/lib/__tests__/prompt.test.js +++ b/packages/jest-watcher/src/lib/__tests__/prompt.test.ts @@ -6,8 +6,6 @@ * */ -'use strict'; - import Prompt from '../Prompt'; import {KEYS} from '../../constants'; diff --git a/packages/jest-watcher/src/lib/__tests__/scroll.test.js b/packages/jest-watcher/src/lib/__tests__/scroll.test.ts similarity index 100% rename from packages/jest-watcher/src/lib/__tests__/scroll.test.js rename to packages/jest-watcher/src/lib/__tests__/scroll.test.ts diff --git a/packages/jest-watcher/src/lib/colorize.js b/packages/jest-watcher/src/lib/colorize.ts similarity index 97% rename from packages/jest-watcher/src/lib/colorize.js rename to packages/jest-watcher/src/lib/colorize.ts index d474f97a86b2..8adf88ae2df1 100644 --- a/packages/jest-watcher/src/lib/colorize.js +++ b/packages/jest-watcher/src/lib/colorize.ts @@ -3,8 +3,6 @@ * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. - * - * @flow */ import chalk from 'chalk'; diff --git a/packages/jest-watcher/src/lib/formatTestNameByPattern.js b/packages/jest-watcher/src/lib/formatTestNameByPattern.ts similarity index 95% rename from packages/jest-watcher/src/lib/formatTestNameByPattern.js rename to packages/jest-watcher/src/lib/formatTestNameByPattern.ts index c42e15b3dfab..b941c9887758 100644 --- a/packages/jest-watcher/src/lib/formatTestNameByPattern.js +++ b/packages/jest-watcher/src/lib/formatTestNameByPattern.ts @@ -3,8 +3,6 @@ * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. - * - * @flow */ import chalk from 'chalk'; @@ -31,7 +29,7 @@ export default (testName: string, pattern: string, width: number) => { return chalk.dim(inlineTestName); } - const startPatternIndex = Math.max(match.index, 0); + const startPatternIndex = Math.max(match.index || 0, 0); const endPatternIndex = startPatternIndex + match[0].length; if (inlineTestName.length <= width) { diff --git a/packages/jest-watcher/src/lib/patternModeHelpers.js b/packages/jest-watcher/src/lib/patternModeHelpers.ts similarity index 88% rename from packages/jest-watcher/src/lib/patternModeHelpers.js rename to packages/jest-watcher/src/lib/patternModeHelpers.ts index fc57d5ad92f3..df411ad12d18 100644 --- a/packages/jest-watcher/src/lib/patternModeHelpers.js +++ b/packages/jest-watcher/src/lib/patternModeHelpers.ts @@ -3,19 +3,15 @@ * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. - * - * @flow */ -'use strict'; - import chalk from 'chalk'; import ansiEscapes from 'ansi-escapes'; import stringLength from 'string-length'; export const printPatternCaret = ( pattern: string, - pipe: stream$Writable | tty$WriteStream, + pipe: NodeJS.WritableStream, ) => { const inputText = `${chalk.dim(' pattern \u203A')} ${pattern}`; @@ -27,7 +23,7 @@ export const printPatternCaret = ( export const printRestoredPatternCaret = ( pattern: string, currentUsageRows: number, - pipe: stream$Writable | tty$WriteStream, + pipe: NodeJS.WritableStream, ) => { const inputText = `${chalk.dim(' pattern \u203A')} ${pattern}`; diff --git a/packages/jest-watcher/src/lib/scroll.js b/packages/jest-watcher/src/lib/scroll.ts similarity index 89% rename from packages/jest-watcher/src/lib/scroll.js rename to packages/jest-watcher/src/lib/scroll.ts index 3f51c5821685..977d9e85786b 100644 --- a/packages/jest-watcher/src/lib/scroll.js +++ b/packages/jest-watcher/src/lib/scroll.ts @@ -3,13 +3,9 @@ * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. - * - * @flow */ -'use strict'; - -import type {ScrollOptions} from 'types/Watch'; +import {ScrollOptions} from '../types'; export default function scroll(size: number, {offset, max}: ScrollOptions) { let start = 0; diff --git a/packages/jest-watcher/src/types.js b/packages/jest-watcher/src/types.js deleted file mode 100644 index 35f8bd0ef357..000000000000 --- a/packages/jest-watcher/src/types.js +++ /dev/null @@ -1,26 +0,0 @@ -/** - * Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - * - * @flow - */ -import type {GlobalConfig} from 'types/Config'; -import type {JestHookSubscriber} from 'types/JestHooks'; - -export type UsageData = { - key: string, - prompt: string, -}; - -export interface WatchPlugin { - +isInternal?: boolean; - +apply?: (hooks: JestHookSubscriber) => void; - +getUsageInfo?: (globalConfig: GlobalConfig) => ?UsageData; - +onKey?: (value: string) => void; - +run?: ( - globalConfig: GlobalConfig, - updateConfigAndRun: Function, - ) => Promise; -} diff --git a/packages/jest-watcher/src/types.ts b/packages/jest-watcher/src/types.ts new file mode 100644 index 000000000000..8886c011cd1f --- /dev/null +++ b/packages/jest-watcher/src/types.ts @@ -0,0 +1,83 @@ +/** + * Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ + +import {Config, TestResult} from '@jest/types'; + +type TestSuiteInfo = { + config: Config.ProjectConfig; + duration?: number; + testPath: string; +}; + +export type JestHookExposedFS = { + projects: Array<{ + config: Config.ProjectConfig; + testPaths: Array; + }>; +}; + +export type FileChange = (fs: JestHookExposedFS) => void; +export type ShouldRunTestSuite = ( + testSuiteInfo: TestSuiteInfo, +) => Promise; +export type TestRunComplete = (results: TestResult.AggregatedResult) => void; + +export type JestHookSubscriber = { + onFileChange: (fn: FileChange) => void; + onTestRunComplete: (fn: TestRunComplete) => void; + shouldRunTestSuite: (fn: ShouldRunTestSuite) => void; +}; + +export type JestHookEmitter = { + onFileChange: (fs: JestHookExposedFS) => void; + onTestRunComplete: (results: TestResult.AggregatedResult) => void; + shouldRunTestSuite: (testSuiteInfo: TestSuiteInfo) => Promise; +}; + +export type UsageData = { + key: string; + prompt: string; +}; + +export type AllowedConfigOptions = Partial< + Pick< + Config.GlobalConfig, + | 'bail' + | 'changedSince' + | 'collectCoverage' + | 'collectCoverageFrom' + | 'collectCoverageOnlyFrom' + | 'coverageDirectory' + | 'coverageReporters' + | 'notify' + | 'notifyMode' + | 'onlyFailures' + | 'reporters' + | 'testNamePattern' + | 'testPathPattern' + | 'updateSnapshot' + | 'verbose' + > & {mode: 'watch' | 'watchAll'} +>; + +export interface WatchPlugin { + isInternal?: boolean; + apply?: (hooks: JestHookSubscriber) => void; + getUsageInfo?: ( + globalConfig: Config.GlobalConfig, + ) => UsageData | undefined | null; + onKey?: (value: string) => void; + run?: ( + globalConfig: Config.GlobalConfig, + updateConfigAndRun: (config?: AllowedConfigOptions) => void, + ) => Promise; +} + +export type ScrollOptions = { + offset: number; + max: number; +}; diff --git a/packages/jest-watcher/tsconfig.json b/packages/jest-watcher/tsconfig.json new file mode 100644 index 000000000000..2bea30d53a40 --- /dev/null +++ b/packages/jest-watcher/tsconfig.json @@ -0,0 +1,8 @@ +{ + "extends": "../../tsconfig.json", + "compilerOptions": { + "rootDir": "src", + "outDir": "build" + }, + "references": [{"path": "../jest-types"}, {"path": "../jest-util"}] +} diff --git a/website/versioned_docs/version-23.x/WatchPlugins.md b/website/versioned_docs/version-23.x/WatchPlugins.md index a2c9c8934189..6f830989149c 100644 --- a/website/versioned_docs/version-23.x/WatchPlugins.md +++ b/website/versioned_docs/version-23.x/WatchPlugins.md @@ -156,6 +156,7 @@ class MyWatchPlugin { For stability and safety reasons, only part of the global configuration keys can be updated with `updateConfigAndRun`. The current white list is as follows: - [`bail`](configuration.html#bail-boolean) +- [`changedSince`](cli.html#changedsince) - [`collectCoverage`](configuration.html#collectcoverage-boolean) - [`collectCoverageFrom`](configuration.html#collectcoveragefrom-array) - [`collectCoverageOnlyFrom`](configuration.html#collectcoverageonlyfrom-array) diff --git a/website/versioned_docs/version-24.0/WatchPlugins.md b/website/versioned_docs/version-24.0/WatchPlugins.md index e9f2c9b1c807..8b6acd192ed7 100644 --- a/website/versioned_docs/version-24.0/WatchPlugins.md +++ b/website/versioned_docs/version-24.0/WatchPlugins.md @@ -156,6 +156,7 @@ class MyWatchPlugin { For stability and safety reasons, only part of the global configuration keys can be updated with `updateConfigAndRun`. The current white list is as follows: - [`bail`](configuration.html#bail-number-boolean) +- [`changedSince`](cli.html#changedsince) - [`collectCoverage`](configuration.html#collectcoverage-boolean) - [`collectCoverageFrom`](configuration.html#collectcoveragefrom-array) - [`collectCoverageOnlyFrom`](configuration.html#collectcoverageonlyfrom-array)