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

Set up testing environment for updateChangelog and write comprehensive unit tests #188

Open
MajorLift opened this issue Feb 8, 2024 · 0 comments

Comments

@MajorLift
Copy link
Contributor

MajorLift commented Feb 8, 2024

Explanation

There are currently no tests written for updateChangelog or any other method in the update-changelog.ts file. We should write comprehensive unit tests for this module.

Issues

One complication with writing tests for updateChangelog and its helper methods is that they rely on executing actual git commands, as well as taking a projectRootDirectory parameter which defaults to the root directory of the local auto-changelog repo.

If tests are written to call updateChangelog, the tests will run on the changelog of the auto-changelog repo itself instead of the supplied mock changelog.

Approach

Therefore, it's necessary to set up mock git repos where git commands can be run in order to write tests for updateChangelog.

One possible approach would be to mock the outputs from the git commands, but this is likely to be too complex to be practical.

A second approach is to use the following tools to create sandboxes and set up git repos inside:

  • createSandbox method in the fs module of @metamask/utils
  • repository-{utils,filesystem} modules of @metamask/module-lint
    • module-lint is not intended to be released as a public package, so it will need to be npm installed as a git repo.

References

@MajorLift MajorLift changed the title Set up testing environment for updateChangelog and write unit tests Set up testing environment for updateChangelog and write comprehensive unit tests Feb 8, 2024
MajorLift added a commit that referenced this issue Feb 8, 2024
## Motivation

#158 incorrectly refactored the branches in updateChangelog, resulting in a state where new changelog entries weren't added to the return value if isReleaseCandidate is false.

## Explanation

- This error is fixed by moving the logic for retrieving new entries out of the if (isReleaseCandidate) block.
- The code for retrieving new entries is also extracted into its own method: getNewChangeEntries, abstracting away details that obscured the flow of the method's core logic.
- To verify that the buggy logic is correctly restored, it's necessary to compare the current state of updateChangelog to its state before the bug was introduced. For this, see: [diff link](https://github.com/MetaMask/auto-changelog/compare/e8df1ec717f534c8fe84c46ea86a847fa5a32973..da39a58a55571cf4e8a03e28096aa12c02c75f77#diff-4228e8302e41dd1c51e813af8368efdcb40b3d9db3e3f21f417ae87275d9f389R249-R316).

## References

- Closes #180
- Followed by #188
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant