Skip to content

Commit 02aa43c

Browse files
committed
chore: migrate jest-util to TypeScript
1 parent dc35500 commit 02aa43c

Some content is hidden

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

45 files changed

+889
-690
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
- `[jest-serializer]`: Migrate to TypeScript ([#7841](https://github.com/facebook/jest/pull/7841))
2222
- `[jest-message-util]`: Migrate to TypeScript ([#7834](https://github.com/facebook/jest/pull/7834))
2323
- `[@jest/types]`: New package to handle shared types ([#7834](https://github.com/facebook/jest/pull/7834))
24+
- `[jest-util]`: Migrate to TypeScript ([#7844](https://github.com/facebook/jest/pull/7844))
2425

2526
### Performance
2627

packages/jest-circus/src/index.js

+1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import type {
1818
TestMode,
1919
} from 'types/Circus';
2020
import {bind as bindEach} from 'jest-each';
21+
// $FlowFixMe: Converted to TS
2122
import {ErrorWithStack} from 'jest-util';
2223
import {dispatch} from './state';
2324

packages/jest-circus/src/utils.js

+1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import type {
2222
TestName,
2323
TestResults,
2424
} from 'types/Circus';
25+
// $FlowFixMe: Converted to TS
2526
import {convertDescriptorToString} from 'jest-util';
2627
import isGeneratorFn from 'is-generator-fn';
2728
import co from 'co';

packages/jest-message-util/src/index.ts

+5-6
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ import slash from 'slash';
1414
import {codeFrameColumns} from '@babel/code-frame';
1515
import StackUtils from 'stack-utils';
1616

17-
type Glob = Config.Glob;
1817
type Path = Config.Path;
1918
type AssertionResult = TestResult.AssertionResult;
2019
type SerializableError = TestResult.SerializableError;
@@ -33,12 +32,12 @@ try {
3332
// node internals in the browser though, so no issue.
3433
}
3534

36-
type StackTraceConfig = {
37-
rootDir: string;
38-
testMatch: Array<Glob>;
39-
};
35+
export type StackTraceConfig = Pick<
36+
Config.ProjectConfig,
37+
'rootDir' | 'testMatch'
38+
>;
4039

41-
type StackTraceOptions = {
40+
export type StackTraceOptions = {
4241
noStackTrace: boolean;
4342
};
4443

packages/jest-runner/src/runTest.js

-2
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ function freezeConsole(
3939
testConsole: BufferedConsole | Console | NullConsole,
4040
config: ProjectConfig,
4141
) {
42-
// $FlowFixMe: overwrite it for pretty errors
4342
testConsole._log = function fakeConsolePush(_type, message) {
4443
const error = new ErrorWithStack(
4544
`${chalk.red(
@@ -89,7 +88,6 @@ async function runTestInternal(
8988
if (customEnvironment) {
9089
testEnvironment = getTestEnvironment({
9190
...config,
92-
// $FlowFixMe
9391
testEnvironment: customEnvironment,
9492
});
9593
}

packages/jest-util/src/setGlobal.js renamed to packages/jest-types/src/SourceMaps.ts

+1-6
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,6 @@
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 {Global} from 'types/Global';
11-
12-
export default (global: Global, key: string, value: any) =>
13-
(global[key] = value);
8+
export type SourceMapRegistry = {[key: string]: string};

packages/jest-types/src/TestResult.ts

+5-4
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ export type AssertionResult = {
123123
};
124124

125125
export type FormattedAssertionResult = {
126+
ancestorTitles: Array<string>;
126127
failureMessages: Array<string> | null;
127128
fullName: string;
128129
location: Callsite | null | undefined;
@@ -150,7 +151,7 @@ export type AggregatedResultWithoutCoverage = {
150151
};
151152

152153
export type AggregatedResult = AggregatedResultWithoutCoverage & {
153-
coverageMap?: CoverageMap | null | undefined;
154+
coverageMap?: CoverageMap | null;
154155
};
155156

156157
export type Suite = {
@@ -160,10 +161,10 @@ export type Suite = {
160161
};
161162

162163
export type TestResult = {
163-
console: ConsoleBuffer | null | undefined;
164+
console?: ConsoleBuffer | null;
164165
coverage?: RawCoverage;
165-
displayName: string | null | undefined;
166-
failureMessage: string | null | undefined;
166+
displayName?: string | null;
167+
failureMessage?: string | null;
167168
leaks: boolean;
168169
memoryUsage?: Bytes;
169170
numFailingTests: number;

packages/jest-types/src/index.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
import * as Config from './Config';
99
import * as Console from './Console';
10+
import * as SourceMaps from './SourceMaps';
1011
import * as TestResult from './TestResult';
1112

12-
export {Config, Console, TestResult};
13+
export {Config, Console, SourceMaps, TestResult};

packages/jest-util/package.json

+6-2
Original file line numberDiff line numberDiff line change
@@ -9,21 +9,25 @@
99
"license": "MIT",
1010
"main": "build/index.js",
1111
"dependencies": {
12+
"@jest/types": "^24.1.0",
13+
"@types/node": "*",
1214
"callsites": "^3.0.0",
1315
"chalk": "^2.0.1",
1416
"graceful-fs": "^4.1.15",
1517
"is-ci": "^2.0.0",
1618
"jest-message-util": "^24.0.0",
19+
"jest-mock": "^24.0.0",
1720
"mkdirp": "^0.5.1",
21+
"readable-stream": "^3.1.1",
1822
"slash": "^2.0.0",
1923
"source-map": "^0.6.0"
2024
},
2125
"devDependencies": {
22-
"@types/callsites": "^2.0.0",
2326
"@types/graceful-fs": "^4.1.2",
2427
"@types/is-ci": "^1.0.10",
2528
"@types/mkdirp": "^0.5.2",
26-
"jest-mock": "^24.0.0"
29+
"@types/readable-stream": "^2.3.0",
30+
"@types/slash": "^2.0.0"
2731
},
2832
"engines": {
2933
"node": ">= 6"

packages/jest-util/src/BufferedConsole.js

-167
This file was deleted.

0 commit comments

Comments
 (0)