VirtualConsolePrinter buffers console logs, destructively drains on read/readAsString calls, filters by log level, formats group indentation and collapsed group suppression, dispatches lifecycle events, and is exposed on Window via happyDOM.virtualConsolePrinter.
VirtualConsolePrinter buffers console logs, destructively drains on read/readAsString calls, filters by log level, formats group indentation and collapsed group suppression, dispatches lifecycle events, and is exposed on Window via happyDOM.virtualConsolePrinter. HOW
readAsString() and read() inspect captured virtual console logs non-destructively without clearing the internal buffer until an explicit clear() invocation.
这是本样本作者记下的、开发者或模型在此处通常会有的预期。下面的契约才是真正运行过的东西。
契约
VirtualConsolePrinter.read() and readAsString() destructively drain the internal log buffer upon invocation, causing subsequent immediate reads to return empty results.
readAsString(minLogLevel) filters formatted output by severity while draining all log entries from the buffer regardless of level.
console.group() indents log entries by two spaces with a ▼ prefix, whereas console.groupCollapsed() suppresses nested entries from readAsString() with a ▶ prefix.
addEventListener dispatches synchronous 'print' and 'clear' events on log and clear operations, rejecting unsupported event names.
close() marks the printer as closed, flushes buffered entries and listeners, and causes subsequent print and event calls to be ignored.
Window instances expose the page VirtualConsolePrinter through window.happyDOM.virtualConsolePrinter.