mirror of
https://github.com/creyD/prettier_action.git
synced 2026-04-12 19:30:30 +02:00
This commit adds a complete testing setup for the prettier_action: - Adds BATS (Bash Automated Testing System) testing framework - Creates unit tests for _git_setup() and _git_changed() functions - Creates plugin validation tests to ensure proper prettier plugin format - Creates integration tests for end-to-end workflows - Adds automated test runner script (tests/run_tests.sh) - Adds GitHub Actions workflow for CI/CD testing - Includes ShellCheck linting for bash scripts - Updates README with comprehensive testing documentation - Updates .gitignore to exclude test artifacts Test coverage includes: - Git configuration with different identity modes - File change detection - Plugin name validation (official, community, and scoped formats) - Working directory handling - node_modules cleanup - package-lock.json restoration - only_changed file filtering - Dry run behavior The test suite can be run locally with ./tests/run_tests.sh and runs automatically on all pushes and pull requests.
116 lines
2.9 KiB
Bash
Executable File
116 lines
2.9 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
|
|
# Test runner script for prettier_action
|
|
# This script installs BATS and runs all tests
|
|
|
|
set -e
|
|
|
|
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
PROJECT_ROOT="$(cd "$SCRIPT_DIR/.." && pwd)"
|
|
BATS_VERSION="v1.11.0"
|
|
BATS_INSTALL_DIR="$SCRIPT_DIR/bats"
|
|
|
|
# Colors for output
|
|
RED='\033[0;31m'
|
|
GREEN='\033[0;32m'
|
|
YELLOW='\033[1;33m'
|
|
NC='\033[0m' # No Color
|
|
|
|
echo "========================================="
|
|
echo "Prettier Action Test Runner"
|
|
echo "========================================="
|
|
echo ""
|
|
|
|
# Function to install BATS
|
|
install_bats() {
|
|
echo -e "${YELLOW}Installing BATS (Bash Automated Testing System)...${NC}"
|
|
|
|
if [ -d "$BATS_INSTALL_DIR" ]; then
|
|
echo "BATS already installed at $BATS_INSTALL_DIR"
|
|
return 0
|
|
fi
|
|
|
|
# Clone BATS
|
|
git clone --depth 1 --branch "$BATS_VERSION" https://github.com/bats-core/bats-core.git "$BATS_INSTALL_DIR"
|
|
|
|
# Clone support libraries
|
|
mkdir -p "$BATS_INSTALL_DIR/test_helper"
|
|
git clone --depth 1 https://github.com/bats-core/bats-support.git "$BATS_INSTALL_DIR/test_helper/bats-support"
|
|
git clone --depth 1 https://github.com/bats-core/bats-assert.git "$BATS_INSTALL_DIR/test_helper/bats-assert"
|
|
|
|
echo -e "${GREEN}BATS installed successfully!${NC}"
|
|
echo ""
|
|
}
|
|
|
|
# Function to check if BATS is available
|
|
check_bats() {
|
|
if [ -x "$BATS_INSTALL_DIR/bin/bats" ]; then
|
|
return 0
|
|
fi
|
|
return 1
|
|
}
|
|
|
|
# Main execution
|
|
main() {
|
|
cd "$PROJECT_ROOT"
|
|
|
|
# Check if BATS is installed, if not install it
|
|
if ! check_bats; then
|
|
install_bats
|
|
fi
|
|
|
|
echo -e "${YELLOW}Running tests...${NC}"
|
|
echo ""
|
|
|
|
# Run all test files
|
|
TEST_FILES=(
|
|
"$SCRIPT_DIR/unit_tests.bats"
|
|
"$SCRIPT_DIR/plugin_validation_tests.bats"
|
|
"$SCRIPT_DIR/integration_tests.bats"
|
|
)
|
|
|
|
FAILED=0
|
|
|
|
for test_file in "${TEST_FILES[@]}"; do
|
|
if [ -f "$test_file" ]; then
|
|
echo "Running $(basename "$test_file")..."
|
|
if "$BATS_INSTALL_DIR/bin/bats" "$test_file"; then
|
|
echo -e "${GREEN}✓ $(basename "$test_file") passed${NC}"
|
|
else
|
|
echo -e "${RED}✗ $(basename "$test_file") failed${NC}"
|
|
FAILED=1
|
|
fi
|
|
echo ""
|
|
fi
|
|
done
|
|
|
|
echo "========================================="
|
|
if [ $FAILED -eq 0 ]; then
|
|
echo -e "${GREEN}All tests passed!${NC}"
|
|
exit 0
|
|
else
|
|
echo -e "${RED}Some tests failed!${NC}"
|
|
exit 1
|
|
fi
|
|
}
|
|
|
|
# Parse command line arguments
|
|
case "${1:-}" in
|
|
--install-only)
|
|
install_bats
|
|
exit 0
|
|
;;
|
|
--help)
|
|
echo "Usage: $0 [OPTIONS]"
|
|
echo ""
|
|
echo "Options:"
|
|
echo " --install-only Only install BATS without running tests"
|
|
echo " --help Show this help message"
|
|
echo ""
|
|
exit 0
|
|
;;
|
|
*)
|
|
main
|
|
;;
|
|
esac
|