Skip to content

Instantly share code, notes, and snippets.

@FrankHassanabad
Last active November 8, 2021 19:38
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 FrankHassanabad/ce8353ae0519cbb2cdf38a9e279da1c9 to your computer and use it in GitHub Desktop.
Save FrankHassanabad/ce8353ae0519cbb2cdf38a9e279da1c9 to your computer and use it in GitHub Desktop.
run jest multiple times
#!/bin/sh
# Set your kibana home here
KIBANA_HOME=~/projects/kibana
# Set your kibana project here
KIBANA_PROJECT=x-pack/plugins/alerting/jest.config.js
# security_solution commented out
# KIBANA_PROJECT=x-pack/plugins/security_solution/jest.config.js
# Set your memory to a low value that barely passes so the typical memory saw tooths are small.
# When it doesn't leak set this to around 200 megs to prove it does not leak
# MAX_MEMORY=200
# When it does leak set this to around 2 gigs to get memory snapshots without issues.
MAX_MEMORY=2000
# Set this to true to activate "--inspect-brk" below
CHROME_INSPECT=false
# Useage if no arguments
if [ $# -eq 0 ]; then
echo "Usage is ./copy_tests.sh <test name>"
exit 1
fi
# Check if file exists or not
if [[ ! -f $1 ]]; then
echo "File does not exist"
exit 1
fi
# Gets the directory of your first argument
DIR="$(dirname "${1}")"
# Remove all the copied scripts even if cntrl-C is pressed or other issues.
trap "rm $DIR/script_copy_test_*.test.ts" EXIT
# Loops max times and copy the single test in place
for i in {1..100}
do
cp $1 $DIR/script_copy_test_$i.test.ts
done
pushd $KIBANA_HOME;
if [ "$CHROME_INSPECT" = true ] ;
then
node --max-old-space-size=$MAX_MEMORY --inspect-brk --expose-gc ./node_modules/.bin/jest --verbose --runInBand --logHeapUsage --detectOpenHandles --no-cache --config $KIBANA_PROJECT $DIR/script_copy_test_*.ts;
else
node --max-old-space-size=$MAX_MEMORY --expose-gc ./node_modules/.bin/jest --verbose --runInBand --logHeapUsage --detectOpenHandles --no-cache --config $KIBANA_PROJECT $DIR/script_copy_test_*.ts;
# I uncomment and use this for perf timing based tests
# node --max-old-space-size=$MAX_MEMORY ./node_modules/.bin/jest --verbose --runInBand --config $KIBANA_PROJECT $DIR/script_copy_test_*.ts;
fi
popd;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment