Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/facebook-atom/jest-electron-runner
custom test runner for Jest that allows tests to be run in Electron environment
https://github.com/facebook-atom/jest-electron-runner
Last synced: 3 months ago
JSON representation
custom test runner for Jest that allows tests to be run in Electron environment
- Host: GitHub
- URL: https://github.com/facebook-atom/jest-electron-runner
- Owner: facebook-atom
- License: mit
- Archived: true
- Created: 2018-07-02T00:26:30.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2021-04-05T14:45:15.000Z (over 3 years ago)
- Last Synced: 2024-07-18T08:47:37.231Z (4 months ago)
- Language: JavaScript
- Homepage:
- Size: 287 KB
- Stars: 188
- Watchers: 10
- Forks: 33
- Open Issues: 27
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
[![CircleCI](https://circleci.com/gh/facebook-atom/jest-electron-runner.svg?style=svg)](https://circleci.com/gh/facebook-atom/jest-electron-runner)
## Jest electron runner
A custom test runner for Jest that runs tests inside an [electron](https://electronjs.org/) main or renderer process providing the following benefits:- Main
- all electron instance modules (ipc, app, etc)- Renderer
- full access to a browser environment without the need for jsdom or similar modules## Getting Started
*NOTE: for `jest@23` use the older version `~@jest-runner/[email protected]`*
1. Install jest electron runner `yarn add @jest-runner/electron --dev`
2. Add one of these lines to your jest config (in `package.json` or inside your `jest.config.js` file), depending on the process you wish to test. If you wish to test them in parallel, see the tips section below.- Main process
```js
{
// ...
runner: '@jest-runner/electron/main',
testEnvironment: 'node',
}
```
- Renderer Process
```js
{
// ...
runner: '@jest-runner/electron',
testEnvironment: '@jest-runner/electron/environment',
}
```
3. run jest!
### Debugging
Normally jest-electron-runner runs a headless instance of electron when testing the renderer process. You may show the UI by adding this to your test:
```js
require('electron').remote.getCurrentWindow().show();
```### Tips
- The main process runner can be used to test any non-browser related code, which can speed up tests roughly 2x.
- To run the main and renderer process tests in parallel, you can provide a config object to the `projects` array in a jest javascript config file like so:
```js
// jest.config.js
const common = require('./jest.common.config')module.exports = {
projects: [
{
...common,
runner: '@jest-runner/electron/main',
testEnvironment: 'node',
testMatch: ['**/__tests__/**/*.(spec|test).ts']
},
{
...common,
runner: '@jest-runner/electron',
testEnvironment: '@jest-runner/electron/environment',
testMatch: ['**/__tests__/**/*.(spec|test).tsx']
}
]
}
```### [Code of Conduct](https://code.facebook.com/codeofconduct)
Facebook has adopted a Code of Conduct that we expect project participants to adhere to. Please read [the full text](https://code.facebook.com/codeofconduct) so that you can understand what actions will and will not be tolerated.
### [Contributing Guide](CONTRIBUTING.md)
Read our [contributing guide](CONTRIBUTING.md) to learn about our development process, how to propose bugfixes and improvements, and how to build and test your changes to Jest.
## License
[MIT licensed](./LICENSE).