Skip to content

Commit

Permalink
Feature/npm package updates (#1355)
Browse files Browse the repository at this point in the history
* Update tests reference files

* Update test, for some reason I don't understand is failing

* Update nodejs versions in travis

* Update package-lock.json file

* Update eslint version

* Run eslint and fix eslint warnings/errors

* Fix 'each' is not defined  no-undef

* Re-generate compare-output

* Fix .forEach loops for null values

* Fix eslint errors(remove .eslintrc.json file)

* Fix eslint errors

* Add gitlab-ci.yml, out of travis credits

* Fix .gitlab-ci.yml name

* Fix node version

* Update gitlab-ci code
  • Loading branch information
klodoma authored Aug 24, 2021
1 parent 608a6b8 commit 9fa768b
Show file tree
Hide file tree
Showing 50 changed files with 3,408 additions and 2,006 deletions.
27 changes: 27 additions & 0 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@

image: ubuntu:20.04

before_script:
- export DEBIAN_FRONTEND=noninteractive
- apt-get update
- apt-get install curl wget -y
- wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb
- apt-get install ./google-chrome-stable_current_amd64.deb -y
- curl https://raw.githubusercontent.com/creationix/nvm/master/install.sh | bash
- . ~/.nvm/nvm.sh
- nvm --version
- nvm install $NODEJS
- node -v
- npm -v
- npm install

tests:
script:
- npm run lint && npm run unit-test
parallel:
matrix:
- NODEJS:
- 10
- 12
- 14
- 16
4 changes: 3 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ addons: # get google-chrome [stable|beta]
chrome: beta
language: node_js
node_js:
- 8
- 10
- 12
- 14
- 16
install:
- npm install
script:
Expand Down
2 changes: 1 addition & 1 deletion capture/engine_scripts/puppet/ignoreCSP.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ module.exports = async function (page, scenario) {
const result = await fetch(requestUrl, options);

const buffer = await result.buffer();
let cleanedHeaders = result.headers._headers || {};
const cleanedHeaders = result.headers._headers || {};
cleanedHeaders['content-security-policy'] = '';
await request.respond({
body: buffer,
Expand Down
2 changes: 1 addition & 1 deletion capture/engine_scripts/puppet/overrideCSS.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const BACKSTOP_TEST_CSS_OVERRIDE = `html {background-image: none;}`;
const BACKSTOP_TEST_CSS_OVERRIDE = 'html {background-image: none;}';

module.exports = async (page, scenario) => {
// inject arbitrary css to override styles
Expand Down
2 changes: 1 addition & 1 deletion cli/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ function main () {
return;
}

const commandName = argsOptions['_'][0];
const commandName = argsOptions._[0];

if (!commandName) {
console.log(usage);
Expand Down
37 changes: 15 additions & 22 deletions compare/output/index_bundle.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion compare/src/components/atoms/ButtonFilter.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ const Button = styled.button`

export default class ButtonFilter extends React.Component {
render () {
let { count, label, status } = this.props;
const { count, label, status } = this.props;

return (
<Button
Expand Down
2 changes: 1 addition & 1 deletion compare/src/components/atoms/ButtonSettings.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ const Button = styled.button`

export default class ButtonSettings extends React.Component {
render () {
let isActive = this.props.active ? 'active' : '';
const isActive = this.props.active ? 'active' : '';

return (
<Button onClick={this.props.onClick} className={isActive}>
Expand Down
2 changes: 1 addition & 1 deletion compare/src/components/atoms/DiffDetails.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const Value = styled.span`

export default class DiffDetails extends React.Component {
render () {
let { diff, suppress } = this.props;
const { diff, suppress } = this.props;
if (!diff || suppress) {
return null;
}
Expand Down
4 changes: 2 additions & 2 deletions compare/src/components/atoms/ImageScrubber.js
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ export default class ImageScrubber extends React.Component {
'message',
function (result) {
const divergedImgData = result.data;
let clampedImgData = getEmptyImgData(h, w);
const clampedImgData = getEmptyImgData(h, w);
for (let i = divergedImgData.length - 1; i >= 0; i--) {
clampedImgData.data[i] = divergedImgData[i];
}
Expand Down Expand Up @@ -305,7 +305,7 @@ function getImgDataDataFromContext (context) {
}

function getEmptyImgData (h, w) {
var o = imageToCanvasContext(null, h, w);
const o = imageToCanvasContext(null, h, w);
return o.createImageData(w, h);
}

Expand Down
12 changes: 6 additions & 6 deletions compare/src/components/atoms/NavButtons.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,24 +23,24 @@ const ButtonNav = styled.div`
height: 32px;
width: 32px;
margin: 0 0px 0 5px;
transform: ${props => (props.prev ? `rotate(0)` : `rotate(180deg)`)};
opacity: ${props => (props.disabled ? `0.2` : `1`)};
transform: ${props => (props.prev ? 'rotate(0)' : 'rotate(180deg)')};
opacity: ${props => (props.disabled ? '0.2' : '1')};
display: inline-block;
&:hover {
cursor: ${props => (props.disabled ? `` : `pointer`)};
cursor: ${props => (props.disabled ? '' : 'pointer')};
background-color: ${props => (props.disabled ? `${colors.lightGray}` : `${colors.medGray}`)};
}
`;

export default class NavButtons extends React.Component {
nextTest () {
let dest = `#test${this.props.currentId + 1}`;
const dest = `#test${this.props.currentId + 1}`;
this.jumpTo(dest);
}

prevTest () {
let dest = `#test${this.props.currentId - 1}`;
const dest = `#test${this.props.currentId - 1}`;
this.jumpTo(dest);
}

Expand All @@ -52,7 +52,7 @@ export default class NavButtons extends React.Component {
}

render () {
let { currentId, lastId } = this.props;
const { currentId, lastId } = this.props;

return (
<Wrapper>
Expand Down
2 changes: 1 addition & 1 deletion compare/src/components/atoms/SettingOption.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const WrapperOption = styled.div`

export default class SettingOption extends React.Component {
render () {
let { label, value, onToggle } = this.props;
const { label, value, onToggle } = this.props;

return (
<WrapperOption>
Expand Down
4 changes: 2 additions & 2 deletions compare/src/components/ecosystems/List.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ const ListWrapper = styled.section`

class List extends React.Component {
render () {
let { tests, settings } = this.props;
let onlyText =
const { tests, settings } = this.props;
const onlyText =
!settings.refImage && !settings.testImage && !settings.diffImage;

return (
Expand Down
3 changes: 2 additions & 1 deletion compare/src/components/molecules/ApproveButton.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,8 @@ class ApproveButton extends React.Component {
errorMsg: `${err.message}. 🧐
Looks like the "approve" operation failed.
Please check that backstopRemote is running.
` });
`
});
alert(this.state.errorMsg);
}
}
Expand Down
4 changes: 2 additions & 2 deletions compare/src/components/molecules/FiltersSwitch.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ function ButtonsFilter (props) {

class FiltersSwitch extends React.Component {
render () {
let tests = this.props.tests;
let availableStatus = [
const tests = this.props.tests;
const availableStatus = [
{
id: 'all',
label: 'all',
Expand Down
2 changes: 1 addition & 1 deletion compare/src/components/molecules/ScrubberButton.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ const ButtonSD = styled.button`

class ScrubberButton extends React.Component {
onClick () {
let { openModal } = this.props;
const { openModal } = this.props;
openModal(this.props.info);
}

Expand Down
2 changes: 1 addition & 1 deletion compare/src/components/molecules/SettingsPopup.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ class SettingsPopup extends React.Component {
}

render () {
let { settings } = this.props;
const { settings } = this.props;

return (
<PopupWrapper>
Expand Down
6 changes: 3 additions & 3 deletions compare/src/components/molecules/TestImages.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@ class TestImages extends React.Component {
}

onImageClick (img) {
let { openModal } = this.props;
const { openModal } = this.props;
this.props.info.targetImg = img;
openModal(this.props.info);
}

render () {
let { reference, test } = this.props.info;
let { status, settings } = this.props;
const { reference, test } = this.props.info;
const { status, settings } = this.props;

this.state.images = [
{
Expand Down
2 changes: 1 addition & 1 deletion compare/src/components/molecules/TextSearch.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const InputWrapper = styled.div`

class TextSearch extends React.Component {
onChange (event) {
let value = event.target.value;
const value = event.target.value;

if (value.length > 0) {
this.props.findTest(value);
Expand Down
4 changes: 2 additions & 2 deletions compare/src/components/organisms/TestCard.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ function isRemoteOption () {

export default class TestCard extends React.Component {
render () {
let { pair: info, status } = this.props.test;
let onlyText = this.props.onlyText;
const { pair: info, status } = this.props.test;
const onlyText = this.props.onlyText;

return (
<CardWrapper id={this.props.id} status={status}>
Expand Down
2 changes: 1 addition & 1 deletion compare/src/reducers/scrubber.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ function getModeFromImgId (imgId) {
}

const scrubber = (state = {}, action) => {
let targetImgId = '';
switch (action.type) {
case 'OPEN_SCRUBBER_MODAL':
let targetImgId = '';
try {
targetImgId = action.value.targetImg.id;
} catch (err) {}
Expand Down
5 changes: 3 additions & 2 deletions compare/src/reducers/tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ const tests = (state = {}, action) => {
if (action.value.length > 0) {
return Object.assign({}, state, {
filtered: state.all.filter(e => {
let fileName = e.pair.fileName.toLowerCase();
let label = e.pair.label.toLowerCase();
const fileName = e.pair.fileName.toLowerCase();
const label = e.pair.label.toLowerCase();

if (state.filterStatus !== 'all') {
if (
Expand All @@ -46,6 +46,7 @@ const tests = (state = {}, action) => {
return true;
}
}
return false;
})
});
}
Expand Down
7 changes: 4 additions & 3 deletions core/command/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const path = require('path');
const _ = require('lodash');
const logger = require('../util/logger')('COMMAND');

/*
Expand Down Expand Up @@ -86,7 +87,7 @@ const commands = commandNames

const exposedCommands = exposedCommandNames
.filter(function commandIsDefined (commandName) {
return commands.hasOwnProperty(commandName);
return _.has(commands, commandName);
})
.map(function (commandName) {
return {
Expand All @@ -97,8 +98,8 @@ const exposedCommands = exposedCommandNames
.reduce(toObjectReducer, {});

function execute (commandName, config) {
if (!exposedCommands.hasOwnProperty(commandName)) {
if (commandName.charAt(0) === '_' && commands.hasOwnProperty(commandName.substring(1))) {
if (!_.has(exposedCommands, commandName)) {
if (commandName.charAt(0) === '_' && _.has(commands, commandName.substring(1))) {
commandName = commandName.substring(1);
} else {
throw new Error('The command "' + commandName + '" is not exposed publicly.');
Expand Down
2 changes: 1 addition & 1 deletion core/command/remote.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ module.exports = {
const projectPath = path.resolve(config.projectPath);

return new Promise(function (resolve, reject) {
let commandStr = `node ${ssws} ${projectPath} ${MIDDLEWARE_PATH} --config=${config.backstopConfigFileName}`;
const commandStr = `node ${ssws} ${projectPath} ${MIDDLEWARE_PATH} --config=${config.backstopConfigFileName}`;

logger.log(`Starting remote with: ${commandStr}`);

Expand Down
46 changes: 19 additions & 27 deletions core/command/report.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const path = require('path');
const chalk = require('chalk');
const _ = require('lodash');
const cloneDeep = require('lodash/cloneDeep');

const allSettled = require('../util/allSettled');
Expand Down Expand Up @@ -80,17 +81,15 @@ function writeBrowserReport (config, reporter) {

// Fixing URLs in the configuration
const report = toAbsolute(config.html_report);
for (let i in browserReporter.tests) {
if (browserReporter.tests.hasOwnProperty(i)) {
const pair = browserReporter.tests[i].pair;
pair.reference = path.relative(report, toAbsolute(pair.reference));
pair.test = path.relative(report, toAbsolute(pair.test));

if (pair.diffImage) {
pair.diffImage = path.relative(report, toAbsolute(pair.diffImage));
}
_.forEach(browserReporter.tests, test => {
const pair = test.pair;
pair.reference = path.relative(report, toAbsolute(pair.reference));
pair.test = path.relative(report, toAbsolute(pair.test));

if (pair.diffImage) {
pair.diffImage = path.relative(report, toAbsolute(pair.diffImage));
}
}
});

const reportConfigFilename = toAbsolute(config.compareConfigFileName);
const testReportJsonName = toAbsolute(config.bitmaps_test + '/' + config.screenshotDateTime + '/report.json');
Expand Down Expand Up @@ -147,12 +146,7 @@ function writeJunitReport (config, reporter) {
const suite = builder.testSuite()
.name(reporter.testSuite);

for (let i in reporter.tests) {
if (!reporter.tests.hasOwnProperty(i)) {
continue;
}

const test = reporter.tests[i];
_.forEach(reporter.tests, test => {
const testCase = suite.testCase()
.className(test.pair.selector)
.name(' ›› ' + test.pair.label);
Expand All @@ -162,7 +156,7 @@ function writeJunitReport (config, reporter) {
testCase.failure(error);
testCase.error(error);
}
}
});

return new Promise(function (resolve, reject) {
let testReportFilename = config.testReportFileName || config.ciReport.testReportFileName;
Expand Down Expand Up @@ -193,17 +187,15 @@ function writeJsonReport (config, reporter) {

// Fixing URLs in the configuration
const report = toAbsolute(config.json_report);
for (let i in jsonReporter.tests) {
if (jsonReporter.tests.hasOwnProperty(i)) {
const pair = jsonReporter.tests[i].pair;
pair.reference = path.relative(report, toAbsolute(pair.reference));
pair.test = path.relative(report, toAbsolute(pair.test));

if (pair.diffImage) {
pair.diffImage = path.relative(report, toAbsolute(pair.diffImage));
}
_.forEach(jsonReporter.tests, test => {
const pair = test.pair;
pair.reference = path.relative(report, toAbsolute(pair.reference));
pair.test = path.relative(report, toAbsolute(pair.test));

if (pair.diffImage) {
pair.diffImage = path.relative(report, toAbsolute(pair.diffImage));
}
}
});

return fs.writeFile(toAbsolute(config.compareJsonFileName), JSON.stringify(jsonReporter.getReport(), null, 2)).then(function () {
logger.log('Wrote Json report to: ' + toAbsolute(config.compareJsonFileName));
Expand Down
Loading

0 comments on commit 9fa768b

Please sign in to comment.