Naite.t() Overview
Simple API
Two parametersIntuitive usage
Automatic Tracking
Automatic callstack collectionCall path identification
Any Type
All values allowedFlexible logging
Test-Only
NODE_ENV checkNo production impact
What is Naite.t()?
Naite.t() is a function that records data at specific points during test execution. It takes a unique key as the first argument and the value to record as the second argument.
- Can be queried at any time during test execution with
Naite.get() - Transmitted in real-time to VSCode Extension
- Stored with callstack and time information
Basic Usage
Simple Logging
The most basic usage is recording function inputs and outputs.Step-by-Step Logging
Track the flow of complex processes by logging step by step.- Clearly identify which step failed
- Measure time spent at each step
- Filter specific steps with wildcard patterns (
order:payment:*)
start/done Pattern: Recording the start and completion of each operation with
:start/:done makes it easier to calculate elapsed time or verify completion status later.Understanding Internal Behavior
1. Environment Check
Naite.t() first checks the execution environment.
- Safe even if
Naite.t()exists in production code - Test-only feature
- No runtime overhead
2. Context Check
Naite uses Sonamuβs Context system.- Provides independent
naiteStorefor each test - Ensures test isolation
- Maintains Context in async operations with AsyncLocalStorage
Context Creation Process
Context Creation Process
3. Callstack Collection
Automatically collects the callstack at the time ofNaite.t() call.
- Function name (
createUser) - File path (
/Users/.../user.model.ts) - Line number (
123)
Callstack Example
Callstack Example
4. Trace Creation and Storage
Creates aNaiteTrace object with collected information and stores it in the Store.
- Same key can be called multiple times
- Track in chronological order
- Support for loop operation logging
- Single Call
- Multiple Calls
Key Naming Strategy
Hierarchical Structure
Separating hierarchies with colons (:) makes it easy to query later with wildcard patterns.
- Correct Way
- Wrong Way
Recommended Patterns
1
module:function
The most basic pattern.
2
module:function:action
Use when more detailed tracking is needed.
3
module:function:action:detail
Use for very complex flows.
Practical Patterns
1. Conditional Tracking
Clearly track business logic branches.- A/B testing path verification
- Permission branch verification
- Error handling path tracking
2. Error Tracking
Record detailed information when errors occur.3. Performance Measurement
Record time information to identify bottlenecks.4. Loop Operation Tracking
For loops or batch operations, record only summary information.- Bad Example
- Good Example
- Conditional Logging
Value Types and Serialization
Any Type Allowed
Naite.t() accepts any type, allowing all JavaScript values to be recorded.
- Ease of use prioritized over TypeScript type safety
- No interruption from type errors while writing tests
- Same philosophy as expect()
Serialization Warning
JSON serialization is required to transmit to VSCode Extension. Non-serializable values will show a warning.- Recommended
- Warning
Serialization Warning Message
Serialization Warning Message
Performance Considerations
1. Test Environment Only
Naite.t() exists in production code, thereβs no performance impact.
2. Avoid Excessive Logging
Recommendations:- Record only loop start/end
- Record only when problems occur
- Use summary information
3. Conditional Logging
Enable detailed logging only when debugging is needed.Best Practices
1
Use Clear Keys
2
Consistent Structure
3
Minimal Information
4
Log at Meaningful Locations
Cautions
Next Steps
Querying Logs
Learn how to query recorded logs with Naite.get().
Naite Viewer
Learn how to visualize logs with VSCode Extension.
Debugging Tests
Learn how to find bugs with callstack tracking.
What is Naite?
Return to Naite overview.