verstak-sdk/scripts/test.sh

49 lines
984 B
Bash
Executable File
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/usr/bin/env bash
set -euo pipefail
ROOT="$(cd "$(dirname "$0")/.." && pwd)"
FAILED=0
report() {
if [ "$2" -eq 0 ]; then
echo "$1"
else
echo "$1"
FAILED=1
fi
}
echo "=== verstak-sdk test ==="
# Install deps if missing
if [ ! -d "$ROOT/node_modules" ]; then
if [ -f "$ROOT/package-lock.json" ]; then
(cd "$ROOT" && npm ci --no-audit --no-fund)
report "npm ci" $?
else
(cd "$ROOT" && npm install --no-audit --no-fund)
report "npm install" $?
fi
fi
# Run vitest tests
if grep -q '"test"' "$ROOT/package.json" 2>/dev/null; then
OUTPUT=$(cd "$ROOT" && npm test 2>&1) || true
if echo "$OUTPUT" | grep -q "No test files found"; then
echo " vitest: no test files yet"
else
echo "$OUTPUT"
report "vitest" ${PIPESTATUS[0]}
fi
else
echo " no test script in package.json"
fi
echo ""
if [ "$FAILED" -eq 0 ]; then
echo "✅ all tests passed"
else
echo "❌ some tests failed"
fi
exit "$FAILED"