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

Allow the cli to use a string for --maxWorkers #8565

Merged
merged 6 commits into from Jun 24, 2019
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -10,6 +10,7 @@

### Fixes

- `[jest-cli]` fix --maxWorkers work again with % input ([#8559](https://github.com/facebook/jest/pull/8565))
philiiiiiipp marked this conversation as resolved.
Show resolved Hide resolved
- `[babel-plugin-jest-hoist]` Expand list of whitelisted globals in global mocks ([#8429](https://github.com/facebook/jest/pull/8429)
- `[jest-core]` Make watch plugin initialization errors look nice ([#8422](https://github.com/facebook/jest/pull/8422))
- `[jest-snapshot]` Prevent inline snapshots from drifting when inline snapshots are updated ([#8492](https://github.com/facebook/jest/pull/8492))
Expand Down
7 changes: 6 additions & 1 deletion packages/jest-cli/src/__tests__/cli/args.test.ts
Expand Up @@ -50,10 +50,15 @@ describe('check', () => {
it('raises an exception if maxWorkers is specified with no number', () => {
const argv = ({maxWorkers: undefined} as unknown) as Config.Argv;
expect(() => check(argv)).toThrow(
'The --maxWorkers (-w) option requires a number to be specified',
'The --maxWorkers (-w) option requires a number or string to be specified',
);
});

it('allows maxWorkers to be a %', () => {
const argv = ({maxWorkers: '50%'} as unknown) as Config.Argv;
expect(() => check(argv)).not.toThrow();
});

it('raises an exception if config is not a valid JSON string', () => {
const argv = {config: 'x:1'} as Config.Argv;
expect(() => check(argv)).toThrow(
Expand Down
5 changes: 3 additions & 2 deletions packages/jest-cli/src/cli/args.ts
Expand Up @@ -42,8 +42,9 @@ export const check = (argv: Config.Argv) => {

if (argv.hasOwnProperty('maxWorkers') && argv.maxWorkers === undefined) {
throw new Error(
'The --maxWorkers (-w) option requires a number to be specified.\n' +
'The --maxWorkers (-w) option requires a number or string to be specified.\n' +
'Example usage: jest --maxWorkers 2\n' +
'Example usage: jest --maxWorkers 50%\n' +
'Or did you mean --watch?',
);
}
Expand Down Expand Up @@ -349,7 +350,7 @@ export const options = {
'will spawn for running tests. This defaults to the number of the ' +
philiiiiiipp marked this conversation as resolved.
Show resolved Hide resolved
'cores available on your machine. (its usually best not to override ' +
'this default)',
type: 'number' as 'number',
type: 'string' as 'string',
},
moduleDirectories: {
description:
Expand Down