Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: migrate @jest/core to TypeScript #7998

Merged
merged 30 commits into from
Mar 2, 2019
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
7bbf001
chore: migrate @jest/core to TypeScript
SimenB Feb 27, 2019
2cf4192
fix some errors
SimenB Feb 27, 2019
7b38a4a
link to PR
SimenB Feb 27, 2019
e48cd88
fix a couple more type errors
SimenB Feb 27, 2019
ec55efa
rollback patpern prompt changes for easier review
SimenB Feb 27, 2019
f15468c
fix patternprompt onchange argument types
SimenB Feb 27, 2019
0dda5d9
correct stream type
SimenB Feb 27, 2019
0f12413
play around with some tests
SimenB Feb 27, 2019
6110e0b
fix test
SimenB Feb 27, 2019
75a28e6
Merge branch 'master' into ts-jest-core
SimenB Feb 28, 2019
deaaf39
fix final errors
SimenB Feb 28, 2019
b1fb018
Merge branch 'master' into ts-jest-core
SimenB Feb 28, 2019
b787db0
fix type import of async_hooks
SimenB Feb 28, 2019
5345e40
Merge branch 'master' into ts-jest-core
SimenB Mar 1, 2019
3d60689
add jest-validate reference
SimenB Mar 1, 2019
9153220
lint
SimenB Mar 1, 2019
985c189
Merge branch 'master' into ts-jest-core
SimenB Mar 1, 2019
366b04b
missing comma :/
SimenB Mar 1, 2019
8a24f0e
prettify snapshot an revert potentially breaking change
SimenB Mar 2, 2019
0d34ddd
Apply suggestions from code review
jeysal Mar 2, 2019
a0db1a4
remove passWithNoTests from options allowed to be set in watch mode
SimenB Mar 2, 2019
ffc449a
cleanup filter hit stats counter
SimenB Mar 2, 2019
3d424f8
less optional args
SimenB Mar 2, 2019
e90ea19
private test scheduler
SimenB Mar 2, 2019
b2437c4
avoid Object type
SimenB Mar 2, 2019
ac82194
functions should return void, not any
SimenB Mar 2, 2019
aea4808
clarify ignore comment
SimenB Mar 2, 2019
34edc50
remove dead code
SimenB Mar 2, 2019
ddf52ee
less dumb test
SimenB Mar 2, 2019
b149594
WatchPluginClass
jeysal Mar 2, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,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/core]`: Migrate to TypeScript ([#7998](https://github.com/facebook/jest/pull/7998))

### Performance

Expand Down
1 change: 1 addition & 0 deletions docs/WatchPlugins.md
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ For stability and safety reasons, only part of the global configuration keys can
- [`notify`](configuration.html#notify-boolean)
- [`notifyMode`](configuration.html#notifymode-string)
- [`onlyFailures`](configuration.html#onlyfailures-boolean)
- [`passWithNoTests`](cli.html#passwithnotests)
SimenB marked this conversation as resolved.
Show resolved Hide resolved
- [`reporters`](configuration.html#reporters-array-modulename-modulename-options)
- [`testNamePattern`](cli.html#testnamepattern-regex)
- [`testPathPattern`](cli.html#testpathpattern-regex)
Expand Down
2 changes: 2 additions & 0 deletions packages/jest-changed-files/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ import hg from './hg';

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

export {ChangedFiles, ChangedFilesPromise} from './types';

function notEmpty<T>(value: T | null | undefined): value is T {
return value != null;
}
Expand Down
10 changes: 4 additions & 6 deletions packages/jest-changed-files/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,10 @@ export type Options = {
includePaths?: Array<Config.Path>;
};

type ChangedFiles = Set<Config.Path>;
export type Repos = {git: ChangedFiles; hg: ChangedFiles};
export type ChangedFilesPromise = Promise<{
repos: Repos;
changedFiles: ChangedFiles;
}>;
type Paths = Set<Config.Path>;
export type Repos = {git: Paths; hg: Paths};
export type ChangedFiles = {repos: Repos; changedFiles: Paths};
export type ChangedFilesPromise = Promise<ChangedFiles>;

export type SCMAdapter = {
findChangedFiles: (
Expand Down
3 changes: 2 additions & 1 deletion packages/jest-core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"version": "24.1.0",
"main": "build/jest.js",
"dependencies": {
"@jest/types": "^24.1.0",
"@jest/reporters": "^24.1.0",
"@jest/transform": "^24.1.0",
"ansi-escapes": "^3.0.0",
Expand All @@ -24,7 +25,7 @@
"jest-watcher": "^24.0.0",
"micromatch": "^3.1.10",
"p-each-series": "^1.0.0",
"pirates": "^4.0.0",
"pirates": "^4.0.1",
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

4.0.1 has typings

"realpath-native": "^1.1.0",
"rimraf": "^2.5.4",
"strip-ansi": "^5.0.0"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,45 +3,49 @@
*
* 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 {Test} from 'types/TestRunner';
import type {TestResult} from 'types/TestResult';
import type {GlobalConfig} from 'types/Config';
import {Test} from 'jest-runner';
import {Config, TestResult} from '@jest/types';

type TestMap = {[key: string]: {[key: string]: boolean}};

export default class FailedTestsCache {
_enabledTestsMap: ?{[key: string]: {[key: string]: boolean}};
private _enabledTestsMap?: TestMap;

filterTests(tests: Array<Test>): Array<Test> {
if (!this._enabledTestsMap) {
const enabledTestsMap = this._enabledTestsMap;

if (!enabledTestsMap) {
return tests;
}
// $FlowFixMe
return tests.filter(testResult => this._enabledTestsMap[testResult.path]);
return tests.filter(testResult => enabledTestsMap[testResult.path]);
}

setTestResults(testResults: Array<TestResult>) {
setTestResults(testResults: Array<TestResult.TestResult>) {
this._enabledTestsMap = (testResults || [])
.filter(testResult => testResult.numFailingTests)
.reduce((suiteMap, testResult) => {
.reduce<TestMap>((suiteMap, testResult) => {
suiteMap[testResult.testFilePath] = testResult.testResults
.filter(test => test.status === 'failed')
.reduce((testMap, test) => {
testMap[test.fullName] = true;
return testMap;
}, {});
.reduce(
(testMap, test) => {
testMap[test.fullName] = true;
return testMap;
},
{} as {[name: string]: true},
);
return suiteMap;
}, {});

this._enabledTestsMap = Object.freeze(this._enabledTestsMap);
}

updateConfig(globalConfig: GlobalConfig): GlobalConfig {
updateConfig(globalConfig: Config.GlobalConfig): Config.GlobalConfig {
if (!this._enabledTestsMap) {
return globalConfig;
}
const newConfig: GlobalConfig = {...globalConfig};
const newConfig: Config.GlobalConfig = {...globalConfig};
newConfig.enabledTestsMap = this._enabledTestsMap;
return Object.freeze(newConfig);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,15 @@
*
* 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 {Context} from 'types/Context';
import type {Reporter, Test} from 'types/TestRunner';
import type {TestResult, AggregatedResult} from 'types/TestResult';
import type {ReporterOnStartOptions} from 'types/Reporters';

export type RunOptions = {|
estimatedTime: number,
showStatus: boolean,
|};
import {TestResult} from '@jest/types';
import {Test} from 'jest-runner';
import {Context} from 'jest-runtime';
import {Reporter, ReporterOnStartOptions} from './types';

export default class ReporterDispatcher {
_disabled: boolean;
_reporters: Array<Reporter>;
private _reporters: Array<Reporter>;

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

async onTestResult(
test: Test,
testResult: TestResult,
results: AggregatedResult,
testResult: TestResult.TestResult,
results: TestResult.AggregatedResult,
) {
for (const reporter of this._reporters) {
reporter.onTestResult &&
Expand All @@ -52,13 +44,19 @@ export default class ReporterDispatcher {
}
}

async onRunStart(results: AggregatedResult, options: ReporterOnStartOptions) {
async onRunStart(
results: TestResult.AggregatedResult,
options: ReporterOnStartOptions,
) {
for (const reporter of this._reporters) {
reporter.onRunStart && (await reporter.onRunStart(results, options));
}
}

async onRunComplete(contexts: Set<Context>, results: AggregatedResult) {
async onRunComplete(
contexts: Set<Context>,
results: TestResult.AggregatedResult,
) {
for (const reporter of this._reporters) {
reporter.onRunComplete &&
(await reporter.onRunComplete(contexts, results));
Expand All @@ -67,7 +65,7 @@ export default class ReporterDispatcher {

// Return a list of last errors for every reporter
getErrors(): Array<Error> {
return this._reporters.reduce((list, reporter) => {
return this._reporters.reduce<Array<Error>>((list, reporter) => {
const error = reporter.getLastError && reporter.getLastError();
return error ? list.concat(error) : list;
}, []);
Expand Down
Loading