Skip to content

Commit

Permalink
feat: Integrated Visual Regression with ember-backstop (#94)
Browse files Browse the repository at this point in the history
* Integrating Visual Regression

* Removed lerna since flag

* made change to .gitignore

* Backstop ref changes

* Made all computed properties computed

* Checking an artifact workflow

* Changed artifact workflow with path

* Changed backstop config

* Backstop Debug

* Backstop Debug Window Eliminated

* Enabled CI Reporting

* Reduced async limit

* Trial with max threshold

* Trial check for screenshots

* Full threshold

* New inline banner

* no tests for banners

* Run 2 VR tests

* Removed workflow downloads

* Experiments I with async

* Experiments II with async

* Experiments III with async

* Experiments IV with async

* Experiments V with async

* Experiments VI

* Experiments VII

* Parallel process

* Normal threshold limits

* fix(tests): concurrency

* fix(lerna): removed --no-bail

* New ref images

* fix: button ref images

* changed threshold

* Update continuous-integration-workflow.yml

* Hopefully final ref images

* Cleanup for final review

* Made required changes

Co-authored-by: Shibu Lijack <[email protected]>
  • Loading branch information
sharath-sriram and shibulijack-fd authored Jan 31, 2020
1 parent 22455e6 commit 2613dca
Show file tree
Hide file tree
Showing 64 changed files with 1,464 additions and 92 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/continuous-integration-workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ on:
jobs:
build:
name: Build
runs-on: ubuntu-latest
runs-on: macos-latest
steps:
- uses: actions/checkout@v2

Expand Down
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,7 @@ tmp
/bower.json.ember-try
/package.json.ember-try
.DS_Store

#backstopjs
html_report
bitmaps_test
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
],
"scripts": {
"start": "yarn workspace nucleus start",
"test": "lerna run test --parallel --no-private",
"test": "lerna run test --no-private --stream --concurrency 1",
"build": "lerna run build --parallel --no-private",
"lint": "lerna run lint:hbs",
"lerna:version": "lerna version prerelease --preid beta",
Expand All @@ -21,7 +21,7 @@
"ember-cli": "~3.11.0",
"ember-source-channel-url": "^2.0.0",
"ember-try": "^1.1.0",
"lerna": "^3.18.4"
"lerna": "^3.20.2"
},
"engines": {
"node": "^10.13.0",
Expand Down
38 changes: 38 additions & 0 deletions packages/banner/ember-backstop/backstop.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
const path = require('path');

module.exports = {
id: `ember-backstop test`,
viewports: [
{
label: 'webview',
width: 1440,
height: 900,
},
],
onBeforeScript: `puppet/onBefore.js`,
onReadyScript: `puppet/onReady.js`,
scenarios: [
{
label: '{testName}',
cookiePath: 'backstop_data/engine_scripts/cookies.json',
url: '{origin}/backstop/dview/{testId}/{scenarioId}',
delay: 500,
},
],
paths: {
bitmaps_reference: 'backstop_data/bitmaps_reference',
bitmaps_test: 'backstop_data/bitmaps_test',
engine_scripts: 'backstop_data/engine_scripts',
html_report: 'backstop_data/html_report',
ci_report: 'backstop_data/ci_report',
},
report: [],
engine: 'puppet',
engineOptions: {
args: ['--no-sandbox'],
},
asyncCaptureLimit: 10,
asyncCompareLimit: 50,
debug: false,
debugWindow: false,
};
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/* eslint-env browser, node */

module.exports = async (page, scenario) => {
const hoverSelector = scenario.hoverSelectors || scenario.hoverSelector;
const clickSelector = scenario.clickSelectors || scenario.clickSelector;
const keyPressSelector = scenario.keyPressSelectors || scenario.keyPressSelector;
const scrollToSelector = scenario.scrollToSelector;
const postInteractionWait = scenario.postInteractionWait; // selector [str] | ms [int]

if (keyPressSelector) {
for (const keyPressSelectorItem of [].concat(keyPressSelector)) {
await page.waitFor(keyPressSelectorItem.selector);
await page.type(keyPressSelectorItem.selector, keyPressSelectorItem.keyPress);
}
}

if (hoverSelector) {
for (const hoverSelectorIndex of [].concat(hoverSelector)) {
await page.waitFor(hoverSelectorIndex);
await page.hover(hoverSelectorIndex);
}
}

if (clickSelector) {
for (const clickSelectorIndex of [].concat(clickSelector)) {
await page.waitFor(clickSelectorIndex);
await page.click(clickSelectorIndex);
}
}

if (postInteractionWait) {
await page.waitFor(postInteractionWait);
}

if (scrollToSelector) {
await page.waitFor(scrollToSelector);
await page.evaluate(scrollToSelector => {
document.querySelector(scrollToSelector).scrollIntoView();
}, scrollToSelector);
}
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/* eslint-env browser, node */

const debug = require('debug')('BackstopJS');

module.exports = async (page, scenario, vp) => {
debug('SCENARIO > ' + scenario.label);
await require('./overrideCSS')(page, scenario);
await require('./clickAndHoverHelper')(page, scenario);

// add more ready handlers here...
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/* eslint-env browser, node */

module.exports = function(page, scenario) {
// inject arbitrary css to override styles
page.evaluate(() => {
const BACKSTOP_TEST_CSS_OVERRIDE = `#ember-testing {width: 100% !important; height: 100% !important; -webkit-transform: scale(1) !important; transform: scale(1) !important;}`;
let style = document.createElement('style');
style.type = 'text/css';
let styleNode = document.createTextNode(BACKSTOP_TEST_CSS_OVERRIDE);
style.appendChild(styleNode);
document.head.appendChild(style);
});
};
1 change: 1 addition & 0 deletions packages/banner/ember-cli-build.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const EmberAddon = require('ember-cli/lib/broccoli/ember-addon');
module.exports = function(defaults) {
let app = new EmberAddon(defaults,
{
hinting: false,
stylelint: {
linterConfig:{
syntax: 'scss'
Expand Down
4 changes: 3 additions & 1 deletion packages/banner/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
"lint:js": "eslint .",
"start": "ember serve -p 4003",
"deploy": "ember deploy production",
"test": "COVERAGE=TRUE ember test --test-port=1512",
"test": "ember backstop-remote & COVERAGE=TRUE ember test --test-port=1512",
"posttest": "ember backstop-stop",
"test:dev": "ember test --server -launch=false"
},
"dependencies": {
Expand All @@ -41,6 +42,7 @@
"broccoli-funnel": "^2.0.2",
"broccoli-merge-trees": "^3.0.2",
"ember-a11y-testing": "^1.0.0",
"ember-backstop": "^1.3.4",
"ember-cli": "~3.13.1",
"ember-cli-autoprefixer": "^0.8.1",
"ember-cli-code-coverage": "^1.0.0-beta.8",
Expand Down
6 changes: 6 additions & 0 deletions packages/banner/testem.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,11 @@ module.exports = {
'--window-size=1440,900'
].filter(Boolean)
}
},
proxies: {
'/backstop': {
target: 'http://localhost:1512',
secure: false
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import hbs from 'htmlbars-inline-precompile';
import a11yAudit from 'ember-a11y-testing/test-support/audit';
import setupBanner from '../../helpers/setup-banner';
import { ITEMS } from '../../constants/nucleus-banner';
import backstop from 'ember-backstop/test-support/backstop';

let StubMapsService = Service.extend({
items: ITEMS
Expand Down Expand Up @@ -50,4 +51,41 @@ module('Integration | Component | nucleus-banner', function(hooks) {
assert.ok(true, 'no a11y errors found!');
});
});

test('normal banner passes visual regression tests', async function(assert){
var bannerObject = [{title:'This is a banner', type:'success'}]
const nucleusBanner = Service.extend({
items: bannerObject,
});
this.owner.register('service:nucleusBanner', nucleusBanner);

await render(hbs`
{{nucleus-banner}}
`);
await backstop(assert, {scenario: {misMatchThreshold: 0.1}});
});

test('banner with link passes visual regression tests', async function(assert){
let closeAction = this.spy();
let displayedItems = [{ title: 'This is another banner',
type: 'danger',
isDismissible: true,
content: {
linkAction: closeAction,
linkText: 'Click here'
},
}, {
title:"This is another banner",
type: 'danger',
isDismissible: true
}]
const nucleusBanner = Service.extend({
items: displayedItems,
});
this.owner.register('service:nucleusBanner', nucleusBanner);
await render(hbs`
{{nucleus-banner}}
`);
await backstop(assert,{scenario: {misMatchThreshold: 0.1}});
});
});
38 changes: 38 additions & 0 deletions packages/button/ember-backstop/backstop.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
const path = require('path');

module.exports = {
id: `ember-backstop test`,
viewports: [
{
label: 'webview',
width: 1440,
height: 900,
},
],
onBeforeScript: `puppet/onBefore.js`,
onReadyScript: `puppet/onReady.js`,
scenarios: [
{
label: '{testName}',
cookiePath: 'backstop_data/engine_scripts/cookies.json',
url: '{origin}/backstop/dview/{testId}/{scenarioId}',
delay: 500,
},
],
paths: {
bitmaps_reference: 'backstop_data/bitmaps_reference',
bitmaps_test: 'backstop_data/bitmaps_test',
engine_scripts: 'backstop_data/engine_scripts',
html_report: 'backstop_data/html_report',
ci_report: 'backstop_data/ci_report',
},
report: [],
engine: 'puppet',
engineOptions: {
args: ['--no-sandbox'],
},
asyncCaptureLimit: 10,
asyncCompareLimit: 50,
debug: false,
debugWindow: false,
};
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/* eslint-env browser, node */

module.exports = async (page, scenario) => {
const hoverSelector = scenario.hoverSelectors || scenario.hoverSelector;
const clickSelector = scenario.clickSelectors || scenario.clickSelector;
const keyPressSelector = scenario.keyPressSelectors || scenario.keyPressSelector;
const scrollToSelector = scenario.scrollToSelector;
const postInteractionWait = scenario.postInteractionWait; // selector [str] | ms [int]

if (keyPressSelector) {
for (const keyPressSelectorItem of [].concat(keyPressSelector)) {
await page.waitFor(keyPressSelectorItem.selector);
await page.type(keyPressSelectorItem.selector, keyPressSelectorItem.keyPress);
}
}

if (hoverSelector) {
for (const hoverSelectorIndex of [].concat(hoverSelector)) {
await page.waitFor(hoverSelectorIndex);
await page.hover(hoverSelectorIndex);
}
}

if (clickSelector) {
for (const clickSelectorIndex of [].concat(clickSelector)) {
await page.waitFor(clickSelectorIndex);
await page.click(clickSelectorIndex);
}
}

if (postInteractionWait) {
await page.waitFor(postInteractionWait);
}

if (scrollToSelector) {
await page.waitFor(scrollToSelector);
await page.evaluate(scrollToSelector => {
document.querySelector(scrollToSelector).scrollIntoView();
}, scrollToSelector);
}
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/* eslint-env browser, node */

const debug = require('debug')('BackstopJS');

module.exports = async (page, scenario, vp) => {
debug('SCENARIO > ' + scenario.label);
await require('./overrideCSS')(page, scenario);
await require('./clickAndHoverHelper')(page, scenario);

// add more ready handlers here...
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/* eslint-env browser, node */

module.exports = function(page, scenario) {
// inject arbitrary css to override styles
page.evaluate(() => {
const BACKSTOP_TEST_CSS_OVERRIDE = `#ember-testing {width: 100% !important; height: 100% !important; -webkit-transform: scale(1) !important; transform: scale(1) !important;}`;
let style = document.createElement('style');
style.type = 'text/css';
let styleNode = document.createTextNode(BACKSTOP_TEST_CSS_OVERRIDE);
style.appendChild(styleNode);
document.head.appendChild(style);
});
};
1 change: 1 addition & 0 deletions packages/button/ember-cli-build.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const EmberAddon = require('ember-cli/lib/broccoli/ember-addon');
module.exports = function(defaults) {
let app = new EmberAddon(defaults,
{
hinting: false,
stylelint: {
linterConfig:{
syntax: 'scss'
Expand Down
4 changes: 3 additions & 1 deletion packages/button/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
"lint:js": "eslint .",
"start": "ember serve -p 4003",
"deploy": "ember deploy production",
"test": "COVERAGE=TRUE ember test --test-port=1509",
"test": "ember backstop-remote & COVERAGE=TRUE ember test --test-port=1509",
"posttest": "ember backstop-stop",
"test:dev": "COVERAGE=TRUE ember test --server -launch=false"
},
"dependencies": {
Expand All @@ -39,6 +40,7 @@
"broccoli-funnel": "^2.0.2",
"broccoli-merge-trees": "^3.0.2",
"ember-a11y-testing": "^1.0.0",
"ember-backstop": "^1.3.4",
"ember-cli": "~3.13.1",
"ember-cli-autoprefixer": "^0.8.1",
"ember-cli-code-coverage": "^1.0.0-beta.8",
Expand Down
6 changes: 6 additions & 0 deletions packages/button/testem.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,11 @@ module.exports = {
'--window-size=1440,900'
].filter(Boolean)
}
},
proxies: {
'/backstop': {
target: 'http://localhost:1509',
secure: false
}
}
}
Loading

0 comments on commit 2613dca

Please sign in to comment.