Problem
In the past, I ran headless browser tests with Travis CI:
# .travis.yml
addons:
chrome: stable
services:
- xvfb
language: node_js
node_js:
- stable
install:
- npm install
before_script:
- export DISPLAY=:99.0
script:
- npm test
After moving to GitHub Actions:
# .github/workflows/build.yml
on: [push]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
with:
node-version: 14
- run: npm install
- run: npm test
I found that I still needed to add xvfb
due to the errors:
Cannot start Chrome
Chrome stderr: [ERROR:browser_main_loop.cc(1434)] Unable to open X display.
Solution
I replaced - run: npm test
with the solution:
- run: sudo apt-get install xvfb
- run: xvfb-run --auto-servernum npm test
Which was replaced with the XVFB GitHub Action:
- name: Run headless test
uses: GabrielBB/xvfb-action@v1
with:
run: npm test