Files
overleaf-cep/services/web/bin/test_unit_run_dir
Andrew Rumble ccf1fb8fcb Merge pull request #29662 from overleaf/ar-allow-esm-tests-to-be-grepped
[web] Split vitest tests and spread args

GitOrigin-RevId: d0e06836fc4f4b9de50def456aef7f0ecb6cb128
2025-11-14 09:05:29 +00:00

67 lines
1.7 KiB
Bash
Executable File

#!/bin/bash
declare -a vitest_args=("$@")
has_mocha_test=0
has_sequential_test=0
for dir_path in "$@"; do
if [ -n "$(find "$dir_path" -name "*.js" -type f -print -quit 2>/dev/null)" ]; then
has_mocha_test=1
fi
if [ -n "$(find "$dir_path" -name "*.sequential.test.mjs" -type f -print -quit 2>/dev/null)" ]; then
has_sequential_test=1
fi
done
if [[ -n "$MOCHA_GREP" ]]; then
vitest_args+=("--testNamePattern" "$MOCHA_GREP")
fi
if [[ -n "$VITEST_NO_CACHE" ]]; then
echo "Disabling cache for vitest."
vitest_args+=("--no-cache")
fi
echo "Running unit tests in directory: $*"
npm run test:unit:esm:parallel -- "${vitest_args[@]}"
vitest_parallel_status=$?
if (( has_sequential_test == 0 )); then
echo "No sequential vitest tests found, skipping sequential vitest step."
vitest_sequential_status=0
else
npm run test:unit:esm:sequential -- "${vitest_args[@]}"
vitest_sequential_status=$?
fi
if (( has_mocha_test == 1 )); then
mocha --recursive --timeout 25000 --exit --grep="$MOCHA_GREP" --require test/unit/bootstrap.js --extension=js "$@"
mocha_status=$?
else
echo "No mocha tests found, skipping mocha step."
mocha_status=0
fi
if [ "$mocha_status" -eq 0 ] && [ "$vitest_sequential_status" -eq 0 ] && [ "$vitest_parallel_status" -eq 0 ]; then
exit 0
fi
# Report status briefly at the end for failures
if [ "$mocha_status" -ne 0 ]; then
echo "Mocha tests failed with status: $mocha_status"
fi
if [ "$vitest_parallel_status" -ne 0 ]; then
echo "Vitest parallel tests failed with status: $vitest_parallel_status"
fi
if [ "$vitest_sequential_status" -ne 0 ]; then
echo "Vitest sequential tests failed with status: $vitest_sequential_status"
fi
exit 1