Skip to content
This repository has been archived by the owner on Apr 12, 2018. It is now read-only.

Commit

Permalink
Added test
Browse files Browse the repository at this point in the history
  • Loading branch information
MatthiasWinkelmann committed Mar 8, 2017
2 parents bc07512 + b64ca3d commit 78e74af
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 12 deletions.
7 changes: 5 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ FROM mhart/alpine-node:latest

LABEL description "Run Google Chrome's Lighthouse Audit in the background"

LABEL version="1.0.3"
LABEL version="1.0.5"

LABEL author="Matthias Winkelmann <[email protected]>"
LABEL coffee.matthi.vcs-url="https://github.com/MatthiasWinkelmann/lighthouse-chromium-alpine-docker"
Expand All @@ -27,7 +27,8 @@ RUN apk -U --no-cache upgrade && \
libx11\
xorg-server\
chromium\
ttf-opensans
ttf-opensans\
wait4ports
#-----------------
# Set ENV and change mode
#-----------------
Expand All @@ -45,6 +46,8 @@ ENV GEOMETRY "$SCREEN_WIDTH""x""$SCREEN_HEIGHT""x""$SCREEN_DEPTH"

RUN echo $TZ > /etc/timezone

RUN rc-update add dbus default

ADD lighthouse-chromium-xvfb.sh .
ADD test.sh .
RUN npm --global install yarn && yarn global add lighthouse
Expand Down
32 changes: 23 additions & 9 deletions lighthouse-chromium-xvfb.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,30 +6,44 @@ _kill_procs() {
kill -TERM $xvfb
}

# Setup a trap to catch SIGTERM and relay it to child processes
trap _kill_procs SIGTERM
/usr/bin/dbus-uuidgen --ensure=/etc/machine-id

XVFB_WHD=${XVFB_WHD:-1280x720x16}
# We need to test if /var/run/dbus exists, since script will fail if it does not

export DISPLAY=:99
[ ! -e /var/run/dbus ] && mkdir /var/run/dbus

start-stop-daemon --start --pidfile /var/run/dbus.pid --exec /usr/bin/dbus-daemon -- --system

# Setup a trap to catch SIGTERM and relay it to child processes
trap _kill_procs SIGTERM

TMP_PROFILE_DIR=`mktemp -d -t chromium.XXXXXX`
CHROME_DEBUGGING_PORT=9222

# Start Xvfb
dbus-run-session -- Xvfb :99 -ac -screen 0 $XVFB_WHD -nolisten tcp &
Xvfb ${DISPLAY} -ac -screen 0 ${GEOMETRY} -nolisten tcp &

xvfb=$!

while [ 1 -gt $xvfb ]; do echo "waiting for Xvfb to start: $xvfb"; sleep 1; done

echo "xvfb started"


dbus-run-session -- /usr/bin/chromium-browser --no-sandbox --user-data-dir=$TMP_PROFILE_DIR --start-maximized --no-first-run --remote-debugging-port=9222 "about:blank" &
echo "Starting chromium, with debugger on port $CHROME_DEBUGGING_POST"
/usr/bin/chromium-browser \
--no-sandbox \
--user-data-dir=${TMP_PROFILE_DIR} \
--disable-webgl \
--start-maximized \
--remote-debugging-port=${CHROME_DEBUGGING_PORT} \
--no-first-run "about:blank" &

chromium=$!

while [ 1 -gt $chromium ]; do echo "waiting for chromium to start"; sleep 1; done
wait4ports tcp://127.0.0.1:$CHROME_DEBUGGING_PORT

echo "chromium started"

lighthouse --port=9222 --disable-webgl --skip-autolaunch --disable-cpu-throttling=true $@
lighthouse --port=${CHROME_DEBUGGING_PORT} \
--skip-autolaunch \
--disable-cpu-throttling=true $@
3 changes: 2 additions & 1 deletion test.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/bin/sh

/lighthouse/lighthouse-chromium-xvfb.sh --output-path=/tmp/test-report.html "https://matthi.coffee"
./lighthouse-chromium-xvfb.sh --output-path=/tmp/test-report.html https://matthi.coffee

grep -q "Best Practices" /tmp/test-report*

0 comments on commit 78e74af

Please sign in to comment.