Reflections on writing my first tests
- This was my first time properly writing and completing tests for a product at work. Have I grown enough to see things I couldn’t see before? Or did I finally have a little breathing room? Probably both. Anyway, it may seem like a small thing, but having built something and finished testing it feels incredibly reassuring.
- When you build and operate a feature yourself, you learn where it tends to break and what needs checking. After going through a cycle of building, operating, and revamping the search page, I understood which features needed tests.
- Can multiple filters be selected?
- Does the router work correctly when a filter is selected?
- Does fetching happen correctly when the route changes?
- Does the side sheet open according to the selected filter?
These are mostly things that are tedious to test every time but can break frequently.
- Writing tests and thinking through test cases also helps uncover bugs I had missed.
Finding a folder structure that fits how we work
- Notes on folder structures https://reactnext-central.xyz/blog/nextjs/code-structure-and-maintenance-strategies-for-nextjs https://bluemiv.tistory.com/87
Improving the folder structure to make features and structure easier to understand, and maintenance more efficient.
- Every new feature adds another folder inside components, effectively serving the same purpose as modules. The name “components” no longer really fits.
- Custom hooks and Zustand stores make hook and store files harder to manage.
- There are multiple hooks and utils folders in different places.
- Finding the files related to a particular feature feels inefficient.
modules > coupons >
components / types / hooks / store / constants /styles /test
* modules: Since development is organized by feature, separate them into modules. Manage only shared components in components.
* constants: Is a separate folder really necessary?
* types: Types currently live together in api. Do they need to move?
* Separating styles makes the code cleaner, but distancing them from the components that use them makes maintenance harder: which component calls which styles?
* test: Will we keep writing tests going forward?
components // Use the existing components folder for shared components.
│
modules
├── common
│ └── (code shared by multiple features)
├── coupons
│ ├── components
│ │ ├── CartItem.tsx
│ │ └── CartTotal.tsx
│ ├── styles
│ │ └── index.tsx
│ ├── hooks
│ │ ├── applyDiscount.ts
│ │ └── getCartSum.ts
│ ├── styles // optional
│ │ └── index.tsx
│ ├── types // optional
│ │ └── index.tsx
│ ├── test // optional
│ │ └── index.tsx
│ └── store // Zustand store
│ ├── applyDiscount.ts
│ └── getCartSum.ts
│
These are the questions I’m considering…
- modules: Since development is organized by feature, separate them into modules. Manage only shared components in components.
- constants: Is a separate folder really necessary?
- types: Types currently live together in api. Do they need to move?
- Separating styles makes the code cleaner, but distancing them from the components that use them makes maintenance harder: which component calls which styles?
- test: Will we keep writing tests going forward?
Recently, a folder structure called FSD has been gaining attention. Since our features keep growing, it might be worth considering this structure too.