Skip to content

Commit

Permalink
e2e: add visual regression tests (#858)
Browse files Browse the repository at this point in the history
The rendering differs slightly between machines which makes it throw
enormous amount of false positives (in my tests, everything was wrong,
always). This approach will generate the base screenshots from the last
released version and then compare it to the one generated by the code in
current working branch. It's possible to require never version than the
latest released if something was changed/fixed/etc. (e.g. if 7.10.0 is
the last released, then `cy.visSimpleCanvasSnapshot("name", {}, {
requireNewerVersionThan: "7.10.0" })` can be used to basically skip
given test until a new version is released, this will pass the CI checks
and automatically check any new PRs as the version will be 7.10.1+ by
then).

I created some label rendering (literal/MD/HTML, ASCII/UTF, some font
options…) tests.

Co-authored-by: Yotam Berkowitz <yotamberk@gmail.com>
  • Loading branch information
Thomaash and yotamberk committed Jul 18, 2020
1 parent 5812308 commit 5292129
Show file tree
Hide file tree
Showing 24 changed files with 858 additions and 259 deletions.
122 changes: 90 additions & 32 deletions .circleci/config.yml
Expand Up @@ -15,6 +15,67 @@ executors:
GIT_COMMITTER_EMAIL: visjsbot@gmail.com
GIT_COMMITTER_NAME: vis-bot

commands:
install_chromium_deps:
description: Install dependencies for headless Chromium
steps:
- run: sudo apt-get update
- run: |
sudo apt-get install -yq \
ca-certificates \
fonts-liberation \
gconf-service \
libappindicator1 \
libasound2 \
libatk-bridge2.0-0 \
libatk1.0-0 \
libc6 \
libcairo2 \
libcups2 \
libdbus-1-3 \
libexpat1 \
libfontconfig1 \
libgcc1 \
libgconf-2-4 \
libgdk-pixbuf2.0-0 \
libglib2.0-0 \
libgtk-3-0 \
libnspr4 \
libnss3 \
libpango-1.0-0 \
libpangocairo-1.0-0 \
libstdc++6 \
libx11-6 \
libx11-xcb1 \
libxcb1 \
libxcomposite1 \
libxcursor1 \
libxdamage1 \
libxext6 \
libxfixes3 \
libxi6 \
libxrandr2 \
libxrender1 \
libxss1 \
libxtst6 \
lsb-release \
wget \
xdg-utils
install_cypress_deps:
description: Install dependencies for headless Cypress
steps:
- run: sudo apt-get update
- run: |
sudo apt-get install -yq \
libasound2 \
libgconf-2-4 \
libgtk-3-dev \
libnotify-dev \
libnss3 \
libxss1 \
xvfb
jobs:
prepare:
executor: node
Expand Down Expand Up @@ -56,24 +117,7 @@ jobs:
- attach_workspace:
at: ..

- run:
name: Install dependencies for headless Chromium
command: |
sudo apt-get update
sudo apt-get install -yq \
ca-certificates fonts-liberation gconf-service libappindicator1 \
libasound2 libatk-bridge2.0-0 libatk1.0-0 libc6 libcairo2 libcups2 \
libdbus-1-3 libexpat1 libfontconfig1 libgcc1 libgconf-2-4 \
libgdk-pixbuf2.0-0 libglib2.0-0 libgtk-3-0 libnspr4 libnss3 \
libpango-1.0-0 libpangocairo-1.0-0 libstdc++6 libx11-6 libx11-xcb1 \
libxcb1 libxcomposite1 libxcursor1 libxdamage1 libxext6 libxfixes3 \
libxi6 libxrandr2 libxrender1 libxss1 libxtst6 lsb-release wget \
xdg-utils
- run:
command: npm run generate-examples-index
# One of the examples sports really massive network that takes long to
# render and would regularly exceed the default timeout of 10 minues.
no_output_timeout: 20m
- install_chromium_deps

- persist_to_workspace:
root: ..
Expand Down Expand Up @@ -107,21 +151,27 @@ jobs:

- run: npm run test:unit

test_e2e:
test_e2e_functional:
executor: node

steps:
- attach_workspace:
at: ..

- run:
name: Install dependencies for Cypress
command: |
sudo apt-get update
sudo apt-get install -yq \
xvfb libgtk-3-dev libnotify-dev libgconf-2-4 libnss3 libxss1 \
libasound2
- run: npm run test:e2e
- install_cypress_deps

- run: npm run test:e2e:functional

test_e2e_visual:
executor: node

steps:
- attach_workspace:
at: ..

- install_cypress_deps

- run: npm run test:e2e:visual

gh_pages:
executor: node
Expand Down Expand Up @@ -191,19 +241,25 @@ workflows:
- prepare
- build

- test_e2e:
- test_e2e_functional:
requires:
- prepare
- build

- test_e2e_visual:
requires:
- prepare
- build

- gh_pages:
requires:
# - lint_js
- build
- examples
# - lint_js
- lint_ts
- prepare
- test_e2e
- test_e2e_functional
- test_e2e_visual
- test_unit
filters:
branches:
Expand All @@ -212,12 +268,14 @@ workflows:

- release:
requires:
# - lint_js
- build
- examples
- gh_pages
# - lint_js
- lint_ts
- prepare
- test_e2e
- test_e2e_functional
- test_e2e_visual
- test_unit
filters:
branches:
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -27,6 +27,7 @@ coverage/
/cypress/pages/**/*.js
/cypress/pages/**/*.js.map
/cypress/screenshots/
/cypress/snapshots/
/cypress/support/**/*.js
/cypress/support/**/*.js.map
/cypress/videos/
Expand Down
1 change: 0 additions & 1 deletion cypress.json
@@ -1,5 +1,4 @@
{
"testFiles": "**/*.spec.js",
"viewportHeight": 1600,
"viewportWidth": 1200
}
@@ -1,4 +1,4 @@
import { VisEvent } from "./helpers";
import { VisEvent } from "../helpers";

context("Clicks", (): void => {
/*
Expand Down
Expand Up @@ -4,7 +4,7 @@ import {
TestData,
addMoreEdges,
generateMaryTree
} from "./helpers";
} from "../helpers";

/**
* Generate a consecutive list of ids starting with first and ending with last
Expand Down Expand Up @@ -181,7 +181,7 @@ describe("Directed hierarchical layout", (): void => {

describe(name, (): void => {
it("Preparation", (): void => {
cy.visit("http://localhost:58253/cypress/pages/universal.html");
cy.visVisitUniversal();

cy.visRun(({ network, nodes, edges }): void => {
network.setOptions({
Expand Down
@@ -1,4 +1,4 @@
import { Point, VisEvent } from "./helpers";
import { Point, VisEvent } from "../helpers";

/**
* Create drag events according to given path.
Expand Down
@@ -1,4 +1,4 @@
import { IdType, Point } from "./helpers";
import { IdType, Point } from "../helpers";

// eslint-disable-next-line require-jsdoc
function selectEditAndCheck(
Expand Down Expand Up @@ -74,10 +74,7 @@ function selectEditAndCheck(

context("Manipulation GUI", () => {
beforeEach(() => {
cy.visit(
"http://localhost:58253/cypress/pages/universal.html#" +
encodeURIComponent(JSON.stringify({ manipulation: true }))
);
cy.visVisitUniversal({ manipulation: true });
});

it("Add a node", () => {
Expand Down
File renamed without changes.
@@ -1,6 +1,6 @@
context("Simple", (): void => {
beforeEach((): void => {
cy.visit("http://localhost:58253/cypress/pages/universal.html");
cy.visVisitUniversal();
});

it("Click the canvas", (): void => {
Expand Down
125 changes: 125 additions & 0 deletions cypress/integration/visual/label-rendering.spec.ts
@@ -0,0 +1,125 @@
context("Label rendering", (): void => {
for (const multi of [false, true, "md", "html"]) {
describe(`Multi: ${multi}`, function(): void {
for (const { variantName, color, background, size } of [
{ variantName: "defaults" },
{
variantName: "changed",

align: "right",
background: "#440044",
color: "#AA00AA",
face: "serif",
size: 25,
strokeColor: "#FFFFFF",
strokeWidth: 2,
vadjust: 12,

bold: {
color: "#FF0000",
size: 40,
vadjust: 20
},
boldital: {
color: "#FFFF00",
size: 30,
vadjust: 5
},
ital: {
color: "#00FF00",
size: 20,
vadjust: -10
},
mono: {
color: "#0000FF",
size: 10,
vadjust: -20
}
}
]) {
describe(`Variant: ${variantName}`, function(): void {
for (const [labelName, label] of [
// ASCII, single line
["ASCII", "test"],
// UTF, multi line
["UTF", "+\něščřžýáíé\n=\t|\nÉÍÁÝŽŘČŠĚ\n<𝄞>"],
// Markdown
[
"MD",
"Multi: " +
" ".repeat(10) +
"`códé`" +
",\n" +
"*bóld*" +
", " +
"-ítálícs-" +
", " +
"nórmál" +
",\n" +
"-*bóld+ítálícs*-" +
", " +
"*-ítálícs+bóld-*."
],
// HTML
[
"HTML",
"Multi: " +
" ".repeat(10) +
"<code>códé</code>" +
",\n" +
"<b>bóld</b>" +
", " +
"<i>ítálícs</i>" +
", " +
"nórmál" +
",\n" +
"<i><b>bóld+ítálícs</b></i>" +
", " +
"<b><i>ítálícs+bóld</i></b>."
]
]) {
it(
JSON.stringify(
label.replace(/\t/g, "<HT>").replace(/\n/g, "<LF>")
),
(): void => {
cy.visSimpleCanvasSnapshot(
`${multi}-${variantName}-${labelName}`,
{
nodes: [
{
id: 1,
fixed: true,
x: -50,
y: -300,
shape: "box",
label
},
{
id: 3,
fixed: true,
x: 50,
y: 300,
shape: "square",
label
}
],
edges: [{ id: 2, from: 1, to: 3, label }],
options: {
nodes: {
font: { background, color, multi, size }
},
edges: {
font: { background, color, multi, size }
}
}
}
);
}
);
}
});
}
});
}
});

0 comments on commit 5292129

Please sign in to comment.