Open
Conversation
Collaborator
|
@navDhammu so sorry, this one has been open forever and we never got to reviewing it! I apologize. Do you think after merging conflicts it'd still be relevant? If so I can take a look next week! |
Collaborator
Author
|
@antsgar No worries. I think as long as all tests written after this PR was opened, were written using the correct syntax for the newer jest versions then it should be ok. |
Collaborator
Author
|
@antsgar After merging it looks like the newer tests written for animals are failing and they would need to be refactored to use the proper done callback / promise syntax for this jest version. Would you like me to look into this? |
1 task
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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
postCropRequestfunction declarationExample - refactoring
postCropRequestfunction call