or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

cli.mdindex.mdprogrammatic.md
tile.json

index.mddocs/

Electron Mocha

Electron Mocha is a command-line testing tool that enables running Mocha test suites within Electron environments. It provides the capability to test JavaScript applications in real browser contexts and specifically test Electron desktop applications, supporting both main process (Node.js environment) and renderer process (Chromium browser environment) testing.

Package Information

  • Package Name: electron-mocha
  • Package Type: npm
  • Language: JavaScript
  • Installation: npm install -g electron-mocha

Core Imports

For programmatic usage:

const { main } = require("electron-mocha/lib/main");

For CLI usage:

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

Basic Usage

# Run tests in main process (Node.js environment)
electron-mocha test/

# Run tests in renderer process (browser environment with DOM)
electron-mocha --renderer test/

# Run tests with debugging enabled
electron-mocha --renderer --inspect test/

# Run tests in interactive mode (window stays open)
electron-mocha --renderer --interactive test/

Architecture

Electron Mocha is built around several key components:

  • CLI Interface: Command-line wrapper that spawns Electron with test configuration
  • Main Process Runner: Executes tests in Node.js environment within Electron's main process
  • Renderer Process Runner: Executes tests in Chromium environment within Electron's renderer process
  • IPC Bridge: Handles communication between main and renderer processes for test results
  • Configuration System: Extends Mocha's configuration with Electron-specific options

Capabilities

Command-Line Interface

Complete command-line interface for running Mocha tests within Electron environments, with all standard Mocha options plus Electron-specific configuration.

// CLI executable
electron-mocha [options] [files...]

// Core Electron-specific options
--renderer              // Run tests in renderer process
--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
--url, --index         // Load custom URL in renderer [string]
--preload              // Load module during renderer preload [string]
--window-config        // Custom Electron window options [string]
--warnings, -W         // Print renderer warnings to console
--show-window          // Show the window during tests
--inspect              // Enable debugger (default port 5858)

Command-Line Interface

Programmatic API

Core programmatic interface for integrating Electron Mocha into custom tooling and build systems.

/**
 * Main entry point module for programmatic usage
 */
const main: {
  /**
   * Main entry point function for programmatic usage
   * @param argv - Command line arguments array
   */
  main(argv?: string[]): void;
};

/**
 * Test execution handler from run module
 * @param argv - Parsed command line options
 */
async function handler(argv: ElectronMochaOptions): Promise<void>;

// See ElectronMochaOptions in Types section below

Programmatic API

Environment Variables

Environment variables for configuring Electron executable location and runtime behavior.

// Environment variables
ELECTRON_PATH          // Path to Electron executable
ELECTRON_RUN_AS_NODE  // Used internally for cleanup processes

Types

interface ElectronMochaOptions {
  // Electron-specific options
  renderer?: boolean;
  'require-main'?: string[];
  script?: string[];
  interactive?: boolean;
  url?: string;
  preload?: string;
  'window-config'?: string;
  warnings?: boolean;
  'show-window'?: boolean;
  inspect?: boolean | number;
  
  // Standard Mocha options also supported
  reporter?: string;
  grep?: string;
  timeout?: number;
  recursive?: boolean;
  watch?: boolean;
  config?: string;
  require?: string[];
  exit?: boolean;
  bail?: boolean;
  slow?: number;
  color?: boolean;
  // All other standard Mocha CLI options supported
}

interface WindowConfig {
  width?: number;
  height?: number;
  webPreferences?: {
    enableRemoteModule?: boolean;
    contextIsolation?: boolean;
    nodeIntegration?: boolean;
    preload?: string;
  };
  // All BrowserWindow options supported
}