test: [M3-6428] - Migrate from Jest to Vitest#9817
test: [M3-6428] - Migrate from Jest to Vitest#9817jdamore-linode merged 44 commits intolinode:developfrom
Conversation
…test configuration
| "start:manager:ci": "yarn workspace linode-manager start:ci", | ||
| "clean": "rm -rf node_modules && rm -rf packages/@linode/api-v4/node_modules && rm -rf packages/manager/node_modules && rm -rf packages/@linode/validation/node_modules", | ||
| "test": "yarn workspace linode-manager test --maxWorkers=4", | ||
| "test": "yarn workspace linode-manager test", |
There was a problem hiding this comment.
Would we no longer have multiple workers running with the switch to Vitest?
There was a problem hiding this comment.
@dwiley-akamai Nope! This just removes the upper limit of having 4 workers. If I remember correctly, Vitest (and maybe Jest too) will default to the number of available cores minus 1, but we added this argument to work around an issue we were having in CI, I believe.
I originally removed it to see if CI would pass without it, but I may restore it to see if having it improves performance at all. And if it doesn't, I'll remove it again 😅
There was a problem hiding this comment.
There is no Vitest equivalent to jest.setTimeout, so in this case we just pass the desired timeout to the test as the third parameter when calling it(...).
There was a problem hiding this comment.
Unlike Jest, when mocking modules, Vitest expects the entire module to be mocked. We accomplish this by importing the actual module and using it for the mock, overriding only the exports that we wish to mock.
Similar changes have been made throughout the codebase:
- src/features/Billing/BillingPanels/PaymentInfoPanel/PaymentInformation.test.tsx
- src/features/Billing/BillingPanels/BillingActivityPanel/BillingActivityPanel.test.tsx
- src/features/ObjectStorage/BucketDetail/ObjectDetailsDrawer.test.tsx
- src/features/Domains/DownloadDNSZoneFileButton.test.tsx
- src/components/PaymentMethodRow/PaymentMethodRow.test.tsx
- src/features/TopMenu/AddNewMenu/AddNewMenu.test.tsx
- src/features/Kubernetes/ClusterList/ClusterActionMenu.test.tsx
- src/features/StackScripts/StackScriptsLanding.test.tsx
- src/features/Linodes/LinodesDetail/LinodeBackup/LinodeBackups.test.tsx
- src/hooks/useOrder.test.tsx
There was a problem hiding this comment.
Calls to jest.mock() and vi.mock() get hoisted to the top of the file during test transformation, so calling it inside of a test doesn't always result in the behavior we expect.
In some cases we want the mocked value to differ between tests in the same test file. Unlike Jest, Vitest offers a way for us to modify the mocked value using the vi.hoisted utility. We use this in SelectRegionPanel.test.tsx and RescueDialog.test.tsx.
Co-authored-by: Banks Nussman <115251059+bnussman-akamai@users.noreply.github.com>
|
Coming over from frontend cafe 😆 -- will take a look tomorrow! 👀 |
coliu-akamai
left a comment
There was a problem hiding this comment.
Looks good, thanks Joe!! 🎉 Appreciate the explanations on this and the previous pr, was helpful for understanding the changes made
I did get the intermittent test failures you mentioned for SearchLanding.test.tsx and CreateAPITokenDrawer.test.tsx when running yarn test - any chance you know why they happen?
| "build": "concurrently --raw \"tsc\" \"tsup\"", | ||
| "test": "jest", | ||
| "test:debug": "node --inspect-brk node_modules/.bin/jest --runInBand", | ||
| "test": "yarn vitest run", |
There was a problem hiding this comment.
Do we no longer need a test:debug script for vitest? 👀 (or was this script just unnecessary in the first place?)



Description 📝
Replaces Jest with Vitest and attempts to get all of our tests passing. See also PR #8951 -- a lot of the test changes in this PR stem from that.
Trouble tests and other things to call attention to:
confirmObjectStorage()inObjectStorage/utilities.tsto convert the function to async/await syntax, but have not tested the change in CloudRescueDialog.test.tsx,SearchLanding.test.tsx,CreateAPITokenDrawer.test.tsxare each failing intermittently, but seem to pass when run by themselvesI've kept pretty good documentation on each of the significant changes made to the tests, and plan to follow up with a self review that describes each significant change.
Changes 🔄
jestwithvivi.mock, moving component rendering to inside of tests, and making changes involving async operationsHow to test 🧪
yarn testAs an Author I have considered 🤔
Check all that apply