From 6d2686475f226fad13c470b5b89f20a29b6e3380 Mon Sep 17 00:00:00 2001 From: Simen Bekkhus Date: Mon, 4 Mar 2019 17:57:11 +0100 Subject: [PATCH 1/2] chore: use types from @jest/reporter in @jest/core --- .../jest-circus/src/globalErrorHandlers.ts | 9 +++---- packages/jest-core/src/ReporterDispatcher.ts | 2 +- packages/jest-core/src/TestScheduler.ts | 3 +-- packages/jest-core/src/types.ts | 26 +------------------ packages/jest-core/tsconfig.json | 2 +- packages/jest-haste-map/src/crawlers/node.ts | 5 ++++ packages/jest-reporters/src/index.ts | 1 + .../src/workers/ChildProcessWorker.ts | 10 +++++++ yarn.lock | 6 ++--- 9 files changed, 27 insertions(+), 37 deletions(-) diff --git a/packages/jest-circus/src/globalErrorHandlers.ts b/packages/jest-circus/src/globalErrorHandlers.ts index 5acd9ffac9a9..0bf47f870d70 100644 --- a/packages/jest-circus/src/globalErrorHandlers.ts +++ b/packages/jest-circus/src/globalErrorHandlers.ts @@ -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(); @@ -27,7 +26,7 @@ export const injectGlobalErrorHandlers = ( }; export const restoreGlobalErrorHandlers = ( - parentProcess: Process, + parentProcess: NodeJS.Process, originalErrorHandlers: GlobalErrorHandlers, ) => { parentProcess.removeListener('uncaughtException', uncaught); diff --git a/packages/jest-core/src/ReporterDispatcher.ts b/packages/jest-core/src/ReporterDispatcher.ts index b36299aa1cb9..89e1024b3646 100644 --- a/packages/jest-core/src/ReporterDispatcher.ts +++ b/packages/jest-core/src/ReporterDispatcher.ts @@ -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; diff --git a/packages/jest-core/src/TestScheduler.ts b/packages/jest-core/src/TestScheduler.ts index 737241fd4d4b..859f10cd1008 100644 --- a/packages/jest-core/src/TestScheduler.ts +++ b/packages/jest-core/src/TestScheduler.ts @@ -17,7 +17,7 @@ import { NotifyReporter, SummaryReporter, VerboseReporter, - // @ts-ignore: Not migrated to TS + Reporter, } from '@jest/reporters'; import exit from 'exit'; import { @@ -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. diff --git a/packages/jest-core/src/types.ts b/packages/jest-core/src/types.ts index debd9af8d73a..450f8095c3b9 100644 --- a/packages/jest-core/src/types.ts +++ b/packages/jest-core/src/types.ts @@ -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; @@ -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; - onRunStart: ( - results: TestResult.AggregatedResult, - options: ReporterOnStartOptions, - ) => Promise; - onTestStart: (test: Test) => Promise; - onRunComplete: ( - contexts: Set, - results: TestResult.AggregatedResult, - ) => Promise; - getLastError: () => Error; -}; diff --git a/packages/jest-core/tsconfig.json b/packages/jest-core/tsconfig.json index b235da20ff81..2911ca431c27 100644 --- a/packages/jest-core/tsconfig.json +++ b/packages/jest-core/tsconfig.json @@ -4,7 +4,6 @@ "rootDir": "src", "outDir": "build" }, - // TODO: This is missing `@jest/reporters` "references": [ {"path": "../jest-changed-files"}, {"path": "../jest-config"}, @@ -12,6 +11,7 @@ {"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"}, diff --git a/packages/jest-haste-map/src/crawlers/node.ts b/packages/jest-haste-map/src/crawlers/node.ts index 6813e79ac519..2f3cb61e2c5e 100644 --- a/packages/jest-haste-map/src/crawlers/node.ts +++ b/packages/jest-haste-map/src/crawlers/node.ts @@ -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)); diff --git a/packages/jest-reporters/src/index.ts b/packages/jest-reporters/src/index.ts index d706797ee0fd..22342bd5307b 100644 --- a/packages/jest-reporters/src/index.ts +++ b/packages/jest-reporters/src/index.ts @@ -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'; diff --git a/packages/jest-worker/src/workers/ChildProcessWorker.ts b/packages/jest-worker/src/workers/ChildProcessWorker.ts index d72833a5b2c3..5a062ae2784b 100644 --- a/packages/jest-worker/src/workers/ChildProcessWorker.ts +++ b/packages/jest-worker/src/workers/ChildProcessWorker.ts @@ -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; } } diff --git a/yarn.lock b/yarn.lock index 35dfdc279ddb..1fdc97ddaadd 100644 --- a/yarn.lock +++ b/yarn.lock @@ -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" From e02f90b49250e5b385369488e9e115e795bda446 Mon Sep 17 00:00:00 2001 From: Simen Bekkhus Date: Mon, 4 Mar 2019 18:05:07 +0100 Subject: [PATCH 2/2] changelog --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 051e7bf00cc1..6798246e4d06 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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)).