83 lines
2.1 KiB
Bash
Executable File
83 lines
2.1 KiB
Bash
Executable File
#!/bin/bash
|
|
#
|
|
# Run CLI Tests
|
|
#
|
|
# Detects the project type and runs appropriate tests with coverage
|
|
|
|
set -e
|
|
|
|
echo "🧪 Running CLI tests..."
|
|
|
|
# Detect project type
|
|
if [ -f "package.json" ]; then
|
|
PROJECT_TYPE="node"
|
|
elif [ -f "setup.py" ] || [ -f "pyproject.toml" ]; then
|
|
PROJECT_TYPE="python"
|
|
else
|
|
echo "❌ Error: Could not detect project type"
|
|
echo " Expected package.json (Node.js) or setup.py/pyproject.toml (Python)"
|
|
exit 1
|
|
fi
|
|
|
|
# Run tests based on project type
|
|
if [ "$PROJECT_TYPE" == "node" ]; then
|
|
echo "📦 Node.js project detected"
|
|
|
|
# Check if npm test is configured
|
|
if ! grep -q '"test"' package.json 2>/dev/null; then
|
|
echo "❌ Error: No test script found in package.json"
|
|
echo " Run setup-jest-testing.sh first"
|
|
exit 1
|
|
fi
|
|
|
|
# Install dependencies if needed
|
|
if [ ! -d "node_modules" ]; then
|
|
echo "📦 Installing dependencies..."
|
|
npm install
|
|
fi
|
|
|
|
# Run tests with coverage
|
|
echo "🧪 Running Jest tests..."
|
|
npm run test:coverage
|
|
|
|
# Display coverage summary
|
|
if [ -f "coverage/lcov-report/index.html" ]; then
|
|
echo ""
|
|
echo "✅ Tests complete!"
|
|
echo "📊 Coverage report: coverage/lcov-report/index.html"
|
|
fi
|
|
|
|
elif [ "$PROJECT_TYPE" == "python" ]; then
|
|
echo "🐍 Python project detected"
|
|
|
|
# Check if pytest is installed
|
|
if ! command -v pytest &> /dev/null; then
|
|
echo "❌ Error: pytest is not installed"
|
|
echo " Run setup-pytest-testing.sh first"
|
|
exit 1
|
|
fi
|
|
|
|
# Create/activate virtual environment if it exists
|
|
if [ -d "venv" ]; then
|
|
echo "🔧 Activating virtual environment..."
|
|
source venv/bin/activate
|
|
elif [ -d ".venv" ]; then
|
|
echo "🔧 Activating virtual environment..."
|
|
source .venv/bin/activate
|
|
fi
|
|
|
|
# Run tests with coverage
|
|
echo "🧪 Running pytest tests..."
|
|
pytest --cov --cov-report=term-missing --cov-report=html
|
|
|
|
# Display coverage summary
|
|
if [ -d "htmlcov" ]; then
|
|
echo ""
|
|
echo "✅ Tests complete!"
|
|
echo "📊 Coverage report: htmlcov/index.html"
|
|
fi
|
|
fi
|
|
|
|
echo ""
|
|
echo "🎉 All tests passed!"
|