CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/npm-jest--console

Console utilities for Jest testing framework that provide custom console implementations including BufferedConsole for capturing output, CustomConsole for formatted logging, and NullConsole for suppressing output during tests

Pending
Quality

Pending

Does it follow best practices?

Impact

Pending

No eval scenarios have been run

SecuritybySnyk

Pending

The risk profile of this skill

Overview
Eval results
Files

buffered-console.mddocs/

BufferedConsole

BufferedConsole is a console implementation that captures all output in memory as structured log entries, making it ideal for testing scenarios where you need to verify console output programmatically.

Capabilities

BufferedConsole Class

Console implementation that extends Node.js Console to buffer all output in memory for later retrieval.

/**
 * Console implementation that buffers all output in memory
 * Extends Node.js Console with memory buffering capabilities
 */
class BufferedConsole extends Console {
  /** Creates a new BufferedConsole instance with no configuration required */
  constructor();
  
  /** Reference to the Node.js Console constructor */
  Console: typeof Console;
  
  /** Returns the current buffer contents or undefined if empty */
  getBuffer(): ConsoleBuffer | undefined;
  
  /** Static method to write entries to a console buffer */
  static write(
    buffer: ConsoleBuffer,
    type: LogType,
    message: LogMessage,
    stackLevel?: number
  ): ConsoleBuffer;
}

Usage Examples:

import { BufferedConsole } from "@jest/console";

// Create a buffered console
const console = new BufferedConsole();

// Use like a normal console
console.log("Hello, World!");
console.error("Something went wrong");
console.warn("Warning message");

// Retrieve the buffer
const buffer = console.getBuffer();
if (buffer) {
  buffer.forEach(entry => {
    console.log(`Type: ${entry.type}, Message: ${entry.message}`);
  });
}

// Static write method for custom buffering
import type { ConsoleBuffer } from "@jest/console";
const customBuffer: ConsoleBuffer = [];
BufferedConsole.write(customBuffer, 'log', 'Custom message');

Console Methods

All standard console methods are supported with proper buffering and stack trace preservation.

Logging Methods

/**
 * Log a message to the buffer
 * @param firstArg - Primary message or data to log
 * @param rest - Additional arguments to format and log
 */
log(firstArg: unknown, ...rest: Array<unknown>): void;

/**
 * Log an informational message to the buffer
 * @param firstArg - Primary message or data to log
 * @param rest - Additional arguments to format and log
 */
info(firstArg: unknown, ...rest: Array<unknown>): void;

/**
 * Log a debug message to the buffer
 * @param firstArg - Primary message or data to log
 * @param rest - Additional arguments to format and log
 */
debug(firstArg: unknown, ...rest: Array<unknown>): void;

/**
 * Log a warning message to the buffer
 * @param firstArg - Primary message or data to log
 * @param rest - Additional arguments to format and log
 */
warn(firstArg: unknown, ...rest: Array<unknown>): void;

/**
 * Log an error message to the buffer
 * @param firstArg - Primary message or data to log
 * @param rest - Additional arguments to format and log
 */
error(firstArg: unknown, ...rest: Array<unknown>): void;

Assertion Method

/**
 * Assert that a value is truthy, logging assertion failures to the buffer
 * @param value - Value to test for truthiness
 * @param message - Optional message or Error object for assertion failure
 */
assert(value: unknown, message?: string | Error): void;

Object Inspection Methods

/**
 * Log an object inspection to the buffer
 * @param firstArg - Object to inspect
 * @param options - Optional inspection options from Node.js util.inspect
 */
dir(firstArg: unknown, options?: InspectOptions): void;

/**
 * Log XML-style object representation to the buffer
 * @param firstArg - Primary object to log
 * @param rest - Additional arguments to format and log
 */
dirxml(firstArg: unknown, ...rest: Array<unknown>): void;

Grouping Methods

/**
 * Start a new console group with optional title, increasing indentation depth
 * @param title - Optional group title
 * @param rest - Additional arguments to format in the title
 */
group(title?: string, ...rest: Array<unknown>): void;

/**
 * Start a new collapsed console group with optional title
 * @param title - Optional group title
 * @param rest - Additional arguments to format in the title
 */
groupCollapsed(title?: string, ...rest: Array<unknown>): void;

/**
 * End the current console group, decreasing indentation depth
 */
groupEnd(): void;

Counting Methods

/**
 * Increment and log a counter for the given label
 * @param label - Counter label, defaults to 'default'
 */
count(label?: string): void;

/**
 * Reset a counter for the given label to zero
 * @param label - Counter label to reset, defaults to 'default'
 */
countReset(label?: string): void;

Timing Methods

/**
 * Start a timer with the given label
 * @param label - Timer label, defaults to 'default'
 */
time(label?: string): void;

/**
 * End a timer and log the elapsed time
 * @param label - Timer label to end, defaults to 'default'
 */
timeEnd(label?: string): void;

/**
 * Log the current elapsed time for a running timer
 * @param label - Timer label to check, defaults to 'default'
 * @param data - Additional data to log with the time
 */
timeLog(label?: string, ...data: Array<unknown>): void;

docs

buffered-console.md

custom-console.md

index.md

null-console.md

output-formatting.md

tile.json