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

output-formatting.mddocs/

Output Formatting

Output formatting utilities for converting console buffer entries into readable, styled string output with proper indentation and stack traces.

Capabilities

getConsoleOutput Function

Formats console buffer entries into a readable string output with proper styling, indentation, and stack traces for Jest test results.

/**
 * Formats console buffer entries into readable string output
 * Converts an array of log entries into formatted output with styling and stack traces
 * @param buffer - Array of log entries to format
 * @param config - Stack trace configuration for formatting
 * @param globalConfig - Jest global configuration for output styling
 * @returns Formatted string with styled console output
 */
function getConsoleOutput(
  buffer: ConsoleBuffer,
  config: StackTraceConfig,
  globalConfig: Config.GlobalConfig
): string;

Usage Examples:

import { BufferedConsole, getConsoleOutput } from "@jest/console";
import type { Config } from "@jest/types";

// Create and use a buffered console
const console = new BufferedConsole();
console.log("Hello, World!");
console.warn("This is a warning");
console.error("This is an error");

// Get the buffer
const buffer = console.getBuffer();

if (buffer) {
  // Mock configuration objects (in real Jest these come from the test framework)
  const stackTraceConfig = {
    rootDir: process.cwd(),
    testMatch: ["**/*.test.js"]
  };
  
  const globalConfig: Config.GlobalConfig = {
    verbose: true,
    noStackTrace: false,
    // ... other Jest config properties
  } as Config.GlobalConfig;

  // Format the output
  const formattedOutput = getConsoleOutput(buffer, stackTraceConfig, globalConfig);
  console.log(formattedOutput);
}

// Example of formatted output:
// console.log
//   Hello, World!
//     at Object.<anonymous> (/path/to/file.js:2:9)
//
// console.warn
//   This is a warning
//     at Object.<anonymous> (/path/to/file.js:3:9)
//
// console.error
//   This is an error
//     at Object.<anonymous> (/path/to/file.js:4:9)

Dependencies

The output formatting functionality relies on external Jest utilities:

Required Types

// From @jest/types
interface Config {
  GlobalConfig: {
    verbose?: boolean;
    noStackTrace?: boolean;
    // Other Jest global configuration properties
  };
}

// From jest-message-util
interface StackTraceConfig {
  rootDir: string;
  testMatch?: string[];
  // Other stack trace configuration properties
}

interface StackTraceOptions {
  noCodeFrame: boolean;
  noStackTrace: boolean;
}

Output Styling

The formatting applies different styles based on log types:

  • Standard logs (log, info, debug): Plain text with indentation
  • Warnings (warn): Yellow styling with stack traces when enabled
  • Errors (error): Red styling with stack traces when enabled
  • All types: Proper indentation based on Jest's verbose mode setting

The output includes:

  • Type indicators (e.g., "console.log", "console.warn")
  • Indented message content
  • Stack trace information (when not suppressed)
  • Color coding for warnings and errors using chalk styling

docs

buffered-console.md

custom-console.md

index.md

null-console.md

output-formatting.md

tile.json