Skip to content

Commit

Permalink
feat(jest-core, jest-watcher)!: move TestWatcher class to `jest-wat…
Browse files Browse the repository at this point in the history
…cher` (#12652)
  • Loading branch information
mrazauskas authored Apr 8, 2022
1 parent 051af02 commit 09fa164
Show file tree
Hide file tree
Showing 20 changed files with 18 additions and 30 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
- `[jest-cli, jest-core]` Add `--ignoreProjects` CLI argument to ignore test suites by project name ([#12620](https://github.com/facebook/jest/pull/12620))
- `[jest-core]` Pass project config to `globalSetup`/`globalTeardown` function as second argument ([#12440](https://github.com/facebook/jest/pull/12440))
- `[jest-core]` Stabilize test runners with event emitters ([#12641](https://github.com/facebook/jest/pull/12641))
- `[jest-core, jest-watcher]` [**BREAKING**] Move `TestWatcher` class to `jest-watcher` package ([#12652](https://github.com/facebook/jest/pull/12652))
- `[jest-environment-jsdom]` [**BREAKING**] Upgrade jsdom to 19.0.0 ([#12290](https://github.com/facebook/jest/pull/12290))
- `[jest-environment-jsdom]` [**BREAKING**] Add default `browser` condition to `exportConditions` for `jsdom` environment ([#11924](https://github.com/facebook/jest/pull/11924))
- `[jest-environment-jsdom]` [**BREAKING**] Pass global config to Jest environment constructor for `jsdom` environment ([#12461](https://github.com/facebook/jest/pull/12461))
Expand Down
2 changes: 1 addition & 1 deletion e2e/transform/transform-runner/runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ import type {
OnTestStart,
OnTestSuccess,
TestRunnerContext,
TestWatcher,
} from 'jest-runner';
import type {TestWatcher} from 'jest-watcher';

export default class BaseTestRunner {
private _globalConfig: Config.GlobalConfig;
Expand Down
1 change: 0 additions & 1 deletion packages/jest-core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
"@types/node": "*",
"ansi-escapes": "^4.2.1",
"chalk": "^4.0.0",
"emittery": "^0.10.2",
"exit": "^0.1.2",
"graceful-fs": "^4.2.9",
"jest-changed-files": "^28.0.0-alpha.3",
Expand Down
2 changes: 1 addition & 1 deletion packages/jest-core/src/TestScheduler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ import {
cleanup as cleanupSnapshots,
} from 'jest-snapshot';
import {requireOrImportModule} from 'jest-util';
import type {TestWatcher} from 'jest-watcher';
import ReporterDispatcher from './ReporterDispatcher';
import type TestWatcher from './TestWatcher';
import {shouldRunInBand} from './testSchedulerHelper';

type TestRunnerConstructor = new (
Expand Down
3 changes: 1 addition & 2 deletions packages/jest-core/src/__tests__/watch.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,8 @@
*/

import chalk from 'chalk';
import {JestHook, KEYS} from 'jest-watcher';
// eslint-disable-next-line import/order
import TestWatcher from '../TestWatcher';
import {JestHook, KEYS, TestWatcher} from 'jest-watcher';

const runJestMock = jest.fn();
const watchPluginPath = `${__dirname}/__fixtures__/watchPlugin`;
Expand Down
2 changes: 1 addition & 1 deletion packages/jest-core/src/cli/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import {readConfigs} from 'jest-config';
import type HasteMap from 'jest-haste-map';
import Runtime, {Context} from 'jest-runtime';
import {createDirectory, preRunMessage} from 'jest-util';
import TestWatcher from '../TestWatcher';
import {TestWatcher} from 'jest-watcher';
import {formatHandleErrors} from '../collectHandles';
import getChangedFilesPromise from '../getChangedFilesPromise';
import getConfigsOfProjectsToRun from '../getConfigsOfProjectsToRun';
Expand Down
1 change: 0 additions & 1 deletion packages/jest-core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,5 @@

export {default as SearchSource} from './SearchSource';
export {createTestScheduler} from './TestScheduler';
export {default as TestWatcher} from './TestWatcher';
export {runCLI} from './cli';
export {default as getVersion} from './version';
2 changes: 1 addition & 1 deletion packages/jest-core/src/runJest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ import Resolver from 'jest-resolve';
import type {Context} from 'jest-runtime';
import {requireOrImportModule, tryRealpath} from 'jest-util';
import {JestHook, JestHookEmitter} from 'jest-watcher';
import type {TestWatcher} from 'jest-watcher';
import type FailedTestsCache from './FailedTestsCache';
import SearchSource from './SearchSource';
import {TestSchedulerContext, createTestScheduler} from './TestScheduler';
import type TestWatcher from './TestWatcher';
import collectNodeHandles, {HandleCollectionResult} from './collectHandles';
import getNoTestsFoundMessage from './getNoTestsFoundMessage';
import runGlobalHook from './runGlobalHook';
Expand Down
2 changes: 1 addition & 1 deletion packages/jest-core/src/watch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@ import {
AllowedConfigOptions,
JestHook,
KEYS,
TestWatcher,
WatchPlugin,
WatchPluginClass,
} from 'jest-watcher';
import FailedTestsCache from './FailedTestsCache';
import SearchSource from './SearchSource';
import TestWatcher from './TestWatcher';
import getChangedFilesPromise from './getChangedFilesPromise';
import activeFilters from './lib/activeFiltersMessage';
import createContext from './lib/createContext';
Expand Down
2 changes: 1 addition & 1 deletion packages/jest-runner/__typetests__/jest-runner.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ import type {
OnTestSuccess,
TestRunnerContext,
TestRunnerOptions,
TestWatcher,
UnsubscribeFn,
} from 'jest-runner';
import type {TestWatcher} from 'jest-watcher';

const globalConfig = {} as Config.GlobalConfig;
const runnerContext = {} as TestRunnerContext;
Expand Down
1 change: 1 addition & 0 deletions packages/jest-runner/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
"jest-resolve": "^28.0.0-alpha.8",
"jest-runtime": "^28.0.0-alpha.8",
"jest-util": "^28.0.0-alpha.8",
"jest-watcher": "^28.0.0-alpha.8",
"jest-worker": "^28.0.0-alpha.8",
"source-map-support": "^0.5.6",
"throat": "^6.0.1"
Expand Down
2 changes: 1 addition & 1 deletion packages/jest-runner/src/__tests__/testRunner.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
*
*/

import {TestWatcher} from '@jest/core';
import type {TestContext} from '@jest/test-result';
import {makeGlobalConfig, makeProjectConfig} from '@jest/test-utils';
import {TestWatcher} from 'jest-watcher';
import TestRunner from '../index';

let mockWorkerFarm;
Expand Down
9 changes: 2 additions & 7 deletions packages/jest-runner/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,11 @@ import type {
TestResult,
} from '@jest/test-result';
import {deepCyclicCopy} from 'jest-util';
import type {TestWatcher} from 'jest-watcher';
import {PromiseWithCustomMessage, Worker} from 'jest-worker';
import runTest from './runTest';
import type {SerializableResolver, worker} from './testWorker';
import {
EmittingTestRunner,
TestRunnerOptions,
TestWatcher,
UnsubscribeFn,
} from './types';
import {EmittingTestRunner, TestRunnerOptions, UnsubscribeFn} from './types';

const TEST_WORKER_PATH = require.resolve('./testWorker');

Expand All @@ -36,7 +32,6 @@ export type {
OnTestFailure,
OnTestStart,
OnTestSuccess,
TestWatcher,
TestRunnerContext,
TestRunnerOptions,
JestTestRunner,
Expand Down
11 changes: 1 addition & 10 deletions packages/jest-runner/src/types.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 Emittery = require('emittery');
import type {JestEnvironment} from '@jest/environment';
import type {
SerializableError,
Expand All @@ -16,6 +15,7 @@ import type {
} from '@jest/test-result';
import type {Config} from '@jest/types';
import type RuntimeType from 'jest-runtime';
import type {TestWatcher} from 'jest-watcher';

export type ErrorWithCode = Error & {code?: string};

Expand Down Expand Up @@ -96,12 +96,3 @@ export abstract class EmittingTestRunner extends BaseTestRunner {
}

export type JestTestRunner = CallbackTestRunner | EmittingTestRunner;

// TODO: Should live in `@jest/core` or `jest-watcher`
type WatcherState = {interrupted: boolean};
export interface TestWatcher extends Emittery<{change: WatcherState}> {
state: WatcherState;
setState(state: WatcherState): void;
isInterrupted(): boolean;
isWatchMode(): boolean;
}
1 change: 1 addition & 0 deletions packages/jest-runner/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
{"path": "../jest-transform"},
{"path": "../jest-types"},
{"path": "../jest-util"},
{"path": "../jest-watcher"},
{"path": "../jest-worker"}
]
}
1 change: 1 addition & 0 deletions packages/jest-watcher/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"@types/node": "*",
"ansi-escapes": "^4.2.1",
"chalk": "^4.0.0",
"emittery": "^0.10.2",
"jest-util": "^28.0.0-alpha.8",
"string-length": "^4.0.1"
},
Expand Down
File renamed without changes.
1 change: 1 addition & 0 deletions packages/jest-watcher/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
export {default as BaseWatchPlugin} from './BaseWatchPlugin';
export {default as JestHook} from './JestHooks';
export {default as PatternPrompt} from './PatternPrompt';
export {default as TestWatcher} from './TestWatcher';
export * from './constants';
export type {
AllowedConfigOptions,
Expand Down
1 change: 0 additions & 1 deletion packages/jest/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

export {
SearchSource,
TestWatcher,
createTestScheduler,
getVersion,
runCLI,
Expand Down
3 changes: 2 additions & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2557,7 +2557,6 @@ __metadata:
"@types/rimraf": ^3.0.0
ansi-escapes: ^4.2.1
chalk: ^4.0.0
emittery: ^0.10.2
exit: ^0.1.2
graceful-fs: ^4.2.9
jest-changed-files: ^28.0.0-alpha.3
Expand Down Expand Up @@ -13514,6 +13513,7 @@ __metadata:
jest-resolve: ^28.0.0-alpha.8
jest-runtime: ^28.0.0-alpha.8
jest-util: ^28.0.0-alpha.8
jest-watcher: ^28.0.0-alpha.8
jest-worker: ^28.0.0-alpha.8
source-map-support: ^0.5.6
throat: ^6.0.1
Expand Down Expand Up @@ -13721,6 +13721,7 @@ __metadata:
"@types/node": "*"
ansi-escapes: ^4.2.1
chalk: ^4.0.0
emittery: ^0.10.2
jest-util: ^28.0.0-alpha.8
string-length: ^4.0.1
languageName: unknown
Expand Down

0 comments on commit 09fa164

Please sign in to comment.