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

Check if the maxWorkers has a value and raises an exception otherwise #4591

Merged
merged 3 commits into from
Oct 3, 2017
Merged

Check if the maxWorkers has a value and raises an exception otherwise #4591

merged 3 commits into from
Oct 3, 2017

Conversation

nicolasiensen
Copy link
Contributor

Summary

In this commit, we are adding a new validation in the check method of the jest-cli package, so we raise an exception if the user tries to run Jest with undefined maxWorkers

Some users were confusing -w as an alias to --watch, but in fact, -w is an alias to --maxWorkers. This change will also make this distinction clearer.

Also, a new test file was added to the jest-cli package, in order to unit test the check method.

Fixes issue #4577

Test plan

jest --maxWorkers
# raises an exception
jest --maxWorkers 2
# runs the tests

jest

In this commit we are adding a new validation in the check method of the
jest-cli package, so we raise an exception if the user tries to run Jest
with undefined maxWorkers, e.g.

jest --maxWorkers

jest --maxWorkers 2

Some users were confusing -w as an alias to --watch, but in fact it is
an alias to --maxWorkers. This change will also make this distinction
clearer.

Fixes issue #4577
@thymikee
Copy link
Collaborator

thymikee commented Oct 3, 2017

Great! Can we hide the help menu and just display the message?
EDIT: scratch that, forgot this is default behavior.

@nicolasiensen
Copy link
Contributor Author

It seems to be Jest's default behaviour to display the whole menu when an exception is raised during the validation of the arguments.

jest2

Should we change this default behaviour, so whenever the arguments are invalid Jest displays only the error message?

@codecov-io
Copy link

codecov-io commented Oct 3, 2017

Codecov Report

Merging #4591 into master will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@           Coverage Diff           @@
##           master    #4591   +/-   ##
=======================================
  Coverage   55.68%   55.68%           
=======================================
  Files         186      186           
  Lines        6348     6348           
  Branches        3        3           
=======================================
  Hits         3535     3535           
  Misses       2812     2812           
  Partials        1        1

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 7aa3017...2ff0f6b. Read the comment docs.


it('raises an exception if config is not a valid JSON string', () => {
const argv: Argv = {config: 'x:1'};
expect(() => check(argv)).toThrow();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tests, nice! I think we should at least check the core message of the error though.

Something like this would be more descriptive:

expect(() => check(argv)).toThrowError('not a valid JSON string');

throw new Error(
'The --maxWorkers option requires a number to be specified.\n' +
'Example usage: jest --maxWorkers 2\n' +
'Or did you mean --watch ?',
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: remove the space before question mark.

Also, how about adjusting this to most common mistake:

- The --maxWorkers option
+ The --maxWorkers (-w) option

Copy link
Collaborator

@thymikee thymikee left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left a couple of inline comments, but generally looks good.

@thymikee
Copy link
Collaborator

thymikee commented Oct 3, 2017

@cpojer Let's wait for CI to pass and it's basically ready to merge.
@nicolasiensen Great contribution 🙂

@cpojer
Copy link
Member

cpojer commented Oct 3, 2017

Agree with @thymikee, this is a great PR. Thank you <3

@github-actions
Copy link

This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 13, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants