jest-electron:在 electron 浏览器环境运行 jest 单测

jest-electron

Easiest way to run jest unit test cases in electron.

Usage

  • 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

Debugger mode

Keep the electron browser window for debugging. set env INTERACTIVE=1
.

INTERACTIVE=1 jest

License

MIT@ hustcc
.