May 25, 2021 Electron
Electron is chromium-based, so a display driver is required to make it work. I f Chromium can't find a display driver, ELectron fails to start, so no matter how you run it, Electron won't perform any of your tests. W hen testing Electron-based applications on Travis, Circle, Jenkins, or similar systems, some configuration is required. Essentially, we need to use a virtual display driver.
Start by installing Xvfb. T his is a virtual framebuffer that implements the X11 display service protocol, where all graphics operations are performed in memory without the need to appear on any screen output device. That's exactly what we need.
Then create a virtual xvfb screen and export an environment variable called DISPLAY that
DISPLAY
to him. C
hromium in Electron automatically looks for
$DISPLAY
your app doesn't need to be configured longer. T
his step can be automated with Paul Betts'
xvfb-maybe:
if the system needs to, add your test command
xvfb-maybe
and the gadget automatically sets xvfb.
Under Windows or macOS, it doesn't do anything.
## 在 Windows 或者 macOS,这只是调用 electron-mocha
## 在 Linux, 如果我们在 headless 环境,这将是等同于
## xvfb-run electron-mocha ./test/*.js
xvfb-maybe electron-mocha ./test/*.js
On Travis, your
.travis.yml
similar to the following code:
addons:
apt:
packages:
- xvfb
install:
- export DISPLAY=':99.0'
- Xvfb :99 -screen 0 1024x768x24 > /dev/null 2>&1 &
Under Jenkins, there is an Xvfb plug-in available.
Circle CI is great and has xvfb, but $DISPLAY
$DISPLAY
so you don't need to set it up longer.
AppVeyor runs on Windows and supports Selenium, Chromium, Electron and a number of similar tools out of the box without configuration.