This article is for EDOCODE Advent Calendar 2024, published on 16th December 2024.
The previous article was written by Taiji Yamada, a Product Manager at EDOCODE: Automated Email System Using Notion Webhooks and the No-Code Tool "Make" (The article is in Japanese).
Also, please check out the Wano Advent Calendar by our parent group company!
Our app, Gojiberry, is a Shopify survey app that helps merchants gather valuable feedback from their customers.
From the very beginning, we’ve built Gojiberry with test-driven development (TDD) to ensure our app is bug-free and that we can confidently release new features without breaking existing functionality. This foundation has allowed us to make large-scale changes, like migrating from Create React App (CRA) to Vite, with minimal disruption.
When CRA was deprecated, and its dependencies became outdated, we decided it was time to upgrade to a modern build tool that would better support our growing app. The large size of our codebase added some complexity, but the switch to Vite proved to be worth the effort.
Our goal was to migrate our two React projects:
If you're a Shopify store owner looking to gather actionable customer feedback, try out Gojiberry today on the Shopify App Store!
CRA served us well in the past, but it’s no longer maintained, and its dependencies have become outdated. This posed several challenges:
One of the biggest improvements in user-events v14 is the requirement to use await for all interaction methods. This eliminates the need for wrapping actions in await waitFor, making test code cleaner and easier to maintain.
Before (user-events v13):
import { render, screen } from '@testing-library/react'; import userEvent from '@testing-library/user-event'; import MyComponent from './MyComponent'; test('updates state on click', async () => { render(<MyComponent />); userEvent.click(screen.getByRole('button')); await waitFor(() => { expect(screen.getByText('Updated state')).toBeInTheDocument(); }); });
After (user-events v14):
import { render, screen } from '@testing-library/react'; import userEvent from '@testing-library/user-event'; import MyComponent from './MyComponent'; test('updates state on click', async () => { render(<MyComponent />); userEvent.click(screen.getByRole('button')); await waitFor(() => { expect(screen.getByText('Updated state')).toBeInTheDocument(); }); });
This change simplifies tests by removing the need to explicitly manage state changes with waitFor. Developers no longer need to think about when to include await waitFor, as the library automatically handles it.
The improvements in user-events v14 and Vitest addressed many of these issues, offering a cleaner, faster, and more consistent development experience.
Before choosing Vite, we evaluated Next.js and Remix. While both are powerful frameworks, they required significant changes to our codebase and infrastructure:
Next.js and Remix:
Why we chose Vite:
By choosing Vite, we avoided the complexity of adopting a full-fledged framework while reaping the benefits of a modern, lightweight build tool.
We approached the migration systematically since our monorepo contains two separate npm projects. Here’s how we executed the migration:
Start with the smaller project:
Migration steps:
The process for each project followed these steps:
Repeat for the larger project:
The migration from CRA to Vite, along with the transition to Vitest and user-events v14, has delivered substantial improvements to our development workflow:
The migration has been a game-changer, allowing us to iterate faster while maintaining confidence in our codebase.
Here are some takeaways from our experience:
Migrating from CRA to Vite and Vitest has brought significant improvements to our workflow. We now enjoy faster builds, cleaner test code with user-events v14, and a more resilient codebase thanks to stricter TypeScript rules.
One of the key factors that made this transition smoother was our early investment in test-driven development (TDD). With a comprehensive suite of tests in place, we were able to confidently make massive changes without breaking existing functionality.
If you’re considering a similar migration, we hope our experience provides valuable insights to guide your journey.
Tomorrow, 17th December 2024, the article will be Switching from B2C to B2B: a marketers confession by Amee Xu, a Product Marketing Manager at Gojiberry.
At Wano Group, we are hiring! If you are interested, please check out our open positions using the link below:
JOBS | Wano Group
The above is the detailed content of Lessons Learned Migrating from React CRA & Jest to Vite & Vitest. For more information, please follow other related articles on the PHP Chinese website!