Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions packages/jest-cli/src/__tests__/cli/args.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/**
* Copyright (c) 2014-present, Facebook, Inc. All rights reserved.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
*/

'use strict';

import type {Argv} from 'types/Argv';
import {check} from '../../cli/args';

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

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

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

it('raises an exception if findRelatedTests is specified with no file paths', () => {
const argv: Argv = {findRelatedTests: true};
expect(() => check(argv)).toThrow();
});

it('raises an exception if maxWorkers is specified with no number', () => {
const argv: Argv = {maxWorkers: undefined};
expect(() => check(argv)).toThrow();
});

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

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');

});
});
8 changes: 8 additions & 0 deletions packages/jest-cli/src/cli/args.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,14 @@ export const check = (argv: Argv) => {
);
}

if (argv.hasOwnProperty('maxWorkers') && argv.maxWorkers === undefined) {
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
Contributor

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

);
}

if (
argv.config &&
!isJSONString(argv.config) &&
Expand Down