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

Added tests for options #2409

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

Jimmykoki
Copy link

@Jimmykoki Jimmykoki commented Jun 11, 2023

The tests cover different scenarios such as when the compareBranch option is defined and changed is false, when the concurrencyLevel is undefined, when the concurrencyLevel is not a valid number, and when the concurrencyLevel is a valid number. By testing these scenarios, the code can be ensured to work as expected and avoid errors when used in a larger system.

trying to understand the codebase and added new test cased, and learning how to contribute to the open source community as a junior developer. Please let me know if there are any changes needed.

@changeset-bot
Copy link

changeset-bot bot commented Jun 11, 2023

⚠️ No Changeset found

Latest commit: 8e05fd9

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

Copy link
Contributor

@benpryke benpryke left a comment

Choose a reason for hiding this comment

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

Thanks for submitting this PR, I've taken a look and added some comments.

});

it('should return the number of CPUs when concurrencyLevel is undefined', () => {
const cpus = os.cpus().length;
Copy link
Contributor

@benpryke benpryke Jun 29, 2023

Choose a reason for hiding this comment

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

As this test is so simple, it's hard to avoid reimplementing the function. I think you have 2 options:

  1. Include os.cpus().length || 1 in this variable so as to mimic the intended implementation as closely as possible (breaking this up increases the chance of bugs creeping in).
  2. Mock os.cpus() to return different values, e.g. test for 2 and undefined to cover more possibilities.

});

it('should exit process when concurrencyLevel is not a valid number', () => {
expect(() => computeConcurrencyOption('invalid')).toThrow('Exit called');
Copy link
Contributor

Choose a reason for hiding this comment

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

We're actually missing a bug that exists in the implementation here.

It's important to test the boundary cases; in this case, there is a bug that needs fixing: the function will return 0 when '0' is passed when it actually should exit. This needs fixing and we need a test case to cover that. Note that the comment on line 37 of options.ts is also misleading and needs to be updated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants