Implementation:DevExpress Testcafe WarningLog
| 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 ofWarningLogMessageobjects (each with amessagestring and a nullableactionId).globalLog-- An optional reference to a parentWarningLoginstance. 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 duringcopyFromto prevent double-firing.
Key behaviors:
- Deduplication --
addPlainMessagechecks for existing messages with the samemessagetext before inserting, ensuring each unique warning appears only once. - Template rendering --
addWarningaccepts either a raw string or aWarningLogMessageobject, appliesrenderTemplatewith additional arguments for string interpolation, then stores and propagates the result. - Hierarchical propagation -- If
globalLogis set, warnings bubble up to the global instance viaaddPlainMessage. - Event bus integration -- The static
createAddWarningCallbackfactory creates a callback that emits'before-warning-add'and'warning-add'events on aMessageBusinstance, enabling reactive notification handling in the reporter and UI layers. - Bulk copy --
copyFromimports all messages from anotherWarningLogwhile 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
- DevExpress_Testcafe_CommandFormatter -- Formatted commands may trigger warnings that flow through WarningLog during test execution
- DevExpress_Testcafe_ErrorTypes -- Error codes that may co-occur with warnings during test runs