A WebdriverIO runner to run tests locally within isolated worker processes
—
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.
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 });
});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;
}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 processGraceful 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 performedSignals that the worker process is ready to receive commands.
// Automatically sent when worker process starts
{
name: 'ready',
origin: 'worker'
}Reports when a command has finished executing.
// Sent after successful command execution
{
origin: 'worker',
name: 'finishedCommand',
content: {
command: string,
result: any
}
}Reports errors that occur during test execution.
// Sent when errors occur
{
origin: 'worker',
name: 'error',
content: {
name: string,
message: string,
stack: string
}
}// 1. Worker process starts
// 2. Runner imports and initializes
// 3. 'ready' message sent to main process
// 4. Worker begins listening for commands// 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// 1. Receive shutdown signal or command
// 2. Complete current operations
// 3. Clean up resources (browser sessions, etc.)
// 4. Exit with appropriate code// Invalid commands are ignored:
// - Missing command property
// - Non-existent runner method
// - Non-function runner method// 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// SIGINT handling:
// 1. Set sigintWasCalled flag
// 2. Allow current operations to complete
// 3. Exit gracefully with code 130
// 4. Main process detects worker terminationThe 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 requestsIntegration 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 reportingUses 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 statusConfigurable timeouts for shutdown operations.
// Uses SHUTDOWN_TIMEOUT constant (5000ms) for:
// - Graceful shutdown delay after SIGINT
// - Maximum wait time for cleanup operations
// - Preventing hanging worker processesInstall with Tessl CLI
npx tessl i tessl/npm-wdio--local-runner