or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

cli.mdindex.mdprogrammatic.md
tile.json

cli.mddocs/

Command-Line Interface

Complete command-line interface for running Mocha tests within Electron environments, supporting both main process and renderer process testing with extensive configuration options.

Capabilities

Basic Command Structure

The electron-mocha command serves as a drop-in replacement for the standard mocha command with additional Electron-specific options.

electron-mocha [options] [files...]

Usage Examples:

# Run all tests in test/ directory (main process)
electron-mocha

# Run specific test files
electron-mocha test/unit/*.js test/integration/*.js

# Run tests with custom test pattern
electron-mocha "test/**/*.spec.js"

Electron-Specific Options

Options that control Electron behavior and test execution environment.

--renderer              # Run tests in renderer process [boolean]
--require-main, --main  # Require module in main process [array]
--script               # Load module in renderer via script tag [array]
--interactive          # Show renderer tests in persistent window [boolean]
--url, --index         # Load custom URL in renderer [string]
--preload              # Load module during renderer preload [string]
--window-config        # Supply custom Electron window options [string]
-W, --warnings         # Print renderer warnings to console [boolean]
--show-window          # Show the window during tests [boolean]
--inspect              # Enable debugger on port (default 5858) [number]

Usage Examples:

# Run tests in renderer process
electron-mocha --renderer test/

# Load custom modules in main process
electron-mocha --require-main ./setup.js --require-main ./mocks.js

# Load scripts in renderer process via script tags
electron-mocha --renderer --script ./test/utils.js --script ./test/fixtures.js

# Run tests with custom HTML page
electron-mocha --renderer --url file://$(pwd)/test/custom.html

# Run with preload script
electron-mocha --renderer --preload ./test/preload.js

# Run with custom window configuration
electron-mocha --renderer --window-config ./test/window.json

# Run with debugging enabled
electron-mocha --renderer --inspect --interactive

# Show window during tests (useful for visual debugging)
electron-mocha --renderer --show-window --interactive

# Enable renderer warnings in console
electron-mocha --renderer --warnings

Standard Mocha Options

All standard Mocha command-line options are supported and passed through to the underlying Mocha instance.

--reporter, -R         # Test reporter [string]
--grep, -g            # Only run tests matching pattern [string]
--timeout, -t         # Test timeout in milliseconds [number]
--recursive           # Include sub-directories [boolean]
--watch, -w           # Watch files for changes [boolean]
--config              # Path to config file [string]
--require, -r         # Require modules before running tests [array]
--exit                # Force exit after tests complete [boolean]
--bail, -b            # Stop on first test failure [boolean]
--reporter-option     # Reporter-specific options [string]
--slow                # Slow test threshold in milliseconds [number]
--no-colors           # Disable colored output [boolean]
--full-trace          # Display full stack traces [boolean]

Usage Examples:

# Use different reporter
electron-mocha --reporter json test/

# Run only tests matching pattern
electron-mocha --grep "API tests" test/

# Set custom timeout
electron-mocha --timeout 5000 test/

# Watch mode with recursive directory scanning
electron-mocha --watch --recursive test/

Configuration Files

Electron Mocha supports Mocha configuration files with additional Electron-specific options.

// .mocharc.json example
{
  "reporter": "spec",
  "timeout": 5000,
  "require": ["test/setup.js"],
  "renderer": true,
  "interactive": false,
  "show-window": false
}

// .mocharc.js example
module.exports = {
  reporter: 'spec',
  timeout: 5000,
  'require-main': ['./test/main-setup.js'],
  renderer: true,
  preload: './test/preload.js'
};

Environment Setup

Configuration for Electron executable location and runtime environment.

# Set custom Electron path
export ELECTRON_PATH=/path/to/electron

# Use with system-installed Electron
npm install -g electron
electron-mocha test/

# Use with local Electron installation
npm install electron --save-dev
npx electron-mocha test/

Exit Codes

Standard exit codes for integration with CI/CD systems and build tools.

# Exit codes
0    # All tests passed
1    # Test failures or errors occurred
130  # Process terminated by SIGINT (Ctrl+C)

Debugging Support

Built-in debugging capabilities for both main and renderer processes.

# Enable Node.js debugger for main process tests
electron-mocha --inspect test/main/

# Enable Chrome DevTools for renderer process tests
electron-mocha --renderer --inspect test/renderer/

# Interactive mode with persistent window
electron-mocha --renderer --interactive --show-window test/

# Custom debug port
electron-mocha --inspect=9229 test/

Usage Examples:

# Debug renderer tests with DevTools
electron-mocha --renderer --inspect --interactive test/renderer/

# Debug main process with external debugger
electron-mocha --inspect test/main/ &
# Connect with: node --inspect-brk=9229

# Keep window open for manual inspection
electron-mocha --renderer --show-window --interactive test/

CI/CD Integration

Configuration for continuous integration environments and headless testing.

# XVFB for Linux CI environments
xvfb-run electron-mocha --renderer test/

# Disable GPU for CI environments
electron-mocha --main ignore-gpu-blacklist.js --renderer test/

Usage Examples:

# GitHub Actions example
- name: Run tests
  run: xvfb-run --auto-servernum electron-mocha --renderer test/
  env:
    DISPLAY: ':99'

# Travis CI example
before_script:
  - export DISPLAY=':99.0'
  - Xvfb :99 -screen 0 1024x768x24 > /dev/null 2>&1 &
script:
  - electron-mocha --renderer test/

WebGL Testing

Special configuration for testing WebGL and GPU-accelerated functionality.

# Enable WebGL in headless environments
electron-mocha --main ignore-gpu-blacklist.js --renderer test/webgl/

ignore-gpu-blacklist.js example:

const { app } = require('electron');
app.commandLine.appendSwitch('ignore-gpu-blacklist');