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

Fix getMaxWorkers on termux #7154

Merged
merged 2 commits into from
Oct 12, 2018

Conversation

rplopes
Copy link
Contributor

@rplopes rplopes commented Oct 12, 2018

Summary

Jest is using getMaxWorkers to figure out how many CPUs to use in parallel to run the test suite. However, it's using node's os.cpus(), which unfortunately might not return an answer if the corresponding system information is not available.

That's what happens under termux, a popular terminal emulator for Android. Using termux, we get:

> os = require('os')
...
> os.cpus()
undefined

This small detail is crashing jest, since it's trying to read length from an undefined object:

const cpus = os.cpus().length;

The proposed solution is to default the result of getMaxWorkers to 1 when os.cpus() is undefined. This is enough to fix the crash.

Test plan

Coverage for getMaxWorkers was updated to reflect the new changes.

In addition, to verify the goal of the PR was achieved, one can run jest on termux in any version of Android, termux and node. The code without this fix should crash, and with this fix it should run successfully.

@@ -12,7 +12,7 @@ import type {Argv} from 'types/Argv';
import os from 'os';

export default function getMaxWorkers(argv: Argv): number {
if (argv.runInBand) {
Copy link
Member

@SimenB SimenB Oct 12, 2018

Choose a reason for hiding this comment

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

I think it makes more sense to put the check before we do .length (line 20). In this case, we want maxWorkers to override the fallback of 1

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure, makes sense. I'll push an updated version.

@rplopes rplopes force-pushed the fix-get-max-workers-on-termux branch from c531a98 to 062a46d Compare October 12, 2018 23:06
@SimenB SimenB merged commit a30b83e into jestjs:master Oct 12, 2018
@rplopes rplopes deleted the fix-get-max-workers-on-termux branch October 14, 2018 10:56
@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 12, 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.

3 participants