<commit_before>#!/bin/bash

WHYIS_IMAGE="${1:-tetherlessworld/whyis:latest}"
WHYIS_DEMO_IMAGE="${1:-tetherlessworld/whyis-demo:latest}"

mkdir -p test-results/py

# docker run -e "CI=$CI" $WHYIS_IMAGE bash -c "python3 manage.py test"
# docker run -e "CI=$CI" $WHYIS_IMAGE bash -c "python3 manage.py test --ci && cat test-results/py/results.xml"

echo "Running Python tests in $WHYIS_IMAGE"
docker run -e "CI=$CI" $WHYIS_IMAGE bash -c "mkdir -p test-results/py && python3 manage.py test --ci >test-results/py/test.out 2>test-results/py/test.err; tar cf test-results-py.tar test-results/py && cat test-results-py.tar" >test-results-py.tar
tar xf test-results-py.tar
cat test-results/py/test.out
if [ ! -f "test-results/py/results.xml" ]; then
    echo "Python test results.xml does not exist, exiting abnormally"
    exit 1
fi
if [ "$(grep -c 'failure ' test-results/py/results.xml)" -ge 1 ]; then
    echo "Python test results.xml has failures, exiting abnormally"
    exit 1
fi

mkdir -p test-results/js
echo "Running integration tests in $WHYIS_DEMO_IMAGE"
#JS_REDIRECT=""
#docker run $WHYIS_DEMO_IMAGE bash -c "mkdir -p test-results/js && curl -sL https://deb.nodesource.com/setup_12.x | bash - $JS_REDIRECT && apt-get install -y nodejs xvfb libgtk-3-dev libnotify-dev libgconf-2-4 libnss3 libxss1 libasound2 $JS_REDIRECT && cd tests/integration && npm install $JS_REDIRECT && CYPRESS_baseUrl=http://localhost npm run cypress:run $JS_REDIRECT"
JS_REDIRECT=">/apps/whyis/test-results/js/test.out 2>/apps/whyis/test-results/js/test.err"
docker run $WHYIS_DEMO_IMAGE bash -c "mkdir -p test-results/js && curl -sL https://deb.nodesource.com/setup_12.x | bash - $JS_REDIRECT && apt-get install -y nodejs xvfb libgtk-3-dev libnotify-dev libgconf-2-4 libnss3 libxss1 libasound2 $JS_REDIRECT && cd tests/integration && npm install $JS_REDIRECT && CYPRESS_baseUrl=http://localhost npm run cypress:run-ci $JS_REDIRECT; cd /apps/whyis && tar cf test-results-js.tar test-results/js && cat test-results-js.tar" >test-results-js.tar
tar xf test-results-js.tar
cat test-results/js/test.out<commit_msg>copy out Cypress videos<commit_after>#!/bin/bash

WHYIS_IMAGE="${1:-tetherlessworld/whyis:latest}"
WHYIS_DEMO_IMAGE="${1:-tetherlessworld/whyis-demo:latest}"

mkdir -p test-results/py

# docker run -e "CI=$CI" $WHYIS_IMAGE bash -c "python3 manage.py test"
# docker run -e "CI=$CI" $WHYIS_IMAGE bash -c "python3 manage.py test --ci && cat test-results/py/results.xml"

echo "Running Python tests in $WHYIS_IMAGE"
docker run -e "CI=$CI" $WHYIS_IMAGE bash -c "mkdir -p test-results/py && python3 manage.py test --ci >test-results/py/test.out 2>test-results/py/test.err; tar cf test-results-py.tar test-results/py && cat test-results-py.tar" >test-results-py.tar
tar xf test-results-py.tar
echo "Python test stdout:"
cat test-results/py/test.out
echo "Python test stderr:"
cat test-results/py/test.err
if [ ! -f "test-results/py/results.xml" ]; then
    echo "Python test results.xml does not exist, exiting abnormally"
    exit 1
fi
if [ "$(grep -c 'failure ' test-results/py/results.xml)" -ge 1 ]; then
    echo "Python test results.xml has failures, exiting abnormally"
    exit 1
fi

mkdir -p test-results/js
echo "Running integration tests in $WHYIS_DEMO_IMAGE"
#JS_REDIRECT=""
#docker run $WHYIS_DEMO_IMAGE bash -c "mkdir -p test-results/js && curl -sL https://deb.nodesource.com/setup_12.x | bash - $JS_REDIRECT && apt-get install -y nodejs xvfb libgtk-3-dev libnotify-dev libgconf-2-4 libnss3 libxss1 libasound2 $JS_REDIRECT && cd tests/integration && npm install $JS_REDIRECT && CYPRESS_baseUrl=http://localhost npm run cypress:run $JS_REDIRECT"
JS_REDIRECT=">/apps/whyis/test-results/js/test.out 2>/apps/whyis/test-results/js/test.err"
docker run $WHYIS_DEMO_IMAGE bash -c "mkdir -p test-results/js && curl -sL https://deb.nodesource.com/setup_12.x | bash - $JS_REDIRECT && apt-get install -y nodejs xvfb libgtk-3-dev libnotify-dev libgconf-2-4 libnss3 libxss1 libasound2 $JS_REDIRECT && cd tests/integration && npm install $JS_REDIRECT && CYPRESS_baseUrl=http://localhost npm run cypress:run-ci $JS_REDIRECT; cp -p -R cypress/screenshots /apps/whyis/test-results/js; cp -p -R cypress/videos /apps/whyis/test-results/js; cd /apps/whyis && tar cf test-results-js.tar test-results/js && cat test-results-js.tar" >test-results-js.tar
tar xf test-results-js.tar
echo "Integration test stdout:"
cat test-results/js/test.out
echo "Integration test stderr:"
cat test-results/js/test.err
{'fraction_non_alphanumeric': 0.13950368879946345, 'fraction_numerical': 0.011625307399955287, 'mean_word_length': 4.31353919239905, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 15, 'https://': 4, 'lorem ipsum': 0, 'www.': 0, 'xml': 10}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4133212', 'n_tokens_mistral': 1710, 'n_tokens_neox': 1635, 'n_words': 420}