Easiest way to run jest unit test cases in electron.
- Install
npm i --save-dev jest-electron
- Add to Jest config
In your package.json
{
"jest": {
+ "runner": "jest-electron/runner",
+ "testEnvironment": "jest-electron/environment"
}
}
Notice: update the runner
configure, not testRunner
.
- Update
.travis.yml
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
Keep the electron browser window for debugging. set env DEBUG_MODE=1
.
DEBUG_MODE=1 jest
MIT@hustcc.