README
jest-electron
Easiest way to run jest unit test cases in electron.
When we run unit test in Jest, it is actually running in the node environment, or virtual browser environment(e.g. JSDOM
) mocked by NodeJS. Sometimes we need a lot of Jest mocks for running code with no throw, such as: jest-canvas-mock, jest-storage-mock, @jest/fake-timers and so on. This is solved by Jest-Electron
.
- Technological ecology of
Jest
. - Complete and real
browser environment
. Multi-renderer
for running performance.Running and debug
is better then mock.
Installation
- Add into devDependencies
npm i --save-dev jest-electron
- Update Jest config
{
"jest": {
+ "runner": "jest-electron/runner",
+ "testEnvironment": "jest-electron/environment"
}
}
Notice: update the runner
configure, not testRunner
.
GitHub Action
Running on macOS
will be ok.
- runs-on: ubuntu-latest
+ runs-on: macOS-latest
Travis
Update .travis.yml
with electron supported.
language: node_js
node_js:
- "8"
- "9"
- "10"
- "11"
- "12"
+ addons:
+ apt:
+ packages:
+ - xvfb
+ install:
+ - export DISPLAY=':99.0'
+ - Xvfb :99 -screen 0 1024x768x24 > /dev/null 2>&1 &
+ - npm install
script:
- npm run test
Debugger mode
Keep the electron browser window for debugging. set env DEBUG_MODE=1
.
DEBUG_MODE=1 jest
License
MIT@hustcc.