Skip to content
This repository was archived by the owner on Aug 6, 2018. It is now read-only.

Commit 03e1bd1

Browse files
committed
Upgrade to Backstop 3.x and Chrome Headless. Fixes #4
- Switched to node:8.5.0-alpine (Alpine 3.6) - Using the latest Chromium version from alpine/edge (Chromy requires Chrome ver.61 or later) - Cleaned up SlimerJS dependencies - Using GNU grep for compatibility (busybox grep uses -r vs -R) - Setting NPM_CONFIG_UNSAFE_PERM=true for compatibility between phantomjs-prebuilt and recent nodejs/npm versions - Added basic bats tests - Updated README
1 parent 4db9c7c commit 03e1bd1

File tree

5 files changed

+174
-29
lines changed

5 files changed

+174
-29
lines changed

.travis.yml

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
language: generic
2+
3+
services:
4+
- docker
5+
6+
install:
7+
- curl -fsSL get.docksal.io | sh
8+
- fin version
9+
- fin sysinfo
10+
11+
script:
12+
- make && make test

Dockerfile

+36-17
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,23 @@
1-
FROM mhart/alpine-node:6.10.0
1+
FROM node:8.5.0-alpine
22

3+
ENV \
4+
PHANTOMJS_VERSION=2.1.1 \
5+
CASPERJS_VERSION=1.1.4 \
6+
SLIMERJS_VERSION=0.10.3 \
7+
BACKSTOPJS_VERSION=3.0.25 \
8+
# Workaround to fix phantomjs-prebuilt installation errors
9+
# See https://github.com/Medium/phantomjs/issues/707
10+
NPM_CONFIG_UNSAFE_PERM=true
11+
12+
# Base packages
313
RUN apk add --no-cache \
414
bash \
5-
coreutils \
615
curl \
7-
git \
816
python \
9-
dbus \
10-
firefox-esr \
11-
fontconfig \
12-
ttf-freefont \
13-
xvfb
17+
# Use GNU grep to avoid compatibility issues (busybox grep uses -r vs -R)
18+
grep
1419

15-
# xvfb wrapper
16-
COPY xvfb-run /usr/bin/xvfb-run
17-
18-
ENV PHANTOMJS_VERSION 2.1.1
19-
ENV CASPERJS_VERSION 1.1.4
20-
ENV SLIMERJS_VERSION 0.10.3
21-
ENV BACKSTOPJS_VERSION 2.6.9
22-
23-
# Installing dependencies from archives - not only this allows us to control versions,
20+
# Installing dependencies from archives - not only this allows us to control versions,
2421
# but the resulting image size is 130MB+ less (!) compared to an npm install (440MB vs 575MB).
2522
RUN \
2623
mkdir -p /opt && \
@@ -55,6 +52,28 @@ RUN \
5552
echo "Installing BackstopJS v${BACKSTOPJS_VERSION}..." && \
5653
npm install -g backstopjs@${BACKSTOPJS_VERSION}
5754

55+
ENV \
56+
CHROMIUM_VERSION=61.0 \
57+
FIREFOX_VERSION=52.3 \
58+
CHROME_PATH=/usr/bin/chromium-browser
59+
60+
# Chrome (from edge)
61+
RUN apk add --no-cache --repository http://dl-cdn.alpinelinux.org/alpine/edge/main --repository http://dl-cdn.alpinelinux.org/alpine/edge/community \
62+
"chromium>${CHROMIUM_VERSION}"
63+
64+
# Firefox (from edge)
65+
RUN apk add --no-cache \
66+
"firefox-esr>${FIREFOX_VERSION}"
67+
68+
# SlimerJS dependencies
69+
RUN \
70+
apk add --no-cache \
71+
dbus \
72+
xvfb
73+
74+
# xvfb wrapper
75+
COPY xvfb-run /usr/bin/xvfb-run
76+
5877
WORKDIR /src
5978

6079
ENTRYPOINT ["backstop"]

Makefile

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
-include env_make
2+
3+
VERSION ?= 3
4+
5+
REPO = docksal/backstopjs
6+
NAME = docksal-backstopjs-$(VERSION)
7+
8+
.PHONY: build test push shell run start stop logs clean release
9+
10+
build:
11+
fin docker build -t $(REPO):$(VERSION) .
12+
13+
test:
14+
IMAGE=$(REPO):$(VERSION) NAME=$(NAME) tests/test.bats
15+
16+
shell:
17+
fin docker run --rm --name $(NAME) -it $(PORTS) $(VOLUMES) $(ENV) --entrypoint=bash $(REPO):$(VERSION)
18+
19+
clean:
20+
fin docker rm -f $(NAME) || true
21+
22+
default: build

README.md

+25-12
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,21 @@
22

33
A self-contained Docker image to run [BackstopJS](https://github.com/garris/BackstopJS) with no external dependencies.
44

5+
[Visual Regression Testing with BackstopJS in a Docker container](https://blog.docksal.io/visual-regression-testing-with-backstopjs-in-a-docker-container-dfd1b9ae8582)
6+
57
Features:
68

7-
- [BackstopJS 2.x](https://github.com/garris/BackstopJS)
8-
- [PhantomJS](http://phantomjs.org/),
9-
- [SlimerJS](https://slimerjs.org/) (with Firefox ESR),
9+
- [BackstopJS 3.x](https://github.com/garris/BackstopJS)
10+
- [PhantomJS](http://phantomjs.org/)
11+
- [SlimerJS](https://slimerjs.org/) (with Firefox ESR)
1012
- [CasperJS](http://casperjs.org/)
13+
- Chromium
14+
15+
16+
## Versions
17+
18+
- `docksal/backstopjs:2` - BackstopJS 2.x (legacy)
19+
- `docksal/backstopjs` (`docksal/backstopjs:3`) - BackstopJS 3 with Chrome Headless support
1120

1221

1322
## Usage
@@ -17,7 +26,7 @@ Working directory is expected to be mounted at `/src` in the container.
1726

1827
```
1928
$ docker run --rm -v $(pwd):/src docksal/backstopjs --version
20-
BackstopJS 2.0.2
29+
BackstopJS v3.0.25
2130
```
2231

2332
You can also add a shell alias (in `.bashrc`, `.zshrc`, etc.) for convenience.
@@ -30,38 +39,42 @@ Restart your shell or open a new one, then
3039

3140
```
3241
$ backstopjs --version
33-
BackstopJS 2.0.2
42+
BackstopJS v3.0.25
3443
```
3544

3645

3746
## Sample test
3847

3948
```
40-
docker run --rm -v $(pwd):/src docksal/backstopjs genConfig
49+
docker run --rm -v $(pwd):/src docksal/backstopjs init
4150
docker run --rm -v $(pwd):/src docksal/backstopjs reference
4251
docker run --rm -v $(pwd):/src docksal/backstopjs test
4352
```
4453

4554

46-
## PhantomJS/SlimerJS
55+
## Browser engines
4756

48-
By default BackstopJS is using PhantomJS to take screenshots.
49-
You can also use SlimerJS/Firefox by setting `"engine": "slimerjs"`
50-
in the [configuration file](tests/backstop/backstop-example.json).
57+
By default BackstopJS is using Headless Chrome to take screenshots.
5158

52-
Both SlimerJS and Firefox ESR (extended support release) are installed in the container.
59+
You can also use PhantomJS or SlimerJS/Firefox by setting `"engine": "phantomjs"` or `"engine": "slimerjs"` respectively
60+
in `backstop.json`.
61+
62+
Chrome, PhantomJS, SlimerJS and Firefox ESR (extended support release) are pre-installed in the container.
5363

5464

5565
## Limitations
5666

5767
`backstop openReport` is not (yet) supported.
5868
You will need a running webserver to view HTML reports generated by BackstopJS.
5969

60-
When running SlimerJS, the user you are running the container as must have a home directory in order for Slimer to start properly. You can work around this by setting the HOME variable. Ex:
70+
When running SlimerJS, the user you are running the container as must have a home directory in order for Slimer
71+
to start properly. You can work around this by setting the `HOME` variable:
72+
6173
```
6274
docker run --rm --user 1000 -e HOME=/tmp/home docksal/backstopjs test
6375
```
6476

77+
6578
## Debugging
6679

6780
The following command will start a bash session in the container.

tests/test.bats

+79
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
#!/usr/bin/env bats
2+
3+
PHANTOMJS_VERSION=2.1.1
4+
CASPERJS_VERSION=1.1.4
5+
SLIMERJS_VERSION=0.10.3
6+
BACKSTOPJS_VERSION=3.0.25
7+
CHROMIUM_VERSION=61.0
8+
FIREFOX_VERSION=52.3
9+
10+
# Debugging
11+
teardown() {
12+
echo
13+
# TODO: figure out how to deal with this (output from previous run commands showing up along with the error message)
14+
echo "Note: ignore the lines between \"...failed\" above and here"
15+
echo
16+
echo "Status: $status"
17+
echo "Output:"
18+
echo "================================================================"
19+
echo "$output"
20+
echo "================================================================"
21+
}
22+
23+
# Global skip
24+
# Uncomment below, then comment skip in the test you want to debug. When done, reverse.
25+
#SKIP=1
26+
27+
@test "Check PhantomJS" {
28+
[[ $SKIP == 1 ]] && skip
29+
30+
### Tests ###
31+
32+
run fin docker run --name ${NAME} --rm --entrypoint="" ${IMAGE} phantomjs --version
33+
echo "$output" | grep -F ${PHANTOMJS_VERSION}
34+
}
35+
36+
@test "Check SlimerJS" {
37+
[[ $SKIP == 1 ]] && skip
38+
39+
### Tests ###
40+
41+
run fin docker run --name ${NAME} --rm --entrypoint="" ${IMAGE} slimerjs --version
42+
echo "$output" | grep -F ${SLIMERJS_VERSION}
43+
}
44+
45+
@test "Check CasperJS" {
46+
[[ $SKIP == 1 ]] && skip
47+
48+
### Tests ###
49+
50+
run fin docker run --name ${NAME} --rm --entrypoint="" ${IMAGE} casperjs --version
51+
echo "$output" | grep -F ${CASPERJS_VERSION}
52+
}
53+
54+
@test "Check BackstopJS" {
55+
[[ $SKIP == 1 ]] && skip
56+
57+
### Tests ###
58+
59+
run fin docker run --name ${NAME} --rm --entrypoint="" ${IMAGE} backstop --version
60+
echo "$output" | grep -F ${BACKSTOPJS_VERSION}
61+
}
62+
63+
@test "Check Chrome" {
64+
[[ $SKIP == 1 ]] && skip
65+
66+
### Tests ###
67+
68+
run fin docker run --name ${NAME} --rm --entrypoint="" ${IMAGE} chromium-browser --version
69+
echo "$output" | grep -F ${CHROMIUM_VERSION}
70+
}
71+
72+
@test "Check Firefox" {
73+
[[ $SKIP == 1 ]] && skip
74+
75+
### Tests ###
76+
77+
run fin docker run --name ${NAME} --rm --entrypoint="" ${IMAGE} firefox --version
78+
echo "$output" | grep ${FIREFOX_VERSION}
79+
}

0 commit comments

Comments
 (0)