Skip to content

Commit d0d7970

Browse files
Merge pull request #4 from uktrade/feature/add-test-jobs-to-build
Add test jobs to build and introduce eslint
2 parents 4fb5572 + 53c7a92 commit d0d7970

17 files changed

+1251
-70
lines changed

.circleci/config.yml

+22
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,25 @@ aliases:
33
- &node_version node:12.14.1
44

55
jobs:
6+
test:
7+
machine:
8+
docker_layer_caching: true
9+
working_directory: ~/cypress-image-diff
10+
steps:
11+
- checkout
12+
- run:
13+
name: Build docker
14+
command: make build
15+
- run:
16+
name: Run eslint
17+
command: make lint-test
18+
- run:
19+
name: Run unit
20+
command: make unit-test
21+
- run:
22+
name: Run eslint
23+
command: make e2e-test
24+
625
build_and_publish:
726
docker:
827
- image: *node_version
@@ -21,7 +40,10 @@ workflows:
2140
version: 2
2241
cypressimagediff:
2342
jobs:
43+
- test
2444
- build_and_publish:
45+
requires:
46+
- test
2547
filters:
2648
branches:
2749
only:

.eslintrc

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"extends": [
3+
"airbnb-base",
4+
"prettier"
5+
],
6+
"rules": {
7+
"prefer-object-spread": 0
8+
},
9+
"overrides": [
10+
{
11+
"files": ["src/**/*.js", "cypress/**/*.js"],
12+
"rules": {
13+
"no-undef": "off"
14+
}
15+
}
16+
]
17+
}

Dockerfile

+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
FROM node:12.18.0
2+
3+
ENV NPM_CONFIG_LOGLEVEL warn
4+
ENV NPM_CONFIG_UNSAFE_PERM true
5+
ENV TERM xterm
6+
ENV CHROME_VERSION 86.0.4240.75-1
7+
8+
RUN apt-get update
9+
10+
# Install common dependencies
11+
RUN apt-get install -y \
12+
tzdata \
13+
wget \
14+
curl \
15+
make \
16+
git
17+
18+
# Fix error when libpng cannot be found after CircleCI restores cache for pngquant-bin.
19+
# See https://github.com/tcoopman/image-webpack-loader/issues/95
20+
RUN wget -q -O /tmp/libpng12.deb http://mirrors.kernel.org/ubuntu/pool/main/libp/libpng/libpng12-0_1.2.54-1ubuntu1_amd64.deb \
21+
&& dpkg -i /tmp/libpng12.deb \
22+
&& rm /tmp/libpng12.deb
23+
24+
# Install Cypress dependencies
25+
RUN apt-get install -y \
26+
libgtk2.0-0 \
27+
libnotify-dev \
28+
libgconf-2-4 \
29+
libnss3 \
30+
libxss1 \
31+
libasound2 \
32+
xvfb
33+
34+
# Install Chrome (Version 86)
35+
# See all available versions for download on: https://www.ubuntuupdates.org/package_logs?type=ppas&vals=8
36+
RUN apt-get install -y xvfb xdg-utils libgtk-3-0 lsb-release libappindicator3-1 fonts-liberation libasound2 libnspr4 libnss3 \
37+
&& curl https://dl.google.com/linux/chrome/deb/pool/main/g/google-chrome-stable/google-chrome-stable_${CHROME_VERSION}_amd64.deb -O \
38+
&& dpkg -i google-chrome-stable_${CHROME_VERSION}_amd64.deb \
39+
&& rm google-chrome-stable_${CHROME_VERSION}_amd64.deb \
40+
&& google-chrome --version
41+
42+
WORKDIR /code
43+
44+
# Install dev packages
45+
COPY package.json .
46+
COPY package-lock.json .
47+
RUN npm install
48+
49+
COPY . /code

Makefile

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
build:
2+
docker-compose build
3+
lint-test:
4+
docker-compose run --no-deps --rm test bash -c 'npm run lint'
5+
unit-test:
6+
docker-compose run --no-deps --rm test bash -c 'npm run test:unit'
7+
e2e-test:
8+
docker-compose run --no-deps --rm test bash -c 'npm run test:e2e'
-118 Bytes
Loading
Loading
Loading

cypress/specs/image-diff-spec.js

+18-12
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,20 @@
1-
it('should compare screenshot of the entire page', () => {
2-
cy.visit('../../report-example.html')
3-
cy.compareSnapshot('wholePage')
4-
})
5-
6-
it('should compare screenshot of the entire page', () => {
7-
cy.visit('../../report-example.html')
8-
cy.compareSnapshot('wholePageThreshold', 0.2)
9-
})
1+
describe('Visuals', () => {
2+
beforeEach(() => {
3+
cy.viewport(1280, 720)
4+
})
105

11-
it('should compare screenshot from a given element', () => {
12-
cy.visit('../../report-example.html')
13-
cy.get('#report-header').compareSnapshot('element')
6+
it('should compare screenshot of the entire page', () => {
7+
cy.visit('../../report-example.html')
8+
cy.compareSnapshot('wholePage')
9+
})
10+
11+
it('should compare screenshot of the entire page', () => {
12+
cy.visit('../../report-example.html')
13+
cy.compareSnapshot('wholePageThreshold', 0.2)
14+
})
15+
16+
it('should compare screenshot from a given element', () => {
17+
cy.visit('../../report-example.html')
18+
cy.get('#report-header').compareSnapshot('element')
19+
})
1420
})

cypress/support/commands.js

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// eslint-disable-next-line import/no-unresolved
12
const compareSnapshotCommand = require('../../dist/command')
23

34
compareSnapshotCommand()

docker-compose.yml

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
version: '3.2'
2+
3+
services:
4+
test:
5+
build:
6+
context: .
7+
dockerfile: Dockerfile
8+
volumes:
9+
- ./cypress-visual-screenshots:/code/cypress-visual-screenshots

0 commit comments

Comments
 (0)