From 06d20a9a5ecc8251a2e4bee9438b4401bb8bd8a2 Mon Sep 17 00:00:00 2001 From: Andrew Makarov Date: Sat, 23 Feb 2019 15:43:12 +0300 Subject: [PATCH 1/4] Migrate jest-phabricator to TypeScript --- CHANGELOG.md | 1 + packages/jest-phabricator/package.json | 4 ++++ packages/jest-phabricator/src/{index.js => index.ts} | 10 ++++------ packages/jest-phabricator/tsconfig.json | 12 ++++++++++++ 4 files changed, 21 insertions(+), 6 deletions(-) rename packages/jest-phabricator/src/{index.js => index.ts} (86%) create mode 100644 packages/jest-phabricator/tsconfig.json diff --git a/CHANGELOG.md b/CHANGELOG.md index aa078a389e3e..227365427b90 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -55,6 +55,7 @@ - `[jest-resolve-dependencies]`: Migrate to TypeScript ([#7922](https://github.com/facebook/jest/pull/7922)) - `[expect]`: Migrate to TypeScript ([#7919](https://github.com/facebook/jest/pull/7919)) - `[jest-circus]`: Migrate to TypeScript ([#7916](https://github.com/facebook/jest/pull/7916)) +- `[jest-phabricator]`: Migrate to TypeScript ([#7965](https://github.com/facebook/jest/pull/7965)) ### Performance diff --git a/packages/jest-phabricator/package.json b/packages/jest-phabricator/package.json index b711d648af56..f1000201d15c 100644 --- a/packages/jest-phabricator/package.json +++ b/packages/jest-phabricator/package.json @@ -6,6 +6,10 @@ "url": "https://github.com/facebook/jest.git", "directory": "packages/jest-phabricator" }, + "types": "build/index.d.ts", + "dependencies": { + "@jest/types": "^24.1.0" + }, "engines": { "node": ">= 6" }, diff --git a/packages/jest-phabricator/src/index.js b/packages/jest-phabricator/src/index.ts similarity index 86% rename from packages/jest-phabricator/src/index.js rename to packages/jest-phabricator/src/index.ts index 5c02ee4ae1b3..595e09402b58 100644 --- a/packages/jest-phabricator/src/index.js +++ b/packages/jest-phabricator/src/index.ts @@ -3,23 +3,22 @@ * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. - * @flow */ -import type { +import { AggregatedResult, AggregatedResultWithoutCoverage, CoverageMap, -} from 'types/TestResult'; +} from '@jest/types'; type PhabricatorReport = AggregatedResultWithoutCoverage & { - coverageMap?: ?CoverageMap, + coverageMap?: CoverageMap | null; }; function summarize(coverageMap: CoverageMap) { const summaries = Object.create(null); - coverageMap.files().forEach(file => { + coverageMap.files().forEach((file: string) => { const covered = []; const lineCoverage = coverageMap.fileCoverageFor(file).getLineCoverage(); @@ -42,7 +41,6 @@ function summarize(coverageMap: CoverageMap) { } module.exports = function(results: AggregatedResult): PhabricatorReport { - // $FlowFixMe: This should work, but it does not. return { ...results, coverageMap: results.coverageMap && summarize(results.coverageMap), diff --git a/packages/jest-phabricator/tsconfig.json b/packages/jest-phabricator/tsconfig.json new file mode 100644 index 000000000000..7a7b7a460af1 --- /dev/null +++ b/packages/jest-phabricator/tsconfig.json @@ -0,0 +1,12 @@ +{ + "extends": "../../tsconfig.json", + "compilerOptions": { + "rootDir": "src", + "outDir": "build" + }, + "references": [ + { + "path": "../jest-types" + } + ] +} From 00dd71e9a6f3feb13ef795b9e4f2671fc8babe4e Mon Sep 17 00:00:00 2001 From: Andrew Makarov Date: Sat, 23 Feb 2019 16:30:59 +0300 Subject: [PATCH 2/4] Fix --- packages/jest-phabricator/src/index.ts | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/packages/jest-phabricator/src/index.ts b/packages/jest-phabricator/src/index.ts index 595e09402b58..69f9cb85f834 100644 --- a/packages/jest-phabricator/src/index.ts +++ b/packages/jest-phabricator/src/index.ts @@ -5,22 +5,20 @@ * LICENSE file in the root directory of this source tree. */ -import { - AggregatedResult, - AggregatedResultWithoutCoverage, - CoverageMap, -} from '@jest/types'; - -type PhabricatorReport = AggregatedResultWithoutCoverage & { - coverageMap?: CoverageMap | null; +import {TestResult} from '@jest/types'; + +type PhabricatorReport = TestResult.AggregatedResultWithoutCoverage & { + coverageMap?: TestResult.CoverageMap | null; }; -function summarize(coverageMap: CoverageMap) { +function summarize(coverageMap: TestResult.CoverageMap) { const summaries = Object.create(null); coverageMap.files().forEach((file: string) => { const covered = []; - const lineCoverage = coverageMap.fileCoverageFor(file).getLineCoverage(); + const lineCoverage: any = coverageMap + .fileCoverageFor(file) + .getLineCoverage(); Object.keys(lineCoverage).forEach(lineNumber => { // Line numbers start at one @@ -40,7 +38,9 @@ function summarize(coverageMap: CoverageMap) { return summaries; } -module.exports = function(results: AggregatedResult): PhabricatorReport { +module.exports = function( + results: TestResult.AggregatedResult, +): PhabricatorReport { return { ...results, coverageMap: results.coverageMap && summarize(results.coverageMap), From c22e5d0e6f222b9c01441c1145e730c971a95ca0 Mon Sep 17 00:00:00 2001 From: Simen Bekkhus Date: Sat, 23 Feb 2019 15:07:55 +0100 Subject: [PATCH 3/4] avoid `any` --- packages/jest-phabricator/src/index.ts | 10 ++-------- packages/jest-types/src/TestResult.ts | 6 +++--- 2 files changed, 5 insertions(+), 11 deletions(-) diff --git a/packages/jest-phabricator/src/index.ts b/packages/jest-phabricator/src/index.ts index 69f9cb85f834..72955d2eed3e 100644 --- a/packages/jest-phabricator/src/index.ts +++ b/packages/jest-phabricator/src/index.ts @@ -7,18 +7,12 @@ import {TestResult} from '@jest/types'; -type PhabricatorReport = TestResult.AggregatedResultWithoutCoverage & { - coverageMap?: TestResult.CoverageMap | null; -}; - function summarize(coverageMap: TestResult.CoverageMap) { const summaries = Object.create(null); coverageMap.files().forEach((file: string) => { const covered = []; - const lineCoverage: any = coverageMap - .fileCoverageFor(file) - .getLineCoverage(); + const lineCoverage = coverageMap.fileCoverageFor(file).getLineCoverage(); Object.keys(lineCoverage).forEach(lineNumber => { // Line numbers start at one @@ -40,7 +34,7 @@ function summarize(coverageMap: TestResult.CoverageMap) { module.exports = function( results: TestResult.AggregatedResult, -): PhabricatorReport { +): TestResult.AggregatedResult { return { ...results, coverageMap: results.coverageMap && summarize(results.coverageMap), diff --git a/packages/jest-types/src/TestResult.ts b/packages/jest-types/src/TestResult.ts index 841064692ff1..857751e6a9f0 100644 --- a/packages/jest-types/src/TestResult.ts +++ b/packages/jest-types/src/TestResult.ts @@ -52,10 +52,10 @@ export type CoverageSummary = { }; export type FileCoverage = { - getLineCoverage: () => Object; + getLineCoverage: () => {[line: string]: string}; getUncoveredLines: () => Array; - getBranchCoverageByLine: () => Object; - toJSON: () => Object; + getBranchCoverageByLine: () => {[line: string]: string}; + toJSON: () => {[line: string]: string}; merge: (other: Object) => undefined; computeSimpleTotals: (property: string) => FileCoverageTotal; computeBranchTotals: () => FileCoverageTotal; From d0b091a73ae62459af030dea20b8b979ac2677c8 Mon Sep 17 00:00:00 2001 From: Simen Bekkhus Date: Sat, 23 Feb 2019 15:24:04 +0100 Subject: [PATCH 4/4] remove unnecessary type annotation --- packages/jest-phabricator/src/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/jest-phabricator/src/index.ts b/packages/jest-phabricator/src/index.ts index 72955d2eed3e..0c1faa1cac99 100644 --- a/packages/jest-phabricator/src/index.ts +++ b/packages/jest-phabricator/src/index.ts @@ -10,7 +10,7 @@ import {TestResult} from '@jest/types'; function summarize(coverageMap: TestResult.CoverageMap) { const summaries = Object.create(null); - coverageMap.files().forEach((file: string) => { + coverageMap.files().forEach(file => { const covered = []; const lineCoverage = coverageMap.fileCoverageFor(file).getLineCoverage();