Skip to main content
Learn about Naite, Sonamu’s test logging and debugging system.

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:
When multiple tests run simultaneously, console.log outputs get mixed up. It’s difficult to determine which log came from which test.
Console output:
It’s hard to tell which completed first as the order is mixed up.
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.
It’s difficult to trace where a specific log was output from and which functions it went through.
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.
Key Naming Rules:
  • Use colons (:) to separate hierarchies
  • Recommended format: module:function:action
  • Examples: user:create:start, syncer:render:template, payment:charge:done
Benefits:
  • 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.
Query Chaining: You can chain multiple conditions for complex searches:

3. NaiteStore - Log Storage

Each test has an independent NaiteStore. This is of type Map<string, NaiteTrace[]>, storing logs as arrays based on keys.
Example:
Test Isolation:
Each test has an independent Store so they don’t affect each other.

4. Automatic Callstack Tracking

Naite automatically collects the callstack at the time of Naite.t() call. This allows you to understand where the log was recorded and which function call path was taken.
Usage:
  • 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.
Input/Output Pattern: Using :input and :output suffixes helps clearly distinguish function inputs and outputs. This is useful for tracking data transformation processes.

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

1

Environment Check

Checks if NODE_ENV === "test". Immediately terminates if not in test environment.
2

Context Check

Gets the currently running Context with Sonamu.getContext(). Ignores if no Context exists.
3

Callstack Collection

Collects the current callstack with new Error().stack and parses it.
4

Trace Creation

Creates a NaiteTrace object containing key, value, callstack, and time.
5

Store Save

Adds to the array with naiteStore.set(key, [...existing, trace]).

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

Naite is designed to only work in test environments. Even if Naite.t() exists in production code, there’s no performance impact.
Each test has an independent NaiteStore. A new Store is created each time in getMockContext() in bootstrap.ts.
Naite.t(value: any) accepts any type. Ease of use was prioritized over TypeScript type safety.
However, values that cannot be serialized will show a warning when transmitted to the Extension.
getAllTraces() returns all values serialized to JSON. This is for inter-process communication through Vitest’s task.meta.
Supports simple but powerful pattern matching:
  • user:*: prefix matching (any length)
  • *:create: suffix matching (same length)
  • user:*:done: middle wildcard (same length)
Uses intuitive patterns instead of complex regular expressions.

Cautions

Cautions when using Naite:
  1. Test environment only: Only works when NODE_ENV === "test". Automatically disabled in production.
  2. Context required: Sonamu.getContext() must exist. Only use within bootstrap’s runWithMockContext().
  3. Avoid excessive logging: Calling Naite.t() inside loops can create thousands of traces, degrading performance.
  4. Key naming convention: The module:function:action format is recommended. Consistent rules make finding things easier later.
  5. Serializable values recommended: Values must be JSON serializable to transmit to VSCode Extension. Avoid functions and circular references.

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.