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

Max workers #8410

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@

- `[jest-runtime]` Fix module registry memory leak ([#8282](https://github.com/facebook/jest/pull/8282))
- `[jest-resolve]` optimize resolve module path ([#8388](https://github.com/facebook/jest/pull/8388))
- `[jest-config]` Adjust `--maxWorkers` behavior to use the lesser of provided number and number of cores. ([#8410](https://github.com/facebook/jest/pull/8410))

## 24.7.1

Expand Down
6 changes: 3 additions & 3 deletions packages/jest-config/src/__tests__/getMaxWorkers.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ describe('getMaxWorkers', () => {
expect(getMaxWorkers({})).toBe(1);
});

it('Returns the `maxWorkers` when specified', () => {
const argv = {maxWorkers: 8};
expect(getMaxWorkers(argv)).toBe(8);
it('Returns the lesser of `maxWorkers` and (the number of cpus - 1)', () => {
expect(getMaxWorkers({maxWorkers: 2})).toBe(2);
expect(getMaxWorkers({maxWorkers: 50})).toBe(3);
});

it('Returns based on the number of cpus', () => {
Expand Down
5 changes: 2 additions & 3 deletions packages/jest-config/src/getMaxWorkers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {Config} from '@jest/types';
export default function getMaxWorkers(
argv: Partial<Pick<Config.Argv, 'maxWorkers' | 'runInBand' | 'watch'>>,
): number {
const cpus = os.cpus() ? os.cpus().length : 1;
if (argv.runInBand) {
return 1;
} else if (argv.maxWorkers) {
Expand All @@ -24,15 +25,13 @@ export default function getMaxWorkers(
parsed > 0 &&
parsed <= 100
) {
const cpus = os.cpus().length;
const workers = Math.floor((parsed / 100) * cpus);
return workers >= 1 ? workers : 1;
}

return parsed > 0 ? parsed : 1;
return Math.max(Math.min(cpus - 1, parsed), 1);
} else {
// In watch mode, Jest should be unobtrusive and not use all available CPUs.
const cpus = os.cpus() ? os.cpus().length : 1;
return Math.max(argv.watch ? Math.floor(cpus / 2) : cpus - 1, 1);
}
}
4 changes: 2 additions & 2 deletions packages/jest-transform/src/ScriptTransformer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -573,15 +573,15 @@ const calcIgnorePatternRegExp = (config: Config.ProjectConfig) => {
!config.transformIgnorePatterns ||
config.transformIgnorePatterns.length === 0
) {
return;
return undefined;
}

return new RegExp(config.transformIgnorePatterns.join('|'));
};

const calcTransformRegExp = (config: Config.ProjectConfig) => {
if (!config.transform.length) {
return;
return undefined;
}

const transformRegexp: Array<[RegExp, string]> = [];
Expand Down