RealmsWorld
RealmsWorld copied to clipboard
Set Up Vitest for RealmsWorld
Creates vitest.config.ts
in root of apps/nextjs
Adds example __tests__
directory to src/utils
that includes a mock for tokenDetails
and tests for getTokenName
utility function. The idea being that if test coverage is needed for code in specific directories within the nextjs app, new __tests__
directories can be added to the directory where test coverage is needed instead of having one giant __tests__
directory at the root of the nextjs app for all tests. I think its cleaner and easier to manage test files this way but to each their own.
Adds new commands to package.json
scripts in the nextjs app. "test": "vitest"
& "testUI: "vitest --ui"
running pnpm run test
inside the root of apps/nextjs
directory will run all tests that exist inside the nextjs app. Depending on your needs, it may be easier to read coverage reports in the terminal by running this command inside the specific directory you are currently working in for smaller coverage reports.
running pnpm run testUI
will open vitest's UI interface automatically and the interface updates automatically as changes are saved to test files. I tend to use the UI interface when I want to get a better idea of what lines are missing coverage for the code that Im adding tests for.
React Testing Library is also added as a package here for testing components.