CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/npm-wdio--reporter

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

Pending
Overview
Eval results
Files

reporter-base.mddocs/

Reporter Base Class

The WDIOReporter base class provides the foundation for creating custom WebdriverIO reporters with comprehensive event handling and output management capabilities.

Capabilities

WDIOReporter Class

The main base class that custom reporters extend, providing event-driven architecture and output stream management.

/**
 * Base class for creating custom WebdriverIO reporters
 * Extends EventEmitter to provide comprehensive event handling
 */
export default class WDIOReporter extends EventEmitter {
  // Properties
  outputStream: WriteStream | CustomWriteStream;
  failures: number;
  suites: Record<string, SuiteStats>;
  hooks: Record<string, HookStats>;
  tests: Record<string, TestStats>;
  currentSuites: SuiteStats[];
  counts: {
    suites: number;
    tests: number;
    hooks: number;
    passes: number;
    skipping: number;
    failures: number;
    pending: number;
  };
  retries: number;
  runnerStat?: RunnerStats;
  isContentPresent: boolean;
  specs: string[];
  currentSpec?: string;
  
  /**
   * Constructor for WDIOReporter
   * @param options - Reporter configuration options
   */
  constructor(options: Partial<Reporters.Options>);
}

interface CustomWriteStream {
  write: (content: unknown) => boolean;
}

Usage Example:

import WDIOReporter from "@wdio/reporter";
import type { Reporters } from "@wdio/types";

export class MyReporter extends WDIOReporter {
  constructor(options: Partial<Reporters.Options>) {
    super(options);
    console.log('Custom reporter initialized');
  }
}

Output Management

Methods for managing reporter output streams and content writing.

/**
 * Write content to the reporter's output stream
 * @param content - Content to write (any type)
 */
write(content: unknown): void;

/**
 * Indicates if reporter has completed all async operations
 * Used to control process shutdown timing
 * @returns true if reporter can safely terminate
 */
get isSynchronised(): boolean;

Usage Example:

export class FileReporter extends WDIOReporter {
  onTestPass(testStats: TestStats) {
    this.write(`✓ ${testStats.fullTitle}\n`);
  }

  onTestFail(testStats: TestStats) {
    this.write(`✗ ${testStats.fullTitle}\n`);
    if (testStats.error) {
      this.write(`  ${testStats.error.message}\n`);
    }
  }
}

Runner Event Handlers

Event handlers for test runner lifecycle events.

/**
 * Called when test runner starts
 * @param runnerStats - Statistics about the test runner
 */
onRunnerStart(runnerStats: RunnerStats): void;

/**
 * Called when test runner ends
 * @param runnerStats - Final statistics about the test runner
 */
onRunnerEnd(runnerStats: RunnerStats): void;

Suite Event Handlers

Event handlers for test suite lifecycle events.

/**
 * Called when test suite starts
 * @param suiteStats - Statistics about the suite
 */
onSuiteStart(suiteStats: SuiteStats): void;

/**
 * Called when test suite ends
 * @param suiteStats - Final statistics about the suite
 */
onSuiteEnd(suiteStats: SuiteStats): void;

/**
 * Called when test suite is retried (Cucumber only)
 * @param suiteStats - Statistics about the retried suite
 */
onSuiteRetry(suiteStats: SuiteStats): void;

Test Event Handlers

Event handlers for individual test lifecycle events.

/**
 * Called when test starts
 * @param testStats - Statistics about the test
 */
onTestStart(testStats: TestStats): void;

/**
 * Called when test passes
 * @param testStats - Statistics about the passed test
 */
onTestPass(testStats: TestStats): void;

/**
 * Called when test fails
 * @param testStats - Statistics about the failed test
 */
onTestFail(testStats: TestStats): void;

/**
 * Called when test is retried
 * @param testStats - Statistics about the retried test
 */
onTestRetry(testStats: TestStats): void;

/**
 * Called when test is skipped
 * @param testStats - Statistics about the skipped test
 */
onTestSkip(testStats: TestStats): void;

/**
 * Called when test is pending
 * @param testStats - Statistics about the pending test
 */
onTestPending(testStats: TestStats): void;

/**
 * Called when test ends (regardless of result)
 * @param testStats - Final statistics about the test
 */
onTestEnd(testStats: TestStats): void;

Hook Event Handlers

Event handlers for test hook (before/after) lifecycle events.

/**
 * Called when hook starts
 * @param hookStats - Statistics about the hook
 */
onHookStart(hookStats: HookStats): void;

/**
 * Called when hook ends
 * @param hookStats - Final statistics about the hook
 */
onHookEnd(hookStats: HookStats): void;

Command Event Handlers

Event handlers for WebDriver command execution events.

/**
 * Called before WebDriver command execution
 * @param commandArgs - Command arguments and metadata
 */
onBeforeCommand(commandArgs: BeforeCommandArgs): void;

/**
 * Called after WebDriver command execution
 * @param commandArgs - Command arguments, metadata, and results
 */
onAfterCommand(commandArgs: AfterCommandArgs): void;

Assertion Event Handlers

Event handlers for assertion execution events.

/**
 * Called before assertion execution
 * @param assertionArgs - Assertion arguments and metadata
 */
onBeforeAssertion(assertionArgs: unknown): void;

/**
 * Called after assertion execution
 * @param assertionArgs - Assertion arguments, metadata, and results
 */
onAfterAssertion(assertionArgs: unknown): void;

Configuration Options

interface Reporters.Options {
  stdout?: boolean;
  logFile?: string;
  writeStream?: CustomWriteStream;
  outputDir?: string;
}

The reporter constructor accepts configuration options to control output behavior:

  • stdout: Write to standard output
  • logFile: Path to log file for output
  • writeStream: Custom write stream for output
  • outputDir: Directory for output files (created if it doesn't exist)

Install with Tessl CLI

npx tessl i tessl/npm-wdio--reporter

docs

events.md

index.md

reporter-base.md

statistics.md

utilities.md

tile.json