Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
This is a prequel PR which blocks #3523. Even if the team doesn't agree on that one then this is still relevant because updating to the latest version is probably a good idea anyways.
Currently, our jest version is still at 26.4 which is an old and unmaintained version. There are some peer dependencies in this version that are incompatible with the workspaces feature of pnpm, and not just pnpm but npm as well after some further testing.
Updating to the latest version isn't straightforward because there were breaking changes in jest v27. The main breaking change was that using both done callback and returning a promise is no longer supported - see old blog post. I guess the reason we're still using the old version because there is too much effort to do the migration - there's over 50 test files with thousands of lines of code.
So I used babel to write a custom code migration script with the help of this Babel Plugin Handbook. The script is complicated but to explain simply - it loops through each test file, parses the code into a tree like data structure, and then applies the necessary changes for the jest migration, and rewrites the modified code back to the test file.
Click to view the script used
It automatically makes all the required changes (except a few lines of code which I manually changed) including:
done()
function calls.Example - refactoring
postCropRequest
function declarationExample - refactoring
postCropRequest
function call