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
Does it follow best practices?
Impact
Pending
No eval scenarios have been run
Pending
The risk profile of this skill
Output formatting utilities for converting console buffer entries into readable, styled string output with proper indentation and stack traces.
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)The output formatting functionality relies on external Jest utilities:
// 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;
}The formatting applies different styles based on log types:
log, info, debug): Plain text with indentationwarn): Yellow styling with stack traces when enablederror): Red styling with stack traces when enabledThe output includes: