or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

events.mdindex.mdreporter-base.mdstatistics.mdutilities.md
tile.json

tessl/npm-wdio--reporter

A WebdriverIO utility to help reporting all events with extensible base class for custom reporters

Workspace
tessl
Visibility
Public
Created
Last updated
Describes
npmpkg:npm/@wdio/reporter@9.19.x

To install, run

npx @tessl/cli install tessl/npm-wdio--reporter@9.19.0

index.mddocs/

WDIO Reporter

WDIO 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.

Package Information

  • Package Name: @wdio/reporter
  • Package Type: npm
  • Language: TypeScript
  • Installation: npm install @wdio/reporter

Core Imports

import 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");

Basic Usage

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`);
  }
}

Architecture

The WDIO Reporter system is built around several key components:

  • Base Reporter Class: WDIOReporter extends EventEmitter and provides the foundation for all custom reporters
  • Event System: Comprehensive event lifecycle covering test execution phases (runner, suite, hook, test events)
  • Statistics Classes: Structured data objects (SuiteStats, TestStats, HookStats, RunnerStats) for organizing test metadata
  • Output Management: Configurable output streams supporting both file and stdout writing
  • Event Handler Methods: Override-able methods for each event type providing processed event data

Capabilities

Reporter Base Class

The 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;
}

Reporter Base Class

Statistics Classes

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);
}

Statistics Classes

Event System

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;
}

Event System

Utility Functions

Helper functions for browser detection, string formatting, and color output.

function getBrowserName(caps: WebdriverIO.Capabilities): string;

Utility Functions

Types

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[];
  }[];
}