Skip to content

Commit

Permalink
chore: make TestWatcher extend emittery
Browse files Browse the repository at this point in the history
  • Loading branch information
SimenB committed Jul 28, 2020
1 parent 76f356e commit ae3b43c
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 9 deletions.
1 change: 1 addition & 0 deletions packages/jest-core/package.json
Expand Up @@ -13,6 +13,7 @@
"@types/node": "*",
"ansi-escapes": "^4.2.1",
"chalk": "^4.0.0",
"emittery": "^0.7.1",
"exit": "^0.1.2",
"graceful-fs": "^4.2.4",
"jest-changed-files": "^26.1.0",
Expand Down
4 changes: 2 additions & 2 deletions packages/jest-core/src/TestWatcher.ts
Expand Up @@ -5,13 +5,13 @@
* LICENSE file in the root directory of this source tree.
*/

import {EventEmitter} from 'events';
import emittery = require('emittery');

type State = {
interrupted: boolean;
};

export default class TestWatcher extends EventEmitter {
export default class TestWatcher extends emittery.Typed<{change: State}> {
state: State;
private _isWatchMode: boolean;

Expand Down
1 change: 1 addition & 0 deletions packages/jest-runner/package.json
Expand Up @@ -16,6 +16,7 @@
"@jest/types": "^26.1.0",
"@types/node": "*",
"chalk": "^4.0.0",
"emittery": "^0.7.1",
"exit": "^0.1.2",
"graceful-fs": "^4.2.4",
"jest-config": "^26.1.0",
Expand Down
3 changes: 1 addition & 2 deletions packages/jest-runner/src/index.ts
Expand Up @@ -21,7 +21,6 @@ import type {
TestRunnerContext as JestTestRunnerContext,
TestRunnerOptions as JestTestRunnerOptions,
TestWatcher as JestTestWatcher,
WatcherState,
} from './types';

const TEST_WORKER_PATH = require.resolve('./testWorker');
Expand Down Expand Up @@ -179,7 +178,7 @@ class TestRunner {
};

const onInterrupt = new Promise((_, reject) => {
watcher.on('change', (state: WatcherState) => {
watcher.on('change', state => {
if (state.interrupted) {
reject(new CancelRun());
}
Expand Down
8 changes: 3 additions & 5 deletions packages/jest-runner/src/types.ts
Expand Up @@ -5,7 +5,7 @@
* LICENSE file in the root directory of this source tree.
*/

import type {EventEmitter} from 'events';
import type {Typed as EmitteryTyped} from 'emittery';
import type {Config} from '@jest/types';
import type {SerializableError, TestResult} from '@jest/test-result';
import type {JestEnvironment} from '@jest/environment';
Expand Down Expand Up @@ -61,10 +61,8 @@ export type TestRunnerSerializedContext = {
};

// TODO: Should live in `@jest/core` or `jest-watcher`
export type WatcherState = {
interrupted: boolean;
};
export interface TestWatcher extends EventEmitter {
type WatcherState = {interrupted: boolean};
export interface TestWatcher extends EmitteryTyped<{change: WatcherState}> {
state: WatcherState;
setState(state: WatcherState): void;
isInterrupted(): boolean;
Expand Down
9 changes: 9 additions & 0 deletions yarn.lock
Expand Up @@ -1708,6 +1708,7 @@ __metadata:
"@types/rimraf": ^3.0.0
ansi-escapes: ^4.2.1
chalk: ^4.0.0
emittery: ^0.7.1
exit: ^0.1.2
graceful-fs: ^4.2.4
jest-changed-files: ^26.1.0
Expand Down Expand Up @@ -7224,6 +7225,13 @@ __metadata:
languageName: node
linkType: hard

"emittery@npm:^0.7.1":
version: 0.7.1
resolution: "emittery@npm:0.7.1"
checksum: 917b0995126e004ddf175e7d0a74ae8608083846c3f3608e964bf13caba220a003b7455ced5bf813a40e977605be48e53c74f6150fbe587a47ef6b985b8a447e
languageName: node
linkType: hard

"emoji-regex@npm:>=6.0.0 <=6.1.1":
version: 6.1.1
resolution: "emoji-regex@npm:6.1.1"
Expand Down Expand Up @@ -11453,6 +11461,7 @@ fsevents@^1.2.7:
"@types/node": "*"
"@types/source-map-support": ^0.5.0
chalk: ^4.0.0
emittery: ^0.7.1
exit: ^0.1.2
graceful-fs: ^4.2.4
jest-circus: ^26.1.0
Expand Down

0 comments on commit ae3b43c

Please sign in to comment.