Skip to content

Commit

Permalink
chore: use types from @jest/reporter in @jest/core (#8045)
Browse files Browse the repository at this point in the history
  • Loading branch information
SimenB authored Mar 4, 2019
1 parent 4a5d5d7 commit 38a37aa
Show file tree
Hide file tree
Showing 10 changed files with 28 additions and 38 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@
- `[jest-runner]`: Migrate to TypeScript ([#7968](https://github.com/facebook/jest/pull/7968))
- `[jest-runtime]`: Migrate to TypeScript ([#7964](https://github.com/facebook/jest/pull/7964), [#7988](https://github.com/facebook/jest/pull/7988))
- `[@jest/fake-timers]`: Extract FakeTimers class from `jest-util` into a new separate package ([#7987](https://github.com/facebook/jest/pull/7987))
- `[@jest/reporters]`: Migrate to TypeScript ([#7994](https://github.com/facebook/jest/pull/7994))
- `[@jest/reporters]`: Migrate to TypeScript ([#7994](https://github.com/facebook/jest/pull/7994), [#8045](https://github.com/facebook/jest/pull/8045))
- `[jest-repl]`: Migrate to TypeScript ([#8000](https://github.com/facebook/jest/pull/8000))
- `[jest-validate]`: Migrate to TypeScript ([#7991](https://github.com/facebook/jest/pull/7991))
- `[docs]`: Update CONTRIBUTING.md to add information about running jest with `jest-circus` locally ([#8013](https://github.com/facebook/jest/pull/8013)).
Expand Down
9 changes: 4 additions & 5 deletions packages/jest-circus/src/globalErrorHandlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,13 @@
import {dispatch} from './state';
import {GlobalErrorHandlers} from './types';

type Process = NodeJS.Process;

const uncaught = (error: Error) => {
const uncaught: NodeJS.UncaughtExceptionListener &
NodeJS.UnhandledRejectionListener = (error: unknown) => {
dispatch({error, name: 'error'});
};

export const injectGlobalErrorHandlers = (
parentProcess: Process,
parentProcess: NodeJS.Process,
): GlobalErrorHandlers => {
const uncaughtException = process.listeners('uncaughtException').slice();
const unhandledRejection = process.listeners('unhandledRejection').slice();
Expand All @@ -27,7 +26,7 @@ export const injectGlobalErrorHandlers = (
};

export const restoreGlobalErrorHandlers = (
parentProcess: Process,
parentProcess: NodeJS.Process,
originalErrorHandlers: GlobalErrorHandlers,
) => {
parentProcess.removeListener('uncaughtException', uncaught);
Expand Down
2 changes: 1 addition & 1 deletion packages/jest-core/src/ReporterDispatcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import {TestResult} from '@jest/types';
import {Test} from 'jest-runner';
import {Context} from 'jest-runtime';
import {Reporter, ReporterOnStartOptions} from './types';
import {Reporter, ReporterOnStartOptions} from '@jest/reporters';

export default class ReporterDispatcher {
private _reporters: Array<Reporter>;
Expand Down
3 changes: 1 addition & 2 deletions packages/jest-core/src/TestScheduler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import {
NotifyReporter,
SummaryReporter,
VerboseReporter,
// @ts-ignore: Not migrated to TS
Reporter,
} from '@jest/reporters';
import exit from 'exit';
import {
Expand All @@ -28,7 +28,6 @@ import {
import ReporterDispatcher from './ReporterDispatcher';
import TestWatcher from './TestWatcher';
import {shouldRunInBand} from './testSchedulerHelper';
import {Reporter} from './types';

// The default jest-runner is required because it is the default test runner
// and required implicitly through the `runner` ProjectConfig option.
Expand Down
26 changes: 1 addition & 25 deletions packages/jest-core/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import {Context} from 'jest-runtime';
import {Test} from 'jest-runner';
import {Config, TestResult} from '@jest/types';
import {Config} from '@jest/types';

export type TestRunData = Array<{
context: Context;
Expand Down Expand Up @@ -38,27 +38,3 @@ export type TestPathCases = {
export type TestPathCasesWithPathPattern = TestPathCases & {
testPathPattern: (path: Config.Path) => boolean;
};

// TODO: Obtain this from @jest/reporters once its been migrated
export type ReporterOnStartOptions = {
estimatedTime: number;
showStatus: boolean;
};

export type Reporter = {
onTestResult: (
test: Test,
testResult: TestResult.TestResult,
aggregatedResult: TestResult.AggregatedResult,
) => Promise<void>;
onRunStart: (
results: TestResult.AggregatedResult,
options: ReporterOnStartOptions,
) => Promise<void>;
onTestStart: (test: Test) => Promise<void>;
onRunComplete: (
contexts: Set<Context>,
results: TestResult.AggregatedResult,
) => Promise<void>;
getLastError: () => Error;
};
2 changes: 1 addition & 1 deletion packages/jest-core/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@
"rootDir": "src",
"outDir": "build"
},
// TODO: This is missing `@jest/reporters`
"references": [
{"path": "../jest-changed-files"},
{"path": "../jest-config"},
{"path": "../jest-console"},
{"path": "../jest-haste-map"},
{"path": "../jest-message-util"},
{"path": "../jest-regex-util"},
{"path": "../jest-reporters"},
{"path": "../jest-resolve-dependencies"},
{"path": "../jest-runner"},
{"path": "../jest-runtime"},
Expand Down
5 changes: 5 additions & 0 deletions packages/jest-haste-map/src/crawlers/node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,11 @@ function findNative(

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

Expand Down
1 change: 1 addition & 0 deletions packages/jest-reporters/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ export {default as DefaultReporter} from './default_reporter';
export {default as NotifyReporter} from './notify_reporter';
export {default as SummaryReporter} from './summary_reporter';
export {default as VerboseReporter} from './verbose_reporter';
export {Reporter, ReporterOnStartOptions} from './types';
10 changes: 10 additions & 0 deletions packages/jest-worker/src/workers/ChildProcessWorker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,10 +158,20 @@ export default class ChildProcessWorker implements WorkerInterface {
}

getStdout(): NodeJS.ReadableStream {
if (this._child.stdout === null) {
throw new Error(
'stdout is null - this should never happen. Please open up an issue at https://github.com/facebook/jest',
);
}
return this._child.stdout;
}

getStderr(): NodeJS.ReadableStream {
if (this._child.stderr === null) {
throw new Error(
'stderr is null - this should never happen. Please open up an issue at https://github.com/facebook/jest',
);
}
return this._child.stderr;
}
}
6 changes: 3 additions & 3 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1733,9 +1733,9 @@
integrity sha512-bNtBj6AF1F90jp54KRPOrYfilGNfPr2kpaUN7rMJjauAtfGBXzT/T/REZN6jb4qUs9FTxU37kir3Nrn5WsTUDw==

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

"@types/p-each-series@^1.0.0":
version "1.0.0"
Expand Down

0 comments on commit 38a37aa

Please sign in to comment.