A WebdriverIO utility to help reporting all events with extensible base class for custom reporters
npx @tessl/cli install tessl/npm-wdio--reporter@9.19.0WDIO Reporter is a WebdriverIO utility that provides a comprehensive base class for creating custom test reporters. It offers a complete event-driven architecture with EventEmitter support for capturing various test lifecycle events including runner start/end, suite start/end, hook execution, and test results. The library provides structured data objects for organizing test metadata and includes built-in support for output stream management with configurable file or stdout writing capabilities.
npm install @wdio/reporterimport WDIOReporter from "@wdio/reporter";For named imports:
import WDIOReporter, {
SuiteStats,
TestStats,
HookStats,
RunnerStats,
getBrowserName
} from "@wdio/reporter";CommonJS:
const WDIOReporter = require("@wdio/reporter").default;
const { SuiteStats, TestStats, HookStats, RunnerStats, getBrowserName } = require("@wdio/reporter");import WDIOReporter from "@wdio/reporter";
import type { Reporters } from "@wdio/types";
export class MyCustomReporter extends WDIOReporter {
constructor(options: Partial<Reporters.Options>) {
super(options);
// Custom initialization logic
}
onRunnerStart(runnerStats: RunnerStats) {
console.log(`Runner started for ${runnerStats.specs.length} spec(s)`);
}
onTestPass(testStats: TestStats) {
this.write(`✓ ${testStats.fullTitle}\n`);
}
onTestFail(testStats: TestStats) {
this.write(`✗ ${testStats.fullTitle}\n`);
if (testStats.error) {
this.write(` Error: ${testStats.error.message}\n`);
}
}
onRunnerEnd(runnerStats: RunnerStats) {
console.log(`Runner completed with ${runnerStats.failures} failures`);
}
}The WDIO Reporter system is built around several key components:
WDIOReporter extends EventEmitter and provides the foundation for all custom reportersSuiteStats, TestStats, HookStats, RunnerStats) for organizing test metadataThe main WDIOReporter class that custom reporters extend, providing event handling infrastructure and output management.
export default class WDIOReporter extends EventEmitter {
constructor(options: Partial<Reporters.Options>);
// Output management
write(content: unknown): void;
get isSynchronised(): boolean;
// Event handler methods (overridable)
onRunnerStart(runnerStats: RunnerStats): void;
onSuiteStart(suiteStats: SuiteStats): void;
onHookStart(hookStat: HookStats): void;
onHookEnd(hookStats: HookStats): void;
onTestStart(testStats: TestStats): void;
onTestPass(testStats: TestStats): void;
onTestFail(testStats: TestStats): void;
onTestRetry(testStats: TestStats): void;
onTestSkip(testStats: TestStats): void;
onTestPending(testStats: TestStats): void;
onTestEnd(testStats: TestStats): void;
onSuiteRetry(suiteStats: SuiteStats): void;
onSuiteEnd(suiteStats: SuiteStats): void;
onRunnerEnd(runnerStats: RunnerStats): void;
onBeforeCommand(commandArgs: BeforeCommandArgs): void;
onAfterCommand(commandArgs: AfterCommandArgs): void;
onBeforeAssertion(assertionArgs: unknown): void;
onAfterAssertion(assertionArgs: unknown): void;
}Structured data classes that capture and organize test execution metadata for suites, tests, hooks, and test runners.
class SuiteStats extends RunnableStats {
constructor(suite: Suite);
retry(): void;
}
class TestStats extends RunnableStats {
constructor(test: Test);
pass(): void;
skip(reason: string): void;
fail(errors?: Error[]): void;
}
class HookStats extends RunnableStats {
constructor(runner: Hook);
complete(errors?: Error[]): void;
}
class RunnerStats extends RunnableStats {
constructor(runner: Options.RunnerStart);
}Event interfaces and types that define the structure of data passed through the reporter event system.
interface BeforeCommandArgs extends CommandArgs {
body: unknown;
}
interface AfterCommandArgs extends CommandArgs {
result: unknown;
name?: string; // deprecated
}
interface CommandArgs {
sessionId: string;
method?: string;
endpoint?: string;
retries?: number;
command?: string;
params?: unknown;
}Helper functions for browser detection, string formatting, and color output.
function getBrowserName(caps: WebdriverIO.Capabilities): string;interface Tag {
name: string;
line: number;
}
interface Test {
type: 'test:start' | 'test:pass' | 'test:fail' | 'test:retry' | 'test:pending' | 'test:end' | 'test:skip';
title: string;
parent: string;
fullTitle: string;
pending: boolean;
file?: string;
body?: string;
duration?: number;
cid: string;
specs: string[];
uid: string;
pendingReason?: string;
error?: Error;
errors?: Error[];
retries?: number;
argument?: string | Argument;
state?: string;
}
interface Argument {
rows?: {
cells: string[];
}[];
}