CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/npm-wdio--local-runner

A WebdriverIO runner to run tests locally within isolated worker processes

Pending
Overview
Eval results
Files

worker-process-execution.mddocs/

Worker Process Execution

Worker child process executor that runs the actual test framework in isolated processes. This module is exported from the ./run entry point and used internally by WorkerInstance for test execution.

Capabilities

Runner Instance

The main runner instance used within worker child processes to execute tests and handle framework operations.

/**
 * Runner interface extending NodeJS EventEmitter
 * Used within worker child processes for test execution
 */
interface RunnerInterface extends NodeJS.EventEmitter {
  sigintWasCalled: boolean;
  [key: string]: unknown;
}

/**
 * Runner instance for executing tests within worker processes
 * Automatically handles command processing and framework integration
 */
const runner: RunnerInterface;

Usage Example:

// This module is primarily used internally by @wdio/local-runner
// It's automatically imported and used by WorkerInstance

import { runner } from "@wdio/local-runner/run";

// The runner handles test execution within worker processes
// and communicates with the main process via IPC

// Listen for exit events
runner.on('exit', (code) => {
  console.log(`Test execution completed with code: ${code}`);
});

// Listen for error events  
runner.on('error', ({ name, message, stack }) => {
  console.error('Test execution error:', { name, message, stack });
});

Architecture and Integration

IPC Message Handling

The runner automatically processes messages from the main LocalRunner process.

// The runner listens for IPC messages and executes corresponding commands
// Message format follows Workers.WorkerCommand interface:
interface WorkerCommand {
  cid: string;
  command: string;
  configFile: string;
  args: Workers.WorkerMessageArgs;
  caps: WebdriverIO.Capabilities;
  specs: string[];
  retries: number;
}

Framework Integration

The runner integrates with the @wdio/runner package to execute test frameworks.

// Internal integration with @wdio/runner
// - Processes test execution commands
// - Handles framework-specific operations
// - Manages browser session lifecycle
// - Reports results back to main process

Signal Handling

Graceful shutdown handling for worker processes.

// SIGINT handling
runner.sigintWasCalled = false;

// When SIGINT is received:
// 1. sigintWasCalled is set to true
// 2. Graceful exit with code 130 is initiated
// 3. Cleanup operations are performed

Event System

Ready Event

Signals that the worker process is ready to receive commands.

// Automatically sent when worker process starts
{
  name: 'ready',
  origin: 'worker'
}

Command Completion

Reports when a command has finished executing.

// Sent after successful command execution
{
  origin: 'worker',
  name: 'finishedCommand',
  content: {
    command: string,
    result: any
  }
}

Error Reporting

Reports errors that occur during test execution.

// Sent when errors occur
{
  origin: 'worker',
  name: 'error',
  content: {
    name: string,
    message: string,
    stack: string
  }
}

Lifecycle Management

Process Startup

// 1. Worker process starts
// 2. Runner imports and initializes
// 3. 'ready' message sent to main process
// 4. Worker begins listening for commands

Command Execution

// 1. Receive WorkerCommand via IPC
// 2. Validate command and parameters
// 3. Execute corresponding runner method
// 4. Send 'finishedCommand' with results
// 5. Continue listening for next command

Graceful Shutdown

// 1. Receive shutdown signal or command
// 2. Complete current operations
// 3. Clean up resources (browser sessions, etc.)
// 4. Exit with appropriate code

Error Handling

Command Validation

// Invalid commands are ignored:
// - Missing command property
// - Non-existent runner method
// - Non-function runner method

Execution Errors

// Failed test executions:
// 1. Log error with stack trace
// 2. Report error to main process
// 3. Exit worker process with code 1
// 4. Allow main process to handle retry logic

Signal Interruption

// SIGINT handling:
// 1. Set sigintWasCalled flag
// 2. Allow current operations to complete
// 3. Exit gracefully with code 130
// 4. Main process detects worker termination

Integration Points

Main Process Communication

The runner communicates with LocalRunner through IPC messaging.

// Outbound messages to main process:
// - ready: Worker is ready for commands
// - finishedCommand: Command execution completed
// - error: Error occurred during execution

// Inbound messages from main process:
// - WorkerCommand: Execute specific test operations
// - Configuration updates
// - Shutdown requests

Framework Execution

Integration with @wdio/runner for actual test framework execution.

// The runner delegates to @wdio/runner for:
// - Test file discovery and loading
// - Browser session management  
// - Framework-specific test execution
// - Result collection and reporting

Advanced Features

Exit Hook Integration

Uses exit-hook package for graceful shutdown handling.

// Async exit hooks allow cleanup operations:
// - Close browser sessions
// - Save test artifacts
// - Clean up temporary files
// - Report final status

Timeout Management

Configurable timeouts for shutdown operations.

// Uses SHUTDOWN_TIMEOUT constant (5000ms) for:
// - Graceful shutdown delay after SIGINT
// - Maximum wait time for cleanup operations
// - Preventing hanging worker processes

Install with Tessl CLI

npx tessl i tessl/npm-wdio--local-runner

docs

index.md

runner-management.md

stream-debugging.md

worker-management.md

worker-process-execution.md

tile.json