test_unit_run_dir 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. #!/bin/bash
  2. declare -a vitest_args=("$@")
  3. has_mocha_test=0
  4. has_vitest_test=0
  5. for dir_path in "$@"; do
  6. if [ -n "$(find "$dir_path" -name "*.js" -type f -print -quit 2>/dev/null)" ]; then
  7. has_mocha_test=1
  8. fi
  9. if [ -n "$(find "$dir_path" -name "*.test.mjs" -type f -print -quit 2>/dev/null)" ]; then
  10. has_vitest_test=1
  11. fi
  12. done
  13. if [[ -n "$MOCHA_GREP" ]]; then
  14. vitest_args+=("--testNamePattern" "$MOCHA_GREP")
  15. fi
  16. if [[ -n "$VITEST_NO_CACHE" ]]; then
  17. echo "Disabling cache for vitest."
  18. vitest_args+=("--no-cache")
  19. fi
  20. echo "Running unit tests in directory: $*"
  21. # Remove this if/else when we have converted all module tests to vitest.
  22. if (( has_vitest_test == 1 )); then
  23. npm run test:unit:esm -- "${vitest_args[@]}"
  24. vitest_status=$?
  25. else
  26. echo "No vitest tests found in $*, skipping vitest step."
  27. vitest_status=0
  28. fi
  29. if (( has_mocha_test == 1 )); then
  30. mocha --recursive --timeout 25000 --exit --grep="$MOCHA_GREP" --require test/unit/bootstrap.js --extension=js "$@"
  31. mocha_status=$?
  32. else
  33. echo "No mocha tests found in $TARGET_DIR, skipping mocha step."
  34. mocha_status=0
  35. fi
  36. if [ "$mocha_status" -eq 0 ] && [ "$vitest_status" -eq 0 ]; then
  37. exit 0
  38. fi
  39. # Report status briefly at the end for failures
  40. if [ "$mocha_status" -ne 0 ]; then
  41. echo "Mocha tests failed with status: $mocha_status"
  42. fi
  43. if [ "$vitest_status" -ne 0 ]; then
  44. echo "Vitest tests failed with status: $vitest_status"
  45. fi
  46. exit 1