0
0
mirror of https://github.com/PostHog/posthog.git synced 2024-11-28 18:26:15 +01:00
posthog/bin/tests
Tim Glaser e6333ca7d7
perf: Speed up backend tests locally (#9255)
* perf: Speed up backend tests locally

* fix
2022-04-15 11:43:05 +01:00

43 lines
1.3 KiB
Bash
Executable File

#!/bin/bash
set -e
if ! command -v nodemon &> /dev/null
then
echo "Please install nodemon (npm install -g nodemon) to automatically run tests."
exit
fi
if [ $# -eq 0 ]; then
echo "Are you sure you want to run all backend tests? You can run specific tests by doing:"
echo " "
echo "bin/tests posthog/api/test/test_user.py::TestUserAPI::test_retrieve_current_user"
echo " "
read -r -p "Run all tests? [y/N] " response
if [[ "$response" =~ ^([yY][eE][sS]|[yY])+$ ]]
then
echo "OK!"
else
exit
fi
fi
export REDIS_URL='redis:///'
PG_HOST="${PGHOST:=localhost}"
PG_USER="${PGUSER:=posthog}"
PG_PASSWORD="${PGPASSWORD:=posthog}"
PG_PORT="${PGPORT:=5432}"
PGOPTIONS='--client-min-messages=warning' psql posthog -d "postgres://${PG_USER}:${PG_PASSWORD}@${PG_HOST}:${PG_PORT}" -c "drop database if exists test_posthog" 1> /dev/null
if [[ "$*" == *"migration"* ]]
then
echo "Looks like you're testing a migration. Running all migrations first."
MIGRATIONS=""
else
MIGRATIONS="--no-migrations"
export SKIP_TRIGRAM_INDEX_FOR_TESTS=1
fi
nodemon -w ./posthog -w ./ee --ext py --exec "OBJC_DISABLE_INITIALIZE_FORK_SAFETY=YES pytest --reuse-db --durations-min=2.0 ${MIGRATIONS} -s $* --snapshot-update; mypy posthog ee"