Skip to content

Commit

Permalink
chore: migrate jest-cli to TypeScript (#8024)
Browse files Browse the repository at this point in the history
  • Loading branch information
SimenB authored Mar 5, 2019
1 parent c15b7a5 commit 9fa3268
Show file tree
Hide file tree
Showing 34 changed files with 350 additions and 302 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@
- `[@jest/source-map]`: Extract `getCallsite` function from `jest-util` into a new separate package ([#8029](https://github.com/facebook/jest/pull/8029))
- `[@jest/console]`: Extract custom `console` implementations from `jest-util` into a new separate package ([#8030](https://github.com/facebook/jest/pull/8030))
- `[docs]`: Improve runAllTimers doc (it exhausts the micro-task queue) ([#8031](https://github.com/facebook/jest/pull/8031))
- `[jest-cli]`: Migrate to TypeScript ([#8024](https://github.com/facebook/jest/pull/8024))
- `[jest]`: Migrate to TypeScript ([#8024](https://github.com/facebook/jest/pull/8024))

### Performance

Expand Down
1 change: 1 addition & 0 deletions e2e/__tests__/__snapshots__/showConfig.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ exports[`--showConfig outputs config info and exits 1`] = `
"filter": null,
"globalSetup": null,
"globalTeardown": null,
"json": false,
"listTests": false,
"maxConcurrency": 5,
"maxWorkers": "[maxWorkers]",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {resolve} from 'path';

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

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

test('run Jest programatically', () => {
const {stdout} = run(`node index.js --version`, dir);
Expand Down
File renamed without changes.
6 changes: 6 additions & 0 deletions e2e/run-programmatically/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"name": "run-programmatically",
"version": "1.0.0",
"dependencies": {},
"jest": {}
}
2 changes: 2 additions & 0 deletions packages/jest-cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
"description": "Delightful JavaScript Testing.",
"version": "24.1.0",
"main": "build/index.js",
"types": "build/index.d.ts",
"dependencies": {
"@jest/core": "^24.1.0",
"@jest/types": "^24.1.0",
"chalk": "^2.0.1",
"exit": "^0.1.2",
"import-local": "^2.0.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,55 +6,56 @@
*
*/

'use strict';

import type {Argv} from 'types/Argv';
import {Config} from '@jest/types';
import {check} from '../../cli/args';
import {buildArgv} from '../../cli';

describe('check', () => {
it('returns true if the arguments are valid', () => {
const argv: Argv = {};
const argv = {} as Config.Argv;
expect(check(argv)).toBe(true);
});

it('raises an exception if runInBand and maxWorkers are both specified', () => {
const argv: Argv = {maxWorkers: 2, runInBand: true};
const argv = {maxWorkers: 2, runInBand: true} as Config.Argv;
expect(() => check(argv)).toThrow(
'Both --runInBand and --maxWorkers were specified',
);
});

it('raises an exception if onlyChanged and watchAll are both specified', () => {
const argv: Argv = {onlyChanged: true, watchAll: true};
const argv = {onlyChanged: true, watchAll: true} as Config.Argv;
expect(() => check(argv)).toThrow(
'Both --onlyChanged and --watchAll were specified',
);
});

it('raises an exception when lastCommit and watchAll are both specified', () => {
const argv: Argv = {lastCommit: true, watchAll: true};
const argv = {lastCommit: true, watchAll: true} as Config.Argv;
expect(() => check(argv)).toThrow(
'Both --lastCommit and --watchAll were specified',
);
});

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

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

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

describe('buildArgv', () => {
it('should return only camelcased args ', () => {
// @ts-ignore
const mockProcessArgv = jest
.spyOn(process.argv, 'slice')
.mockImplementation(() => ['--clear-mocks']);
// @ts-ignore
const actual = buildArgv(null);
expect(actual).not.toHaveProperty('clear-mocks');
expect(actual).toHaveProperty('clearMocks', true);
Expand Down
Loading

0 comments on commit 9fa3268

Please sign in to comment.