vitest-testing-patterns
Use when vitest testing patterns including unit tests, mocks, spies, and browser mode testing.
What this skill does
# vitest testing patterns
Master Vitest testing patterns including unit tests, mocks, spies, and browser mode testing. This skill provides comprehensive coverage of essential concepts, patterns, and best practices for professional Vitest development.
## Overview
Vitest is a powerful tool for typescript development, providing robust capabilities for maintaining code quality and ensuring reliable software delivery. This skill covers the fundamental through advanced aspects of working with Vitest.
## Installation and Setup
### Basic Installation
Setting up Vitest requires proper installation and configuration in your development environment.
```bash
# Installation command specific to Vitest
# Follow official documentation for latest version
```
### Project Configuration
Create appropriate configuration files and setup for your project structure:
- Configuration file setup
- Project structure organization
- Team collaboration setup
- CI/CD integration preparation
## Core Concepts
### Fundamental Principles
Understanding the core principles of Vitest is essential for effective usage:
1. **Architecture** - How Vitest is structured and operates
2. **Configuration** - Setting up and customizing behavior
3. **Integration** - Working with other tools and frameworks
4. **Best Practices** - Industry-standard approaches
### Key Features
Vitest provides several key features that make it valuable:
- Feature 1: Core functionality
- Feature 2: Advanced capabilities
- Feature 3: Integration options
- Feature 4: Performance optimization
- Feature 5: Extensibility
### Configuration Strategy
Proper configuration ensures Vitest works optimally:
- Environment-specific setup
- Team standards enforcement
- Performance tuning
- Error handling configuration
### Advanced Usage
For complex scenarios, Vitest offers advanced capabilities:
- Custom extensions
- Advanced patterns
- Performance optimization
- Scalability considerations
## Code Examples
### Example 1: Basic Setup
```typescript
// Basic Vitest setup
// Demonstrates fundamental usage patterns
// Shows proper initialization and configuration
// Core setup code
function basicSetup() {
// Initialize framework
// Configure basic options
// Return configured instance
}
// Usage example
const instance = basicSetup();
```
### Example 2: Configuration
```typescript
// Configuration example for Vitest
// Shows how to properly configure
// Includes common options and patterns
// Configuration object
const config = {
option1: 'value1',
option2: 'value2',
advanced: {
setting1: true,
setting2: false
}
};
// Apply configuration
function applyConfig(config) {
// Validation logic
// Application logic
// Return result
}
```
### Example 3: Advanced Pattern
```typescript
// Advanced usage pattern
// Demonstrates sophisticated techniques
// Shows best practices in action
function advancedPattern() {
// Setup phase
// Execution phase
// Cleanup phase
}
```
### Example 4: Integration
```typescript
// Integration with other tools
// Shows real-world usage
// Demonstrates interoperability
function integrationExample() {
// Setup integration
// Execute workflow
// Handle results
}
```
### Example 5: Error Handling
```typescript
// Proper error handling approach
// Defensive programming patterns
// Graceful degradation
function withErrorHandling() {
try {
// Main logic
} catch (error) {
// Error recovery
} finally {
// Cleanup
}
}
```
### Example 6: Performance Optimization
```typescript
// Performance-optimized implementation
// Shows efficiency techniques
// Demonstrates best practices
function optimizedApproach() {
// Efficient implementation
// Resource management
// Performance monitoring
}
```
### Example 7: Testing
```typescript
// Testing approach for Vitest
// Unit test examples
// Integration test patterns
function testExample() {
// Test setup
// Execution
// Assertions
// Teardown
}
```
### Example 8: Production Usage
```typescript
// Production-ready implementation
// Includes monitoring and logging
// Error recovery and resilience
function productionExample() {
// Production configuration
// Monitoring setup
// Error handling
// Logging
}
```
## Best Practices
1. **Follow conventions** - Adhere to established naming and structural patterns for consistency
2. **Configure appropriately** - Set up framework configuration that matches project requirements
3. **Validate inputs** - Always validate and sanitize inputs before processing
4. **Handle errors gracefully** - Implement comprehensive error handling and recovery
5. **Document decisions** - Comment configuration choices and non-obvious implementations
6. **Test thoroughly** - Write comprehensive tests for all functionality
7. **Optimize performance** - Profile and optimize critical paths
8. **Maintain security** - Follow security best practices and guidelines
9. **Keep updated** - Regularly update framework and dependencies
10. **Monitor production** - Implement logging and monitoring for production systems
## Common Pitfalls
1. **Incorrect configuration** - Misconfiguration leads to unexpected behavior and bugs
2. **Missing error handling** - Not handling edge cases causes production issues
3. **Poor performance** - Not optimizing leads to scalability problems
4. **Inadequate testing** - Insufficient test coverage misses bugs
5. **Security vulnerabilities** - Not following security best practices exposes risks
6. **Tight coupling** - Poor architecture makes maintenance difficult
7. **Ignoring warnings** - Dismissing framework warnings leads to future problems
8. **Outdated dependencies** - Using old versions exposes security risks
9. **No monitoring** - Lack of observability makes debugging difficult
10. **Inconsistent standards** - Team inconsistency reduces code quality
## Advanced Topics
### Customization
Vitest allows extensive customization for specific needs:
- Custom plugins and extensions
- Behavior modification
- Integration adapters
- Domain-specific adaptations
### Performance Tuning
Optimize Vitest performance for production:
- Profiling and benchmarking
- Resource optimization
- Caching strategies
- Parallel execution
### CI/CD Integration
Integrate Vitest into continuous integration pipelines:
- Automated execution
- Result reporting
- Quality gates
- Deployment integration
### Troubleshooting
Common issues and their solutions:
- Configuration errors
- Integration problems
- Performance issues
- Unexpected behavior
## When to Use This Skill
- Setting up Vitest in new projects
- Configuring Vitest for specific requirements
- Migrating to Vitest from alternatives
- Optimizing Vitest performance
- Implementing advanced patterns
- Troubleshooting Vitest issues
- Integrating Vitest with CI/CD
- Training team members on Vitest
- Establishing team standards
- Maintaining existing Vitest implementations
## Additional Resources
### Documentation
- Official Vitest documentation
- Community guides and tutorials
- API reference materials
- Migration guides
### Tools and Utilities
- Development tools
- Testing utilities
- Monitoring solutions
- Helper libraries
### Community
- Online forums and communities
- Open source contributions
- Best practice repositories
- Example implementations
## Conclusion
Mastering Vitest requires understanding both fundamentals and advanced concepts. This skill provides the foundation for professional-grade usage, from initial setup through production deployment. Apply these principles consistently for best results.
## Detailed Configuration Examples
### Configuration Option 1
Comprehensive configuration example demonstrating best practices and common patterns used in production environments.
```bash
# Detailed configuration setup
# Includes all necessary options
# Optimized for production use
```
### Configuration Option 2
Alternative configuration approach for different use casesRelated in General
modeling-omnistudio-epc-catalog
IncludedSalesforce Industries CME EPC product-modeling skill for Product2-based catalog creation. Use when creating EPC products, configuring product attributes, building offer bundles with Product Child Items, or reviewing EPC DataPack JSON metadata for product catalog changes. TRIGGER when: user creates or updates Product2 EPC records, AttributeAssignment payloads, AttributeMetadata/AttributeDefaultValues, Offer bundles, or ProductChildItem relationships. DO NOT TRIGGER when: designing OmniScripts/FlexCards/Integration Procedures (use building-omnistudio-omniscript, building-omnistudio-flexcard, or building-omnistudio-integration-procedure), implementing Apex business logic (use generating-apex), or troubleshooting deployment pipelines (use deploying-metadata).
relationship-science-coach
IncludedUse this skill for direct, practical adult relationship coaching: couples conflict, repair, trust, marriage, dating, flirting, attachment patterns, emotional connection, sex, desire differences, eroticism, kink negotiation, affection, love languages, breakups, and long-term passion. Draw on Gottman, EFT and Hold Me Tight, attachment science, modern sex research, Perel, Nagoski, Kerner, Schnarch, Love and Stosny, and flexible love-language tools. Be concrete and low-hedge. Redirect only for imminent danger, abuse, coercive control, minors, non-consent, self-harm, stalking, or medical/legal/psychiatric decisions.
building-sf-integrations
IncludedSalesforce integration architecture and runtime plumbing with 120-point scoring. Use this skill to set up Named Credentials, External Credentials, External Services, REST/SOAP callout patterns, Platform Events, and Change Data Capture. TRIGGER when: user sets up Named Credentials, External Services, REST/SOAP callouts, Platform Events, CDC, or touches .namedCredential-meta.xml files. DO NOT TRIGGER when: Connected App/OAuth config (use configuring-connected-apps), Apex-only logic (use generating-apex), or data import/export (use handling-sf-data).
venue-templates
IncludedAccess comprehensive LaTeX templates, formatting requirements, and submission guidelines for major scientific publication venues (Nature, Science, PLOS, IEEE, ACM), academic conferences (NeurIPS, ICML, CVPR, CHI), research posters, and grant proposals (NSF, NIH, DOE, DARPA). This skill should be used when preparing manuscripts for journal submission, conference papers, research posters, or grant proposals and need venue-specific formatting requirements and templates.
let-fate-decide
IncludedDraws the 12 Houses of the Zodiac Tarot spread to inject entropy into planning when prompts are vague, ambiguous, or casually delegated. Interprets the spread to guide next steps. Use when the user says 'let fate decide', 'YOLO', 'whatever', 'idk', or other nonchalant phrases, makes Yu-Gi-Oh references, or when you are about to arbitrarily pick between multiple reasonable approaches. Prefer over ask-questions-if-underspecified when the user's tone is casual or playful rather than precision-seeking.
net-ops
IncludedCross-platform network troubleshooting (Windows, macOS, Linux) via local or remote shell. Use for: DNS broken, can't resolve hostnames, nslookup/dig works but apps fail, NRPT, WFP, scutil, /etc/resolver, systemd-resolved, /etc/resolv.conf, NetworkManager, VPN DNS leak residue (ProtonVPN/Mullvad/WireGuard/AnyConnect), AV/firewall blocking DNS or DoH, Tailscale DNS interaction, intermittent connectivity, remote diagnostics over SSH.