2020-02-10 14:07:58 -08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								# Testing on Headless CI Systems (Travis CI, Jenkins)
							 | 
						
					
						
							
								
									
										
										
										
											2016-02-24 12:19:43 -08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2016-02-29 01:38:32 +09:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								Being based on Chromium, Electron requires a display driver to function.
							 | 
						
					
						
							
								
									
										
										
										
											2018-05-08 00:16:09 -05:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								If Chromium can't find a display driver, Electron will fail to launch -
							 | 
						
					
						
							
								
									
										
										
										
											2016-02-29 01:38:32 +09:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								and therefore not executing any of your tests, regardless of how you are running
							 | 
						
					
						
							
								
									
										
										
										
											2022-01-18 12:02:35 -05:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								them. Testing Electron-based apps on Travis, CircleCI, Jenkins or similar Systems
							 | 
						
					
						
							
								
									
										
										
										
											2016-02-29 01:38:32 +09:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								requires therefore a little bit of configuration. In essence, we need to use
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								a virtual display driver.
							 | 
						
					
						
							
								
									
										
										
										
											2016-02-24 12:19:43 -08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								## Configuring the Virtual Display Server
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2016-02-29 01:38:32 +09: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 16:19:21 -05:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								Then, create a virtual Xvfb screen and export an environment variable
							 | 
						
					
						
							
								
									
										
										
										
											2016-02-29 01:38:32 +09: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 01:51:06 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								This step can be automated with Anaïs Betts'
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								[xvfb-maybe](https://github.com/anaisbetts/xvfb-maybe): Prepend your test
							 | 
						
					
						
							
								
									
										
										
										
											2016-04-19 09:31:04 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								commands with `xvfb-maybe` and the little tool will automatically configure
							 | 
						
					
						
							
								
									
										
										
										
											2019-06-21 16:19:21 -05:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								Xvfb, if required by the current system. On Windows or macOS, it will
							 | 
						
					
						
							
								
									
										
										
										
											2016-02-29 01:38:32 +09:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								do nothing.
							 | 
						
					
						
							
								
									
										
										
										
											2016-02-24 12:19:43 -08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2017-11-20 14:18:24 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								```sh
							 | 
						
					
						
							
								
									
										
										
										
											2018-05-08 00:16:09 -05:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								## On Windows or macOS, this invokes electron-mocha
							 | 
						
					
						
							
								
									
										
										
										
											2016-02-24 12:19:43 -08: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-29 01:38:32 +09:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2023-07-10 16:45:18 -04: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 12:19:43 -08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								### Jenkins
							 | 
						
					
						
							
								
									
										
										
										
											2016-02-29 01:38:32 +09:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2016-04-19 09:31:04 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								For Jenkins, a [Xvfb plugin is available](https://wiki.jenkins-ci.org/display/JENKINS/Xvfb+Plugin).
							 | 
						
					
						
							
								
									
										
										
										
											2016-02-24 12:19:43 -08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2022-01-18 12:02:35 -05:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								### CircleCI
							 | 
						
					
						
							
								
									
										
										
										
											2016-02-29 01:38:32 +09:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2022-01-18 12:02:35 -05:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								CircleCI is awesome and has Xvfb and `$DISPLAY` already set up, so no further configuration is required.
							 | 
						
					
						
							
								
									
										
										
										
											2016-02-24 12:19:43 -08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								### AppVeyor
							 | 
						
					
						
							
								
									
										
										
										
											2016-02-29 01:38:32 +09:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								AppVeyor runs on Windows, supporting Selenium, Chromium, Electron and similar
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								tools out of the box - no configuration is required.
							 |