-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Git workflow: Check missing tests #105
Labels
technical
Has only technical and no business requirements
Comments
Some work has already been done. .github/workflows/branch-push.yaml name: CI pipeline
on:
pull_request:
branches:
- "**" # Runs on all pull requests
jobs:
check-test-coverage:
# The coverage is configured inside 'jest.config.js' by setting the 'coverageThreshold'
name: Checking test coverage (must be over 90%)
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [ 20.17 ] # Define Node.js latest LTS version (update as needed)
steps:
...
# Step 6: Make 'check-missing-tests.sh' executable
- name: Make script 'check-missing-tests.sh' executable
run: chmod +x ./check-missing-tests.sh
# Step 7: Fail the job if there are uncovered files (js, ts, jsx, tsx)
- name: Check missing tests
run: ./check-missing-tests.sh check-missing-tests.sh #!/bin/bash
git fetch origin main
# Step 1: Get the list of changed JS, TS, JSX and TSX files in the src directory
CHANGED_FILES=$(git diff --name-only origin/main..HEAD -- 'src/*.[jt]s' 'src/*.[jt]sx')
# Initialize an empty array to hold files without tests
MISSING_TEST_FILES=()
# Step 2: Loop through each changed file and check if it has a corresponding test file
for FILE in $CHANGED_FILES; do
# Extract the file path and replace "src/" with "tests/" and add ".test" postfix
TEST_FILE=$(echo "$FILE" | sed 's|^src/|tests/|' | sed 's|\.[jt]sx\?$|.test&|')
# Check if the corresponding test file exists
if [[ ! -f "$TEST_FILE" ]]; then
MISSING_TEST_FILES+=("$FILE") # Add to missing test files array if test is not found
fi
done
# Step 3: Report and fail if there are any missing test files
if [ ${#MISSING_TEST_FILES[@]} -ne 0 ]; then
echo "The following source files do not have corresponding test files:"
for MISSING_FILE in "${MISSING_TEST_FILES[@]}"; do
echo "$MISSING_FILE"
done
exit 1 # Fail the workflow
else
echo "All changed files have corresponding test files."
exit 0 # Success
fi |
This was referenced Sep 27, 2024
Pull RequestDescription
|
Pull Request 2-3Fixed issues
|
This was referenced Oct 11, 2024
Merged
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Description
The git workflow checks only coverage for files for which a test has already been written.
Files which have been changed but there are no test at all will not considered in the test coverage.
Acceptance criteria
The text was updated successfully, but these errors were encountered: