Naite Overview
Test Logging
Record logs during executionSystematic tracking
Query System
Wildcard patternsChaining queries
Callstack Tracking
Call path tracingDebugging support
VSCode Integration
Real-time visualizationExtension support
What is Naite?
Naite is Sonamu’s test logging system. It systematically records data generated during test execution and allows you to query this data to help with test debugging. Just as tree rings record the growth process, Naite records the entire process of test execution. You can trace what data flowed at each step and which functions were called, in chronological order.Why Do You Need Naite?
Limitations of Conventional Debugging
When writing tests, you often encounter situations like these:Confusion with console.log
Confusion with console.log
When multiple tests run simultaneously, Console output:It’s hard to tell which completed first as the order is mixed up.
console.log outputs get mixed up. It’s difficult to determine which log came from which test.Difficulty with Filtering
Difficulty with Filtering
When you want to see only logs from a specific module or function, filtering is impossible with
console.log. You have to look at all logs.Unknown Call Path
Unknown Call Path
It’s difficult to trace where a specific log was output from and which functions it went through.
Mixed with Test Output
Mixed with Test Output
Vitest’s test result output and
console.log get mixed, reducing readability.Naite’s Solution
Naite systematically solves these problems:Key-based Management
Assigns unique keys to each log for systematic management. You can clearly distinguish modules and functions like
user:create, syncer:render.Wildcard Filtering
You can query only user-related logs with
user:* or all create logs with *:create. Find the information you want quickly.Automatic Callstack Tracking
Automatically collects the callstack for each log recording. You can clearly understand the function call path.
Test Isolation
Each test has an independent log store. Logs never get mixed with other tests.
VSCode Integration
Visualize logs in real-time with VSCode Extension. View them cleanly, separated from test output.
Query System
Easily find logs with complex conditions using chaining queries. Combine
fromFile(), fromFunction(), where() and more.Basic Concepts
1. Naite.t() - Recording Logs
Naite.t() is a function that records data during test execution. The first argument is the key, and the second argument is the value to record.
- Use colons (
:) to separate hierarchies - Recommended format:
module:function:action - Examples:
user:create:start,syncer:render:template,payment:charge:done
- Queryable with wildcard patterns (
user:*,*:create) - Group and manage by module
- Improved readability with intuitive structure
2. Naite.get() - Querying Logs
Naite.get() is a function that queries recorded logs. You can search by key or wildcard pattern.
3. NaiteStore - Log Storage
Each test has an independentNaiteStore. This is of type Map<string, NaiteTrace[]>, storing logs as arrays based on keys.
NaiteStore Structure
NaiteStore Structure
4. Automatic Callstack Tracking
Naite automatically collects the callstack at the time ofNaite.t() call. This allows you to understand where the log was recorded and which function call path was taken.
- Single Call
- Function Chain
- Deep Call
- Filter logs recorded in a specific function with
fromFunction("createUser") - Click on callstack in VSCode Extension → navigate directly to code location
- Debug complex call chains
Practical Examples
Basic Usage - Flow Tracking
The most basic usage is recording each step of the test flow.Intermediate Usage - Conditional Tracking
Track business logic branches.Advanced Usage - Error Tracking
Record detailed information when errors occur.Value of Error Tracking: When an error occurs, you can clearly see what input values caused it and at which step it failed. Combined with VSCode Extension’s callstack feature, you can pinpoint the exact error location.
How It Works
1. Log Recording Process
Context Check
Gets the currently running Context with
Sonamu.getContext(). Ignores if no Context exists.2. Log Query Process
3. VSCode Extension Transmission
Importance of Serialization: All values are serialized to JSON for transmission to VSCode Extension. If you pass functions or circular reference objects to
Naite.t(), a warning is displayed, but it accepts any type for ease of use.Key Features
1. Test-Only Design
1. Test-Only Design
Naite is designed to only work in test environments. Even if
Naite.t() exists in production code, there’s no performance impact.2. Complete Test Isolation
2. Complete Test Isolation
Each test has an independent NaiteStore. A new Store is created each time in
getMockContext() in bootstrap.ts.3. Any Type Allowed
3. Any Type Allowed
Naite.t(value: any) accepts any type. Ease of use was prioritized over TypeScript type safety.4. Automatic Serialization
4. Automatic Serialization
getAllTraces() returns all values serialized to JSON. This is for inter-process communication through Vitest’s task.meta.5. Wildcard Pattern Matching
5. Wildcard Pattern Matching
Supports simple but powerful pattern matching:
user:*: prefix matching (any length)*:create: suffix matching (same length)user:*:done: middle wildcard (same length)
Cautions
Next Steps
Recording Logs
Learn detailed usage and best practices for Naite.t().
Querying Logs
Learn about Naite.get() and the chaining query system.
Naite Viewer
Learn how to visualize logs in real-time with VSCode Extension.
Debugging Tests
Learn how to track complex bugs with callstack tracing.