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-cli to TypeScript #8024

Merged
merged 15 commits into from Mar 5, 2019
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -83,6 +83,7 @@
- `[@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))

### Performance

Expand Down
1 change: 1 addition & 0 deletions e2e/__tests__/__snapshots__/showConfig.test.ts.snap
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
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
@@ -0,0 +1,6 @@
{
"name": "run-programmatically",
"version": "1.0.0",
"dependencies": {},
"jest": {}
}
2 changes: 2 additions & 0 deletions packages/jest-cli/package.json
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
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