Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Implementation:DevExpress Testcafe WarningLog

From Leeroopedia
Revision as of 10:37, 27 September 2026 by Agent (talk | contribs) (Sync from local file)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Knowledge Sources
Domains Notifications, Reporting
Last Updated 2026-02-12 12:00 GMT

Overview

WarningLog is a class that collects, deduplicates, and optionally propagates warning messages through a hierarchical log structure with an event-driven callback mechanism.

Description

src/notifications/warning-log.ts exports the WarningLog class and a supporting WarningLogMessage interface. Each WarningLog instance holds:

  • messageInfos -- An array of WarningLogMessage objects (each with a message string and a nullable actionId).
  • globalLog -- An optional reference to a parent WarningLog instance. When set, every warning added to the local log is also propagated to the global log.
  • callback -- An optional async callback of type (message: string, actionId: string | null) => Promise<void> invoked whenever a new warning is added (unless the log is in copying mode).
  • _isCopying -- A private flag that suppresses callback invocation during copyFrom to prevent double-firing.

Key behaviors:

  • Deduplication -- addPlainMessage checks for existing messages with the same message text before inserting, ensuring each unique warning appears only once.
  • Template rendering -- addWarning accepts either a raw string or a WarningLogMessage object, applies renderTemplate with additional arguments for string interpolation, then stores and propagates the result.
  • Hierarchical propagation -- If globalLog is set, warnings bubble up to the global instance via addPlainMessage.
  • Event bus integration -- The static createAddWarningCallback factory creates a callback that emits 'before-warning-add' and 'warning-add' events on a MessageBus instance, enabling reactive notification handling in the reporter and UI layers.
  • Bulk copy -- copyFrom imports all messages from another WarningLog while suppressing callback invocation to avoid duplicate events.

Usage

WarningLog instances are created at multiple levels of the TestCafe hierarchy: a global log for the entire runner, per-fixture logs, and per-test-run logs. Test runs use the globalLog parameter to propagate warnings upward. The createAddWarningCallback factory is used to wire warnings into the MessageBus for reporter plugins.

Code Reference

Source Location

src/notifications/warning-log.ts (82 lines)

Signature

export interface WarningLogMessage {
    message: string;
    actionId: string | null;
}

type WarningLogCallback = (message: string, actionId: string | null) => Promise<void>;

export default class WarningLog {
    public messageInfos: WarningLogMessage[];
    public globalLog: WarningLog | null;
    public callback?: WarningLogCallback;
    private _isCopying: boolean;

    public constructor (globalLog: WarningLog | null = null, callback?: WarningLogCallback);

    public get messages (): string[];

    public addPlainMessage (msg: WarningLogMessage): void;
    public addWarning (msg: WarningLogMessage | string, ...args: any[]): void;
    public clear (): void;
    public copyFrom (warningLog: WarningLog): void;

    public static createAddWarningCallback (
        messageBus?: MessageBus | object,
        testRun?: TestRun
    ): WarningLogCallback;
}

Import

import WarningLog from '../../notifications/warning-log';
import { WarningLogMessage } from '../../notifications/warning-log';

I/O Contract

Inputs

Parameter Type Description
globalLog null Optional parent log for hierarchical propagation. Defaults to null.
callback WarningLogCallback Optional async callback invoked on each new warning addition.
msg (for addWarning) string The warning message, either as a plain string template or a structured object with message and actionId.
...args (for addWarning) any[] Additional arguments passed to renderTemplate for string interpolation.
messageBus (for createAddWarningCallback) object The message bus to emit warning events on.
testRun (for createAddWarningCallback) TestRun The test run to associate with emitted warning events.

Outputs

Method/Property Return Type Description
messages (getter) string[] Array of deduplicated warning message strings (without actionId).
addWarning void Adds a warning to the local log, propagates to globalLog, and fires the callback.
createAddWarningCallback WarningLogCallback Returns an async function that emits 'before-warning-add' and 'warning-add' events on the provided MessageBus.

Usage Examples

Creating a hierarchical warning log:

const globalLog = new WarningLog();
const callback  = WarningLog.createAddWarningCallback(messageBus, testRun);
const testLog   = new WarningLog(globalLog, callback);

testLog.addWarning('Selector "{0}" did not match any elements.', selectorText);

console.log(testLog.messages);   // ['Selector "div.foo" did not match any elements.']
console.log(globalLog.messages); // ['Selector "div.foo" did not match any elements.']

Copying warnings from a child log:

const fixtureLog = new WarningLog();
fixtureLog.addWarning('Deprecation: .before() hook is deprecated.');

const runnerLog = new WarningLog();
runnerLog.copyFrom(fixtureLog);
// Callback is suppressed during copyFrom to avoid duplicate events

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment