# karma-electron **Repository Path**: mirrors_twilio/karma-electron ## Basic Information - **Project Name**: karma-electron - **Description**: Karma launcher and preprocessor for Electron - **Primary Language**: Unknown - **License**: Unlicense - **Default Branch**: stable-twilio - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2021-10-22 - **Last Updated**: 2025-09-21 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # karma-electron [![Build status](https://travis-ci.org/twolfson/karma-electron.svg?branch=master)](https://travis-ci.org/twolfson/karma-electron) [![Build status](https://ci.appveyor.com/api/projects/status/urgpvcip7kl9q2ih/branch/master?svg=true)](https://ci.appveyor.com/project/twolfson/karma-electron-launcher/branch/master) [Karma][] launcher and preprocessor for [Electron][] This was written to allow for directly testing in [Electron][] where we might want `require` to work automatically [Karma]: https://github.com/karma-runner/karma [Electron]: https://github.com/atom/electron **Features:** - Tested via CI on Linux and Windows - Support for Node.js integration in the renderer process (e.g. `node_modules`, `__filename`, relative paths for `require`) - Support for hidden browser windows - Support for isolated test runs to prevent cookie/localStorage pollution **Requirements:** - `karma>=1.1.0` to work within `electron's` security policy for shared context between parent/child windows - See https://github.com/karma-runner/karma/pull/1984 for more information **Notices:** - This plugin has been tested against `electron@0.37.4` and `electron@1.3.3` but should support the latest version - This plugin is best suited for testing the renderer portion of an `electron` application - For testing a full application, see `electron's` documentation on Selenium and WebDriver - https://github.com/electron/electron/blob/v1.3.6/docs/tutorial/using-selenium-and-webdriver.md ## Breaking changes in 5.0.0 We have corrected inaccuracies with `file://` behavior from Electron. For example: - `__filename` is now Karma's `context.html` - Relative paths for `require` resolve from Karma's `context.html` directory We have transferred support for this to the option `client.loadScriptsViaRequire` which loads scripts via `require` and has the original expected Node.js behavior For more information, see https://github.com/twolfson/karma-electron/issues/11 ## Getting Started On a project that has been set up with `karma init` already, install the module via: ```bash # Install our module and `electron` npm install karma-electron electron ``` Then, configure the module: ```js // Inside `karma.conf.js` browsers: ['Electron'] // If you would like Node.js integration support (e.g. `require`) // then, you must include this in `preprocessors` and `client` // DEV: preprocessors is for backfilling `__filename` and local `require` paths preprocessors: { '**/*.js': ['electron'] }, // DEV: `useIframe: false` is for launching a new window instead of using an iframe // In Electron, iframes don't get `nodeIntegration` priveleges yet windows do client: { useIframe: false } ``` Then, we can run Karma: ```bash karma start ``` ## Documentation ### Environment variables - ELECTRON_BIN - Override path to use for `electron` - By default, we will use path given by `electron` **Example:** ```bash ELECTRON_BIN=/usr/bin/electron karma start ``` ### Script configuration We support the following configurations: - client `Object` - Container for configuring child windows loaded from Karma - __filenameOverride `String` - Override `__filename` to be another path (e.g. `/path/to/my-index.html`) - This will also affect `__dirname` and `module.filename` as those are derived from `__filename` - By default, `__filename` will point to Karma's `context.html` - loadScriptsViaRequire `Boolean` - Load scripts via `require` instead of `