test_unit_run_dir 1011 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. #!/bin/bash
  2. TARGET_DIR=$1
  3. declare -a vitest_args=("$TARGET_DIR")
  4. if [[ -n "$MOCHA_GREP" ]]; then
  5. vitest_args+=("--testNamePattern" "$MOCHA_GREP")
  6. fi
  7. if [[ -n "$VITEST_NO_CACHE" ]]; then
  8. echo "Disabling cache for vitest."
  9. vitest_args+=("--no-cache")
  10. fi
  11. echo "Running unit tests in directory: $TARGET_DIR"
  12. npm run test:unit:esm -- "${vitest_args[@]}"
  13. vitest_status=$?
  14. if find "$TARGET_DIR" -type f -name "*.js" -print -quit | grep -q '.'; then
  15. mocha --recursive --timeout 25000 --exit --grep="$MOCHA_GREP" --require test/unit/bootstrap.js --extension=js "$TARGET_DIR"
  16. mocha_status=$?
  17. else
  18. echo "No mocha tests found in $TARGET_DIR, skipping mocha step."
  19. mocha_status=0
  20. fi
  21. if [ $mocha_status -eq 0 ] && [ $vitest_status -eq 0 ]; then
  22. exit 0
  23. fi
  24. # Report status briefly at the end for failures
  25. if [ $mocha_status -ne 0 ]; then
  26. echo "Mocha tests failed with status: $mocha_status"
  27. fi
  28. if [ $vitest_status -ne 0 ]; then
  29. echo "Vitest tests failed with status: $vitest_status"
  30. fi
  31. exit 1