Skip to content

Commit 9fa3268

Browse files
authored
chore: migrate jest-cli to TypeScript (#8024)
1 parent c15b7a5 commit 9fa3268

34 files changed

+350
-302
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,8 @@
8484
- `[@jest/source-map]`: Extract `getCallsite` function from `jest-util` into a new separate package ([#8029](https://github.com/facebook/jest/pull/8029))
8585
- `[@jest/console]`: Extract custom `console` implementations from `jest-util` into a new separate package ([#8030](https://github.com/facebook/jest/pull/8030))
8686
- `[docs]`: Improve runAllTimers doc (it exhausts the micro-task queue) ([#8031](https://github.com/facebook/jest/pull/8031))
87+
- `[jest-cli]`: Migrate to TypeScript ([#8024](https://github.com/facebook/jest/pull/8024))
88+
- `[jest]`: Migrate to TypeScript ([#8024](https://github.com/facebook/jest/pull/8024))
8789

8890
### Performance
8991

e2e/__tests__/__snapshots__/showConfig.test.ts.snap

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ exports[`--showConfig outputs config info and exits 1`] = `
100100
"filter": null,
101101
"globalSetup": null,
102102
"globalTeardown": null,
103+
"json": false,
103104
"listTests": false,
104105
"maxConcurrency": 5,
105106
"maxWorkers": "[maxWorkers]",

e2e/__tests__/runProgramatically.test.ts renamed to e2e/__tests__/runProgrammatically.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import {resolve} from 'path';
99

1010
import {run} from '../Utils';
1111

12-
const dir = resolve(__dirname, '..', 'run-programatically');
12+
const dir = resolve(__dirname, '..', 'run-programmatically');
1313

1414
test('run Jest programatically', () => {
1515
const {stdout} = run(`node index.js --version`, dir);
File renamed without changes.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"name": "run-programmatically",
3+
"version": "1.0.0",
4+
"dependencies": {},
5+
"jest": {}
6+
}

packages/jest-cli/package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,10 @@
33
"description": "Delightful JavaScript Testing.",
44
"version": "24.1.0",
55
"main": "build/index.js",
6+
"types": "build/index.d.ts",
67
"dependencies": {
78
"@jest/core": "^24.1.0",
9+
"@jest/types": "^24.1.0",
810
"chalk": "^2.0.1",
911
"exit": "^0.1.2",
1012
"import-local": "^2.0.0",

packages/jest-cli/src/__tests__/cli/args.test.js renamed to packages/jest-cli/src/__tests__/cli/args.test.ts

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,55 +6,56 @@
66
*
77
*/
88

9-
'use strict';
10-
11-
import type {Argv} from 'types/Argv';
9+
import {Config} from '@jest/types';
1210
import {check} from '../../cli/args';
1311
import {buildArgv} from '../../cli';
1412

1513
describe('check', () => {
1614
it('returns true if the arguments are valid', () => {
17-
const argv: Argv = {};
15+
const argv = {} as Config.Argv;
1816
expect(check(argv)).toBe(true);
1917
});
2018

2119
it('raises an exception if runInBand and maxWorkers are both specified', () => {
22-
const argv: Argv = {maxWorkers: 2, runInBand: true};
20+
const argv = {maxWorkers: 2, runInBand: true} as Config.Argv;
2321
expect(() => check(argv)).toThrow(
2422
'Both --runInBand and --maxWorkers were specified',
2523
);
2624
});
2725

2826
it('raises an exception if onlyChanged and watchAll are both specified', () => {
29-
const argv: Argv = {onlyChanged: true, watchAll: true};
27+
const argv = {onlyChanged: true, watchAll: true} as Config.Argv;
3028
expect(() => check(argv)).toThrow(
3129
'Both --onlyChanged and --watchAll were specified',
3230
);
3331
});
3432

3533
it('raises an exception when lastCommit and watchAll are both specified', () => {
36-
const argv: Argv = {lastCommit: true, watchAll: true};
34+
const argv = {lastCommit: true, watchAll: true} as Config.Argv;
3735
expect(() => check(argv)).toThrow(
3836
'Both --lastCommit and --watchAll were specified',
3937
);
4038
});
4139

4240
it('raises an exception if findRelatedTests is specified with no file paths', () => {
43-
const argv: Argv = {_: [], findRelatedTests: true};
41+
const argv = {
42+
_: [] as Array<string>,
43+
findRelatedTests: true,
44+
} as Config.Argv;
4445
expect(() => check(argv)).toThrow(
4546
'The --findRelatedTests option requires file paths to be specified',
4647
);
4748
});
4849

4950
it('raises an exception if maxWorkers is specified with no number', () => {
50-
const argv: Argv = {maxWorkers: undefined};
51+
const argv = ({maxWorkers: undefined} as unknown) as Config.Argv;
5152
expect(() => check(argv)).toThrow(
5253
'The --maxWorkers (-w) option requires a number to be specified',
5354
);
5455
});
5556

5657
it('raises an exception if config is not a valid JSON string', () => {
57-
const argv: Argv = {config: 'x:1'};
58+
const argv = {config: 'x:1'} as Config.Argv;
5859
expect(() => check(argv)).toThrow(
5960
'The --config option requires a JSON string literal, or a file path with a .js or .json extension',
6061
);
@@ -63,9 +64,11 @@ describe('check', () => {
6364

6465
describe('buildArgv', () => {
6566
it('should return only camelcased args ', () => {
67+
// @ts-ignore
6668
const mockProcessArgv = jest
6769
.spyOn(process.argv, 'slice')
6870
.mockImplementation(() => ['--clear-mocks']);
71+
// @ts-ignore
6972
const actual = buildArgv(null);
7073
expect(actual).not.toHaveProperty('clear-mocks');
7174
expect(actual).toHaveProperty('clearMocks', true);

0 commit comments

Comments
 (0)