Skip to content

Commit 38a37aa

Browse files
authored
chore: use types from @jest/reporter in @jest/core (#8045)
1 parent 4a5d5d7 commit 38a37aa

File tree

10 files changed

+28
-38
lines changed

10 files changed

+28
-38
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@
7474
- `[jest-runner]`: Migrate to TypeScript ([#7968](https://github.com/facebook/jest/pull/7968))
7575
- `[jest-runtime]`: Migrate to TypeScript ([#7964](https://github.com/facebook/jest/pull/7964), [#7988](https://github.com/facebook/jest/pull/7988))
7676
- `[@jest/fake-timers]`: Extract FakeTimers class from `jest-util` into a new separate package ([#7987](https://github.com/facebook/jest/pull/7987))
77-
- `[@jest/reporters]`: Migrate to TypeScript ([#7994](https://github.com/facebook/jest/pull/7994))
77+
- `[@jest/reporters]`: Migrate to TypeScript ([#7994](https://github.com/facebook/jest/pull/7994), [#8045](https://github.com/facebook/jest/pull/8045))
7878
- `[jest-repl]`: Migrate to TypeScript ([#8000](https://github.com/facebook/jest/pull/8000))
7979
- `[jest-validate]`: Migrate to TypeScript ([#7991](https://github.com/facebook/jest/pull/7991))
8080
- `[docs]`: Update CONTRIBUTING.md to add information about running jest with `jest-circus` locally ([#8013](https://github.com/facebook/jest/pull/8013)).

packages/jest-circus/src/globalErrorHandlers.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,13 @@
88
import {dispatch} from './state';
99
import {GlobalErrorHandlers} from './types';
1010

11-
type Process = NodeJS.Process;
12-
13-
const uncaught = (error: Error) => {
11+
const uncaught: NodeJS.UncaughtExceptionListener &
12+
NodeJS.UnhandledRejectionListener = (error: unknown) => {
1413
dispatch({error, name: 'error'});
1514
};
1615

1716
export const injectGlobalErrorHandlers = (
18-
parentProcess: Process,
17+
parentProcess: NodeJS.Process,
1918
): GlobalErrorHandlers => {
2019
const uncaughtException = process.listeners('uncaughtException').slice();
2120
const unhandledRejection = process.listeners('unhandledRejection').slice();
@@ -27,7 +26,7 @@ export const injectGlobalErrorHandlers = (
2726
};
2827

2928
export const restoreGlobalErrorHandlers = (
30-
parentProcess: Process,
29+
parentProcess: NodeJS.Process,
3130
originalErrorHandlers: GlobalErrorHandlers,
3231
) => {
3332
parentProcess.removeListener('uncaughtException', uncaught);

packages/jest-core/src/ReporterDispatcher.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import {TestResult} from '@jest/types';
99
import {Test} from 'jest-runner';
1010
import {Context} from 'jest-runtime';
11-
import {Reporter, ReporterOnStartOptions} from './types';
11+
import {Reporter, ReporterOnStartOptions} from '@jest/reporters';
1212

1313
export default class ReporterDispatcher {
1414
private _reporters: Array<Reporter>;

packages/jest-core/src/TestScheduler.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import {
1717
NotifyReporter,
1818
SummaryReporter,
1919
VerboseReporter,
20-
// @ts-ignore: Not migrated to TS
20+
Reporter,
2121
} from '@jest/reporters';
2222
import exit from 'exit';
2323
import {
@@ -28,7 +28,6 @@ import {
2828
import ReporterDispatcher from './ReporterDispatcher';
2929
import TestWatcher from './TestWatcher';
3030
import {shouldRunInBand} from './testSchedulerHelper';
31-
import {Reporter} from './types';
3231

3332
// The default jest-runner is required because it is the default test runner
3433
// and required implicitly through the `runner` ProjectConfig option.

packages/jest-core/src/types.ts

Lines changed: 1 addition & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
import {Context} from 'jest-runtime';
99
import {Test} from 'jest-runner';
10-
import {Config, TestResult} from '@jest/types';
10+
import {Config} from '@jest/types';
1111

1212
export type TestRunData = Array<{
1313
context: Context;
@@ -38,27 +38,3 @@ export type TestPathCases = {
3838
export type TestPathCasesWithPathPattern = TestPathCases & {
3939
testPathPattern: (path: Config.Path) => boolean;
4040
};
41-
42-
// TODO: Obtain this from @jest/reporters once its been migrated
43-
export type ReporterOnStartOptions = {
44-
estimatedTime: number;
45-
showStatus: boolean;
46-
};
47-
48-
export type Reporter = {
49-
onTestResult: (
50-
test: Test,
51-
testResult: TestResult.TestResult,
52-
aggregatedResult: TestResult.AggregatedResult,
53-
) => Promise<void>;
54-
onRunStart: (
55-
results: TestResult.AggregatedResult,
56-
options: ReporterOnStartOptions,
57-
) => Promise<void>;
58-
onTestStart: (test: Test) => Promise<void>;
59-
onRunComplete: (
60-
contexts: Set<Context>,
61-
results: TestResult.AggregatedResult,
62-
) => Promise<void>;
63-
getLastError: () => Error;
64-
};

packages/jest-core/tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@
44
"rootDir": "src",
55
"outDir": "build"
66
},
7-
// TODO: This is missing `@jest/reporters`
87
"references": [
98
{"path": "../jest-changed-files"},
109
{"path": "../jest-config"},
1110
{"path": "../jest-console"},
1211
{"path": "../jest-haste-map"},
1312
{"path": "../jest-message-util"},
1413
{"path": "../jest-regex-util"},
14+
{"path": "../jest-reporters"},
1515
{"path": "../jest-resolve-dependencies"},
1616
{"path": "../jest-runner"},
1717
{"path": "../jest-runtime"},

packages/jest-haste-map/src/crawlers/node.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,11 @@ function findNative(
9696

9797
const child = spawn('find', args);
9898
let stdout = '';
99+
if (child.stdout === null) {
100+
throw new Error(
101+
'stdout is null - this should never happen. Please open up an issue at https://github.com/facebook/jest',
102+
);
103+
}
99104
child.stdout.setEncoding('utf-8');
100105
child.stdout.on('data', data => (stdout += data));
101106

packages/jest-reporters/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,4 @@ export {default as DefaultReporter} from './default_reporter';
1111
export {default as NotifyReporter} from './notify_reporter';
1212
export {default as SummaryReporter} from './summary_reporter';
1313
export {default as VerboseReporter} from './verbose_reporter';
14+
export {Reporter, ReporterOnStartOptions} from './types';

packages/jest-worker/src/workers/ChildProcessWorker.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,10 +158,20 @@ export default class ChildProcessWorker implements WorkerInterface {
158158
}
159159

160160
getStdout(): NodeJS.ReadableStream {
161+
if (this._child.stdout === null) {
162+
throw new Error(
163+
'stdout is null - this should never happen. Please open up an issue at https://github.com/facebook/jest',
164+
);
165+
}
161166
return this._child.stdout;
162167
}
163168

164169
getStderr(): NodeJS.ReadableStream {
170+
if (this._child.stderr === null) {
171+
throw new Error(
172+
'stderr is null - this should never happen. Please open up an issue at https://github.com/facebook/jest',
173+
);
174+
}
165175
return this._child.stderr;
166176
}
167177
}

yarn.lock

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1733,9 +1733,9 @@
17331733
integrity sha512-bNtBj6AF1F90jp54KRPOrYfilGNfPr2kpaUN7rMJjauAtfGBXzT/T/REZN6jb4qUs9FTxU37kir3Nrn5WsTUDw==
17341734

17351735
"@types/node@*", "@types/node@^11.9.6":
1736-
version "11.9.6"
1737-
resolved "https://registry.yarnpkg.com/@types/node/-/node-11.9.6.tgz#c632bbcc780a1349673a6e2e9b9dfa8c369d3c74"
1738-
integrity sha512-4hS2K4gwo9/aXIcoYxCtHpdgd8XUeDmo1siRCAH3RziXB65JlPqUFMtfy9VPj+og7dp3w1TFjGwYga4e0m9GwA==
1736+
version "11.10.4"
1737+
resolved "https://registry.yarnpkg.com/@types/node/-/node-11.10.4.tgz#3f5fc4f0f322805f009e00ab35a2ff3d6b778e42"
1738+
integrity sha512-wa09itaLE8L705aXd8F80jnFpxz3Y1/KRHfKsYL2bPc0XF+wEWu8sR9n5bmeu8Ba1N9z2GRNzm/YdHcghLkLKg==
17391739

17401740
"@types/p-each-series@^1.0.0":
17411741
version "1.0.0"

0 commit comments

Comments
 (0)