2020-02-10 22:07:58 +00:00
|
|
|
# Testing on Headless CI Systems (Travis CI, Jenkins)
|
2016-02-24 20:19:43 +00:00
|
|
|
|
2016-02-28 16:38:32 +00:00
|
|
|
Being based on Chromium, Electron requires a display driver to function.
|
2018-05-08 05:16:09 +00:00
|
|
|
If Chromium can't find a display driver, Electron will fail to launch -
|
2016-02-28 16:38:32 +00:00
|
|
|
and therefore not executing any of your tests, regardless of how you are running
|
2022-01-18 17:02:35 +00:00
|
|
|
them. Testing Electron-based apps on Travis, CircleCI, Jenkins or similar Systems
|
2016-02-28 16:38:32 +00:00
|
|
|
requires therefore a little bit of configuration. In essence, we need to use
|
|
|
|
a virtual display driver.
|
2016-02-24 20:19:43 +00:00
|
|
|
|
|
|
|
## Configuring the Virtual Display Server
|
|
|
|
|
2016-02-28 16:38:32 +00:00
|
|
|
First, install [Xvfb](https://en.wikipedia.org/wiki/Xvfb).
|
|
|
|
It's a virtual framebuffer, implementing the X11 display server protocol -
|
|
|
|
it performs all graphical operations in memory without showing any screen output,
|
|
|
|
which is exactly what we need.
|
|
|
|
|
2019-06-21 21:19:21 +00:00
|
|
|
Then, create a virtual Xvfb screen and export an environment variable
|
2016-02-28 16:38:32 +00:00
|
|
|
called DISPLAY that points to it. Chromium in Electron will automatically look
|
|
|
|
for `$DISPLAY`, so no further configuration of your app is required.
|
2019-07-15 08:51:06 +00:00
|
|
|
This step can be automated with Anaïs Betts'
|
|
|
|
[xvfb-maybe](https://github.com/anaisbetts/xvfb-maybe): Prepend your test
|
2016-04-19 16:31:04 +00:00
|
|
|
commands with `xvfb-maybe` and the little tool will automatically configure
|
2019-06-21 21:19:21 +00:00
|
|
|
Xvfb, if required by the current system. On Windows or macOS, it will
|
2016-02-28 16:38:32 +00:00
|
|
|
do nothing.
|
2016-02-24 20:19:43 +00:00
|
|
|
|
2017-11-20 06:18:24 +00:00
|
|
|
```sh
|
2018-05-08 05:16:09 +00:00
|
|
|
## On Windows or macOS, this invokes electron-mocha
|
2016-02-24 20:19:43 +00:00
|
|
|
## On Linux, if we are in a headless environment, this will be equivalent
|
|
|
|
## to xvfb-run electron-mocha ./test/*.js
|
|
|
|
xvfb-maybe electron-mocha ./test/*.js
|
|
|
|
```
|
|
|
|
|
|
|
|
### Travis CI
|
2016-02-28 16:38:32 +00:00
|
|
|
|
2023-07-10 20:45:18 +00:00
|
|
|
For Travis, see its [docs on using Xvfb](https://docs.travis-ci.com/user/gui-and-headless-browsers/#using-xvfb-to-run-tests-that-require-a-gui).
|
2016-02-24 20:19:43 +00:00
|
|
|
|
|
|
|
### Jenkins
|
2016-02-28 16:38:32 +00:00
|
|
|
|
2016-04-19 16:31:04 +00:00
|
|
|
For Jenkins, a [Xvfb plugin is available](https://wiki.jenkins-ci.org/display/JENKINS/Xvfb+Plugin).
|
2016-02-24 20:19:43 +00:00
|
|
|
|
2022-01-18 17:02:35 +00:00
|
|
|
### CircleCI
|
2016-02-28 16:38:32 +00:00
|
|
|
|
2022-01-18 17:02:35 +00:00
|
|
|
CircleCI is awesome and has Xvfb and `$DISPLAY` already set up, so no further configuration is required.
|
2016-02-24 20:19:43 +00:00
|
|
|
|
|
|
|
### AppVeyor
|
2016-02-28 16:38:32 +00:00
|
|
|
|
|
|
|
AppVeyor runs on Windows, supporting Selenium, Chromium, Electron and similar
|
|
|
|
tools out of the box - no configuration is required.
|