Merge pull request #29662 from overleaf/ar-allow-esm-tests-to-be-grepped

[web] Split vitest tests and spread args

GitOrigin-RevId: d0e06836fc4f4b9de50def456aef7f0ecb6cb128
This commit is contained in:
Andrew Rumble
2025-11-13 10:36:08 +00:00
committed by Copybot
parent c059a3c5b0
commit ccf1fb8fcb

View File

@@ -3,15 +3,15 @@
declare -a vitest_args=("$@")
has_mocha_test=0
has_vitest_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 "*.test.mjs" -type f -print -quit 2>/dev/null)" ]; then
has_vitest_test=1
if [ -n "$(find "$dir_path" -name "*.sequential.test.mjs" -type f -print -quit 2>/dev/null)" ]; then
has_sequential_test=1
fi
done
@@ -26,24 +26,26 @@ fi
echo "Running unit tests in directory: $*"
# Remove this if/else when we have converted all module tests to vitest.
if (( has_vitest_test == 1 )); then
npm run test:unit:esm -- "${vitest_args[@]}"
vitest_status=$?
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
echo "No vitest tests found in $*, skipping vitest step."
vitest_status=0
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 in $TARGET_DIR, skipping mocha step."
echo "No mocha tests found, skipping mocha step."
mocha_status=0
fi
if [ "$mocha_status" -eq 0 ] && [ "$vitest_status" -eq 0 ]; then
if [ "$mocha_status" -eq 0 ] && [ "$vitest_sequential_status" -eq 0 ] && [ "$vitest_parallel_status" -eq 0 ]; then
exit 0
fi
@@ -53,8 +55,12 @@ if [ "$mocha_status" -ne 0 ]; then
echo "Mocha tests failed with status: $mocha_status"
fi
if [ "$vitest_status" -ne 0 ]; then
echo "Vitest tests failed with status: $vitest_status"
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