Files
KaTeX/dockers/Screenshotter/screenshotter.sh
Martin von Gagern 94dad8029d Check out test fonts in screenshotter.sh (#570)
This ensures that running screenshots as indicated by the screenshotter
readme will correctly render the Unicode examples, even if not run on
Travis.  It also fixes the commit ID of the unicode fonts.

One alternative would have been using a git submodule.  But as many tools
will initialize submodules automatically, that would mean big downloads for
anyone using such a tool to clone KaTeX.

Another alternative would be tweaking the server to fetch the files on
demand if the local copy is unavailable.  But that would cause additional
network overhead, so grabbing the files just once should be simpler.
2016-11-23 09:38:47 -05:00

50 lines
1.5 KiB
Bash
Executable File

#!/bin/bash
# This script does a one-shot creation of screenshots, creating needed
# docker containers and removing them afterwards. During development,
# it might be desirable to avoid the overhead for starting and
# stopping the containers. Developers are encouraged to manage
# suitable containers themselves, calling the screenshotter.js script
# directly.
cleanup() {
[[ "${container}" ]] \
&& docker stop "${container}" >/dev/null \
&& docker rm "${container}" >/dev/null
container=
}
SS_DIR=$(dirname "$0")
TOP_DIR=${SS_DIR}/../..
FONTS_DIR=${TOP_DIR}/test/screenshotter/unicode-fonts
if [[ ! -d "${FONTS_DIR}" ]]; then
echo "Cloning test fonts repository"
git clone https://github.com/Khan/KaTeX-test-fonts "${FONTS_DIR}" \
|| exit 2
fi
pushd "${FONTS_DIR}" || exit 2
git checkout --detach 99fa66a2da643218754c8236b9f9151cac71ba7c || exit 2
popd || exit 2
container=
trap cleanup EXIT
status=0
for browserTag in firefox:2.48.2 chrome:2.48.2; do
browser=${browserTag%:*}
image=selenium/standalone-${browserTag}
echo "Starting container for ${image}"
container=$(docker run -d -P ${image})
[[ ${container} ]] || continue
echo "Container ${container:0:12} started, creating screenshots..."
if node "$(dirname "$0")"/screenshotter.js \
--browser="${browser}" --container="${container}" "$@"; then
res=Done
else
res=Failed
status=1
fi
echo "${res} taking screenshots, stopping and removing ${container:0:12}"
cleanup
done
exit ${status}