Skip to content

Commit

Permalink
visual_regression: add some sanity checks and warnings (check files e…
Browse files Browse the repository at this point in the history
…xist), change folder from data/images to visual_regression
  • Loading branch information
sschmid committed Feb 19, 2020
1 parent b0e169a commit cad0c84
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 16 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Expand Up @@ -15,7 +15,7 @@ pids
*.seed

# optional npm script-generated data
data/images/
visual_regression/
export/

# Documentation
Expand Down
4 changes: 2 additions & 2 deletions package.json
Expand Up @@ -19,8 +19,8 @@
"build:webpack-sourcemap": "webpack --progress --colors --config webpack.sourcemap.js",
"start": "webpack-dev-server --progress --colors --config webpack.dev.js",
"generatePNG": "node ./test/Util/generateDiffImagesPuppeteerLocalhost.js ./test/data/ ./export/",
"generate:current": "node ./test/Util/generateDiffImagesPuppeteerLocalhost.js ./test/data/ ./data/images/current",
"generate:blessed": "node ./test/Util/generateDiffImagesPuppeteerLocalhost.js ./test/data/ ./data/images/blessed",
"generate:current": "node ./test/Util/generateDiffImagesPuppeteerLocalhost.js ./test/data/ ./visual_regression/current",
"generate:blessed": "node ./test/Util/generateDiffImagesPuppeteerLocalhost.js ./test/data/ ./visual_regression/blessed",
"test:visual": "sh ./test/Util/visual_regression.sh",
"fix-memory-limit": "cross-env NODE_OPTIONS=--max_old_space_size=4096"
},
Expand Down
62 changes: 49 additions & 13 deletions test/Util/visual_regression.sh
Expand Up @@ -43,7 +43,7 @@ THRESHOLD=0.01
# Directories. You might want to change BASE, if you're running from a
# different working directory.
BASE=.
IMAGESPARENTFOLDER=$BASE/data/images
IMAGESPARENTFOLDER=$BASE/visual_regression
BLESSED=$IMAGESPARENTFOLDER/blessed
CURRENT=$IMAGESPARENTFOLDER/current
DIFF=$IMAGESPARENTFOLDER/diff
Expand All @@ -52,16 +52,6 @@ DIFF=$IMAGESPARENTFOLDER/diff
RESULTS=$DIFF/results.txt
WARNINGS=$DIFF/warnings.txt

mkdir -p $DIFF
if [ -e "$RESULTS" ]
then
rm $DIFF/*
fi
touch $RESULTS
touch $RESULTS.pass
touch $RESULTS.fail
touch $WARNINGS

# If no prefix is provided, test all images.
if [ "$1" == "" ]
then
Expand All @@ -70,11 +60,57 @@ else
files=$1*.png
fi

if [ "`basename $PWD`" == "Util" ]
# some sanity checks: check if some png images are in the right folder and warn if not. doesn't make sure there are actual, correct png images though.
folderWarningStringMsg="Also, please run this npm script from the base OSMD folder. (npm run test:visual should do this automatically)
Exiting without running visual regression tests.\n"
# check if current directory exists / started from base OSMD folder
if [ ! -e "$CURRENT" ]
then
printf "Warning: directory ${CURRENT} missing. Please run npm run generate:current (and if necessary npm run generate:blessed) first.
${folderWarningStringMsg}"
exit 1
fi
# check if blessed directory exists / started from base OSMD folder
if [ ! -e "$BLESSED" ]
then
printf "Warning: directory ${BLESSED} missing. Please run npm run generate:blessed first (or otherwise get the blessed images).
${folderWarningStringMsg}"
exit 1
fi
# note: ls returns errors if the directory doesn't exist
totalCurrentImages=`ls -l $CURRENT/*.png | wc -l | sed 's/[[:space:]]//g'`
totalBlessedImages=`ls -l $BLESSED/*.png | wc -l | sed 's/[[:space:]]//g'`
# check if there are some current images
if [ "$totalCurrentImages" -lt 1 ]
then
echo Please run this script from the OSMD base directory.
printf "Warning: Found no pngs in ${CURRENT}. Please run npm run generate (and if necessary npm run blessed) first.
${folderWarningStringMsg}"
exit 1
fi
# check if there are some blessed images
if [ "$totalBlessedImages" -lt 1 ]
then
printf "Warning: Found no pngs in ${BLESSED}. Please run npm run blessed first, ideally on the repository's develop state.
${folderWarningStringMsg}"
exit 1
fi
# check that #currentImages == #blessedImages (will continue anyways)
if [ ! "$totalCurrentImages" -eq "$totalBlessedImages" ]
then
printf "Warning: Number of current images (${totalCurrentImages}) is not the same as blessed images (${totalBlessedImages}). Continuing anyways.\n"
else
printf "Found ${totalCurrentImages} current and ${totalBlessedImages} blessed images. Continuing.\n"
fi

mkdir -p $DIFF
if [ -e "$RESULTS" ]
then
rm $DIFF/*
fi
touch $RESULTS
touch $RESULTS.pass
touch $RESULTS.fail
touch $WARNINGS

# Number of simultaneous jobs
nproc=$(sysctl -n hw.physicalcpu 2> /dev/null || nproc)
Expand Down

0 comments on commit cad0c84

Please sign in to comment.