Skip to content

Commit

Permalink
fix: add tests descriptions
Browse files Browse the repository at this point in the history
  • Loading branch information
Anton Standrik authored and Anton Standrik committed Nov 21, 2024
1 parent 67a7d8b commit e5abc6a
Showing 1 changed file with 31 additions and 11 deletions.
42 changes: 31 additions & 11 deletions .github/workflows/quality.yml
Original file line number Diff line number Diff line change
Expand Up @@ -217,33 +217,49 @@ jobs:
name: playwright-artifacts
path: playwright-artifacts

- name: Count new tests
id: count_tests
- name: Analyze test changes
id: analyze_tests
run: |
git fetch origin main:main
new_tests=0
test_details=""
# Get list of changed test files
for file in $(git diff --name-only main...HEAD | grep -E '^tests/suites/.*\.(spec|test)\.(ts|tsx|js|jsx)$'); do
# Count tests in current version
echo "Analyzing file: $file"
# Get test names from current version
if git show HEAD:"$file" > /dev/null 2>&1; then
current_tests=$(git show HEAD:"$file" | grep -E "test\([\'\"]" | wc -l)
current_tests=$(git show HEAD:"$file" | grep -E "test\([\'\"]" | sed -E "s/.*test\(['\"]([^'\"]+)['\"].*/\1/")
else
current_tests=0
current_tests=""
fi
# Count tests in main version
# Get test names from main version
if git show main:"$file" > /dev/null 2>&1; then
base_tests=$(git show main:"$file" | grep -E "test\([\'\"]" | wc -l)
base_tests=$(git show main:"$file" | grep -E "test\([\'\"]" | sed -E "s/.*test\(['\"]([^'\"]+)['\"].*/\1/")
else
base_tests=0
base_tests=""
fi
# Add difference to total
((new_tests += current_tests - base_tests))
# Compare and find new tests
while IFS= read -r test_name; do
if [ ! -z "$test_name" ] && ! echo "$base_tests" | grep -Fxq "$test_name"; then
((new_tests++))
test_details+="- ✨ Added test: \`$test_name\` in \`$file\`\\n"
fi
done <<< "$current_tests"
done
# Escape the test details for GitHub Actions
test_details="${test_details//'%'/'%25'}"
test_details="${test_details//$'\n'/'%0A'}"
test_details="${test_details//$'\r'/'%0D'}"
echo "new_tests=$new_tests" >> $GITHUB_OUTPUT
echo "test_details<<EOF" >> $GITHUB_OUTPUT
echo "$test_details" >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT
- name: Update PR description
uses: actions/github-script@v6
Expand Down Expand Up @@ -289,7 +305,8 @@ jobs:
parseFloat(percent) > 0 ? '🔺' :
parseFloat(percent) < 0 ? '🔽' : '✅';
const newTests = parseInt('${{ steps.count_tests.outputs.new_tests }}');
const newTests = parseInt('${{ steps.analyze_tests.outputs.new_tests }}');
const testDetails = '${{ steps.analyze_tests.outputs.test_details }}'.replace(/%0A/g, '\n');
const testsStatus = newTests > 0 ? '✨' : '➖';
const ciSection = `## CI Results
Expand All @@ -301,6 +318,9 @@ jobs:
|:-----:|:------:|:------:|:-----:|:-------:|:---------:|
| ${testResults.total} | ${testResults.passed} | ${testResults.failed} | ${testResults.flaky} | ${testResults.skipped} | ${testsStatus} ${newTests} |
${newTests > 0 ? `<details>
<summary>✨ New Tests Added</summary>\n\n${testDetails}</details>\n` : ''}
### Bundle Size: ${bundleStatus}
Current: ${formatSize(currentSize)} | Main: ${formatSize(mainSize)}
Diff: ${diff > 0 ? '+' : ''}${formatSize(Math.abs(diff))} (${percent === 'N/A' ? 'N/A' : `${percent}%`})
Expand Down

0 comments on commit e5abc6a

Please sign in to comment.