Overview
sunpeak projects come pre-configured with testing tools and validation commands. The starter kit includes Vitest for unit testing and several npm scripts for code quality checks.Available Commands
Run unit tests with Vitest
Run ESLint and Prettier to check code style
Check TypeScript types without building
Run all validation commands (lint, typecheck, test)
Testing Setup
sunpeak uses Vitest, a fast unit testing framework built on Vite. The test configuration is invitest.config.ts.
What’s Configured
The test environment includes:- jsdom: Browser-like environment for React component testing
- @testing-library/react: For rendering and testing components
- @testing-library/jest-dom: Additional matchers for assertions
- Global test utilities:
describe,it,expect,beforeEach,afterEach - Browser API mocks:
matchMedia,IntersectionObserver,ResizeObserver
src/test/setup.ts.
Running Tests
Run all tests:Code Quality
Beyond unit tests, sunpeak includes tools for code quality:Linting
ESLint and Prettier check code style and catch common issues:Type Checking
TypeScript type checking catches type errors:Validation
Run all checks at once:Testing Best Practices
Keep tests simple
Keep tests simple
Test one thing per test case. Clear tests are maintainable tests.
Use meaningful test descriptions
Use meaningful test descriptions
Test user-facing behavior
Test user-facing behavior
Test what users see and interact with, not implementation details:
Clean up after tests
Clean up after tests
Use
afterEach to reset state between tests:Dive Deeper
Vitest Docs
Learn more about Vitest