Skip to content

Commit 70bed72

Browse files
authored
chore: migrate @jest/core to TypeScript (#7998)
1 parent 160d27a commit 70bed72

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

65 files changed

+1006
-857
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@
7777
- `[jest-repl]`: Migrate to TypeScript ([#8000](https://github.com/facebook/jest/pull/8000))
7878
- `[jest-validate]`: Migrate to TypeScript ([#7991](https://github.com/facebook/jest/pull/7991))
7979
- `[docs]`: Update CONTRIBUTING.md to add information about running jest with `jest-circus` locally ([#8013](https://github.com/facebook/jest/pull/8013)).
80+
- `[@jest/core]`: Migrate to TypeScript ([#7998](https://github.com/facebook/jest/pull/7998))
8081

8182
### Performance
8283

packages/jest-changed-files/src/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ import hg from './hg';
1515

1616
type RootPromise = ReturnType<SCMAdapter['getRoot']>;
1717

18+
export {ChangedFiles, ChangedFilesPromise} from './types';
19+
1820
function notEmpty<T>(value: T | null | undefined): value is T {
1921
return value != null;
2022
}

packages/jest-changed-files/src/types.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,10 @@ export type Options = {
1414
includePaths?: Array<Config.Path>;
1515
};
1616

17-
type ChangedFiles = Set<Config.Path>;
18-
export type Repos = {git: ChangedFiles; hg: ChangedFiles};
19-
export type ChangedFilesPromise = Promise<{
20-
repos: Repos;
21-
changedFiles: ChangedFiles;
22-
}>;
17+
type Paths = Set<Config.Path>;
18+
export type Repos = {git: Paths; hg: Paths};
19+
export type ChangedFiles = {repos: Repos; changedFiles: Paths};
20+
export type ChangedFilesPromise = Promise<ChangedFiles>;
2321

2422
export type SCMAdapter = {
2523
findChangedFiles: (

packages/jest-core/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
"version": "24.1.0",
55
"main": "build/jest.js",
66
"dependencies": {
7+
"@jest/types": "^24.1.0",
78
"@jest/reporters": "^24.1.0",
89
"@jest/transform": "^24.1.0",
910
"ansi-escapes": "^3.0.0",
@@ -24,7 +25,7 @@
2425
"jest-watcher": "^24.0.0",
2526
"micromatch": "^3.1.10",
2627
"p-each-series": "^1.0.0",
27-
"pirates": "^4.0.0",
28+
"pirates": "^4.0.1",
2829
"realpath-native": "^1.1.0",
2930
"rimraf": "^2.5.4",
3031
"strip-ansi": "^5.0.0"

packages/jest-core/src/FailedTestsCache.js renamed to packages/jest-core/src/FailedTestsCache.ts

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,45 +3,49 @@
33
*
44
* This source code is licensed under the MIT license found in the
55
* LICENSE file in the root directory of this source tree.
6-
*
7-
* @flow
86
*/
97

10-
import type {Test} from 'types/TestRunner';
11-
import type {TestResult} from 'types/TestResult';
12-
import type {GlobalConfig} from 'types/Config';
8+
import {Test} from 'jest-runner';
9+
import {Config, TestResult} from '@jest/types';
10+
11+
type TestMap = {[key: string]: {[key: string]: boolean}};
1312

1413
export default class FailedTestsCache {
15-
_enabledTestsMap: ?{[key: string]: {[key: string]: boolean}};
14+
private _enabledTestsMap?: TestMap;
1615

1716
filterTests(tests: Array<Test>): Array<Test> {
18-
if (!this._enabledTestsMap) {
17+
const enabledTestsMap = this._enabledTestsMap;
18+
19+
if (!enabledTestsMap) {
1920
return tests;
2021
}
21-
// $FlowFixMe
22-
return tests.filter(testResult => this._enabledTestsMap[testResult.path]);
22+
return tests.filter(testResult => enabledTestsMap[testResult.path]);
2323
}
2424

25-
setTestResults(testResults: Array<TestResult>) {
25+
setTestResults(testResults: Array<TestResult.TestResult>) {
2626
this._enabledTestsMap = (testResults || [])
2727
.filter(testResult => testResult.numFailingTests)
28-
.reduce((suiteMap, testResult) => {
28+
.reduce<TestMap>((suiteMap, testResult) => {
2929
suiteMap[testResult.testFilePath] = testResult.testResults
3030
.filter(test => test.status === 'failed')
31-
.reduce((testMap, test) => {
32-
testMap[test.fullName] = true;
33-
return testMap;
34-
}, {});
31+
.reduce(
32+
(testMap, test) => {
33+
testMap[test.fullName] = true;
34+
return testMap;
35+
},
36+
{} as {[name: string]: true},
37+
);
3538
return suiteMap;
3639
}, {});
40+
3741
this._enabledTestsMap = Object.freeze(this._enabledTestsMap);
3842
}
3943

40-
updateConfig(globalConfig: GlobalConfig): GlobalConfig {
44+
updateConfig(globalConfig: Config.GlobalConfig): Config.GlobalConfig {
4145
if (!this._enabledTestsMap) {
4246
return globalConfig;
4347
}
44-
const newConfig: GlobalConfig = {...globalConfig};
48+
const newConfig: Config.GlobalConfig = {...globalConfig};
4549
newConfig.enabledTestsMap = this._enabledTestsMap;
4650
return Object.freeze(newConfig);
4751
}

packages/jest-core/src/ReporterDispatcher.js renamed to packages/jest-core/src/ReporterDispatcher.ts

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,15 @@
33
*
44
* This source code is licensed under the MIT license found in the
55
* LICENSE file in the root directory of this source tree.
6-
*
7-
* @flow
86
*/
97

10-
import type {Context} from 'types/Context';
11-
import type {Reporter, Test} from 'types/TestRunner';
12-
import type {TestResult, AggregatedResult} from 'types/TestResult';
13-
import type {ReporterOnStartOptions} from 'types/Reporters';
14-
15-
export type RunOptions = {|
16-
estimatedTime: number,
17-
showStatus: boolean,
18-
|};
8+
import {TestResult} from '@jest/types';
9+
import {Test} from 'jest-runner';
10+
import {Context} from 'jest-runtime';
11+
import {Reporter, ReporterOnStartOptions} from './types';
1912

2013
export default class ReporterDispatcher {
21-
_disabled: boolean;
22-
_reporters: Array<Reporter>;
14+
private _reporters: Array<Reporter>;
2315

2416
constructor() {
2517
this._reporters = [];
@@ -37,8 +29,8 @@ export default class ReporterDispatcher {
3729

3830
async onTestResult(
3931
test: Test,
40-
testResult: TestResult,
41-
results: AggregatedResult,
32+
testResult: TestResult.TestResult,
33+
results: TestResult.AggregatedResult,
4234
) {
4335
for (const reporter of this._reporters) {
4436
reporter.onTestResult &&
@@ -52,13 +44,19 @@ export default class ReporterDispatcher {
5244
}
5345
}
5446

55-
async onRunStart(results: AggregatedResult, options: ReporterOnStartOptions) {
47+
async onRunStart(
48+
results: TestResult.AggregatedResult,
49+
options: ReporterOnStartOptions,
50+
) {
5651
for (const reporter of this._reporters) {
5752
reporter.onRunStart && (await reporter.onRunStart(results, options));
5853
}
5954
}
6055

61-
async onRunComplete(contexts: Set<Context>, results: AggregatedResult) {
56+
async onRunComplete(
57+
contexts: Set<Context>,
58+
results: TestResult.AggregatedResult,
59+
) {
6260
for (const reporter of this._reporters) {
6361
reporter.onRunComplete &&
6462
(await reporter.onRunComplete(contexts, results));
@@ -67,7 +65,7 @@ export default class ReporterDispatcher {
6765

6866
// Return a list of last errors for every reporter
6967
getErrors(): Array<Error> {
70-
return this._reporters.reduce((list, reporter) => {
68+
return this._reporters.reduce<Array<Error>>((list, reporter) => {
7169
const error = reporter.getLastError && reporter.getLastError();
7270
return error ? list.concat(error) : list;
7371
}, []);

0 commit comments

Comments
 (0)