Skip to content

Instantly share code, notes, and snippets.

@osv
Last active February 16, 2017 09:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save osv/05c212f9f980a7c22ef74de7eab078ec to your computer and use it in GitHub Desktop.
Save osv/05c212f9f980a7c22ef74de7eab078ec to your computer and use it in GitHub Desktop.
Copy from actual to baseline image when test is failes
#!/bin/bash
#
# Update baseline image from "actual" directory if test is failed.
#
# This script parse stdin for "Expected false to be true, 'screenshot " message
# and copies image file from "actual" to "baseline" directory
#
# Example of usage
# e2e/foo.spec.js:
# it('matches screenshots', async () => {
# await expectScreenshotToMatch('bar')
# // where expectScreenshotToMatch outputs
# // "Expected false to be true, 'screenshot \"bar\" doesn't match'"
# shell command:
# ./e2e-in-docker --specs e2e/foo.spec.js | ./e2e-in-docker-update-images
#
E2E_ACTUAL=`pwd`/e2e/actual
E2E_BASELINE=`pwd`/e2e/baseline
# blue color
log() {
printf "\e[34m$@\e[0m\n"
}
REGEXP="Expected false to be true, 'screenshot \"(.*)\" doesn't match'"
while read line
do
echo "$line"
if [[ "$line" =~ $REGEXP ]]
then
IMAGE="${BASH_REMATCH[1]}.png"
log "Image \"$IMAGE\" will be copied to baseline dir"
IMAGES=(${IMAGES[@]} $IMAGE)
fi
done < /dev/stdin
if [ -n "$IMAGES" ]; then
for image in "${IMAGES[@]}"
do
log "Copy file \"$image\" to baseline directory"
cp "${E2E_ACTUAL}/$image" "${E2E_BASELINE}/"
done
log "Please, ensure these image is actual and should be commited "
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment