CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/npm-wdio--spec-reporter

A WebdriverIO plugin to report in spec style

Pending
Overview
Eval results
Files

lifecycle.mddocs/

Lifecycle Events

Event-driven lifecycle methods that handle WebdriverIO test execution events and update reporter state.

Capabilities

Runner Lifecycle Events

Methods for handling test runner start and end events.

/**
 * Handle test runner start event
 * Sets up preface and initializes runner-level state
 * @param runner - Runner statistics and configuration
 */
onRunnerStart(runner: RunnerStats): void;

/**
 * Handle test runner end event  
 * Triggers final report generation and output
 * @param runner - Final runner statistics
 */
onRunnerEnd(runner: RunnerStats): void;

Usage Examples:

import SpecReporter from "@wdio/spec-reporter";

class CustomReporter extends SpecReporter {
  onRunnerStart(runner) {
    console.log(`Starting tests on ${runner.capabilities.browserName}`);
    super.onRunnerStart(runner);
  }
  
  onRunnerEnd(runner) {
    super.onRunnerEnd(runner);
    console.log(`Tests completed in ${runner._duration}ms`);
  }
}

Suite Lifecycle Events

Methods for handling test suite start, end, and retry events.

/**
 * Handle suite start event
 * Manages indentation levels and suite tracking
 * @param suite - Suite statistics and metadata
 */
onSuiteStart(suite: SuiteStats): void;

/**
 * Handle suite end event
 * Decreases indentation and resets suite-level state
 */
onSuiteEnd(): void;

/**
 * Handle suite retry event
 * Updates retry counts and manages suite retry state
 */
onSuiteRetry(): void;

Usage Examples:

// Suite events are called automatically by WebdriverIO
// Internal state management:
// - Tracks suite indentation levels for nested output
// - Maintains suite execution order
// - Handles retry logic and count updates

class DebugReporter extends SpecReporter {
  onSuiteStart(suite) {
    console.log(`Suite started: ${suite.title}`);
    super.onSuiteStart(suite);
  }
  
  onSuiteRetry() {
    console.log('Suite is being retried');
    super.onSuiteRetry();
  }
}

Test Lifecycle Events

Methods for handling individual test execution events.

/**
 * Handle test start event
 * Resets test-level state including console output capture
 */
onTestStart(): void;

/**
 * Handle test pass event
 * Updates pass count and captures console logs
 * @param testStat - Test statistics and results
 */
onTestPass(testStat: TestStats): void;

/**
 * Handle test failure event
 * Updates failure count and captures error details
 * @param testStat - Test statistics and error information
 */
onTestFail(testStat: TestStats): void;

/**
 * Handle test skip event
 * Updates skip count and captures pending reasons
 * @param testStat - Test statistics and skip reason
 */
onTestSkip(testStat: TestStats): void;

/**
 * Handle test pending event
 * Updates pending count and captures pending reasons
 * @param testStat - Test statistics and pending information
 */
onTestPending(testStat: TestStats): void;

Usage Examples:

// Test events automatically update internal counters:
// - Passed test count
// - Failed test count  
// - Skipped test count
// - Pending test count
// - Console log capture (if enabled)

class VerboseReporter extends SpecReporter {
  onTestPass(testStat) {
    super.onTestPass(testStat);
    console.log(`✓ ${testStat.title} passed`);
  }
  
  onTestFail(testStat) {
    super.onTestFail(testStat);
    console.log(`✗ ${testStat.title} failed: ${testStat.error?.message}`);
  }
}

Hook Lifecycle Events

Methods for handling test hook execution events.

/**
 * Handle hook end event
 * Tracks hook failures and updates error counts
 * @param hook - Hook statistics and execution results  
 */
onHookEnd(hook: HookStats): void;

Usage Examples:

// Hook events handle before/after hooks:
// - beforeAll, afterAll
// - beforeEach, afterEach
// - Custom hooks

class HookTracker extends SpecReporter {
  onHookEnd(hook) {
    super.onHookEnd(hook);
    if (hook.error) {
      console.log(`Hook "${hook.title}" failed: ${hook.error.message}`);
    }
  }
}

State Management

Internal state tracking for test execution statistics.

interface StateCount {
  /** Count of passed tests */
  passed: number;
  /** Count of failed tests */
  failed: number;
  /** Count of skipped tests */
  skipped: number;
  /** Count of pending tests */
  pending: number;
  /** Count of retried tests */
  retried: number;
}

Event Flow Example

// Typical event flow for a test suite:
// 1. onRunnerStart(runner)
// 2. onSuiteStart(suite)
// 3.   onTestStart()
// 4.   onTestPass(test) | onTestFail(test) | onTestSkip(test)
// 5.   onHookEnd(hook) // if hooks are present
// 6. onSuiteEnd()
// 7. onRunnerEnd(runner)

// For retried suites:
// 1. onRunnerStart(runner)
// 2. onSuiteStart(suite)
// 3.   // ... tests fail
// 4. onSuiteRetry()
// 5.   // ... tests retry
// 6. onSuiteEnd()
// 7. onRunnerEnd(runner)

Real-time Event Handling

When realtime reporting is enabled, events trigger immediate output.

/**
 * Print current test status in real-time
 * Called during test execution if realtimeReporting is enabled
 * @param stat - Current test, hook, or suite statistics
 */
printCurrentStats(stat: TestStats | HookStats | SuiteStats): void;

Usage Examples:

// Enable realtime reporting
const reporter = new SpecReporter({
  realtimeReporting: true
});

// Real-time output shows:
// [chrome 91 macOS #0-0] ------------------------------------------------------------------
// [chrome 91 macOS #0-0] Suite started: 
// [chrome 91 macOS #0-0]   » /tests/login.test.js
// [chrome 91 macOS #0-0]    ✓ should display login form » [ /tests/login.test.js ]
// [chrome 91 macOS #0-0]    ✗ should authenticate user » [ /tests/login.test.js ]

Install with Tessl CLI

npx tessl i tessl/npm-wdio--spec-reporter

docs

configuration.md

formatting.md

index.md

lifecycle.md

sauce-labs.md

tile.json