docs: why get premium article #79
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Tests & Coverage | |
on: | |
pull_request: | |
branches: [main] | |
push: | |
branches: [main] | |
jobs: | |
tests-and-cov: | |
runs-on: ubuntu-latest | |
defaults: | |
run: | |
working-directory: ./ladderly-io | |
steps: | |
- uses: actions/checkout@v3 | |
- name: Setup Node.js | |
uses: actions/setup-node@v3 | |
with: | |
node-version: '22' | |
cache: 'npm' | |
cache-dependency-path: './ladderly-io/package-lock.json' | |
- name: Install dependencies | |
run: npm ci | |
- name: Check test coverage | |
run: | | |
# Run tests and capture output | |
OUTPUT=$(npm run test:cov) | |
echo "$OUTPUT" | |
# Extract branch coverage using grep and awk (get second percentage) | |
BRANCH_COVERAGE=$(echo "$OUTPUT" | grep "All files" | awk -F'|' '{print $3}' | tr -d ' %') | |
if [ -z "$BRANCH_COVERAGE" ]; then | |
echo "Error: Could not find branch coverage in test output!" | |
exit 1 | |
fi | |
if (( $(echo "$BRANCH_COVERAGE < 55" | bc -l) )); then | |
echo "Branch coverage ($BRANCH_COVERAGE%) is below minimum threshold (55%)" | |
exit 1 | |
fi | |
echo "Branch coverage: $BRANCH_COVERAGE%" |