Skip to content

Commit 35ba335

Browse files
vaindclaude
andcommitted
test(danger): Add comprehensive tests for extra-dangerfile and extra-install-packages features
Add test coverage for the new extra-dangerfile and extra-install-packages inputs: - Create test-dangerfile.js demonstrating custom Danger checks - Add extra-dangerfile-test job to verify custom dangerfiles execute correctly - Add extra-packages-test job to verify package installation works - Tests validate that custom dangerfiles can access the Danger API and installed packages 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 240ed21 commit 35ba335

File tree

2 files changed

+104
-0
lines changed

2 files changed

+104
-0
lines changed

.github/test-dangerfile.js

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
// Test dangerfile for exercising extra-dangerfile feature
2+
// This demonstrates how repositories can add custom Danger checks
3+
4+
module.exports = async function ({ fail, warn, message, markdown, danger }) {
5+
console.log('::notice::Running custom dangerfile checks...');
6+
7+
// Test that we have access to the danger API
8+
if (!danger || !danger.github || !danger.github.pr) {
9+
fail('Custom dangerfile cannot access danger API');
10+
return;
11+
}
12+
13+
// Example check: Verify PR has a description
14+
const prBody = danger.github.pr.body;
15+
if (!prBody || prBody.trim().length === 0) {
16+
warn('PR description is empty. Consider adding a description to help reviewers.');
17+
} else {
18+
message('✅ Custom dangerfile check: PR has a description');
19+
}
20+
21+
// Example check: Verify PR title is not too short
22+
const prTitle = danger.github.pr.title;
23+
if (prTitle && prTitle.length < 10) {
24+
warn('PR title is quite short. Consider making it more descriptive.');
25+
} else {
26+
message('✅ Custom dangerfile check: PR title length is reasonable');
27+
}
28+
29+
// Show that we can access git information
30+
const modifiedFiles = danger.git.modified_files || [];
31+
const createdFiles = danger.git.created_files || [];
32+
const totalChangedFiles = modifiedFiles.length + createdFiles.length;
33+
34+
message(`📊 Custom check: This PR changes ${totalChangedFiles} file(s)`);
35+
36+
console.log('::notice::Custom dangerfile checks completed successfully');
37+
};

.github/workflows/danger-workflow-tests.yml

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,70 @@ jobs:
3434
3535
Write-Host "✅ Danger PR analysis completed successfully!"
3636
Write-Host "ℹ️ Check the PR comments for any Danger findings"
37+
38+
# Test extra-dangerfile feature
39+
extra-dangerfile-test:
40+
runs-on: ubuntu-latest
41+
steps:
42+
- uses: actions/checkout@v4
43+
44+
- name: Run danger with extra dangerfile
45+
id: danger-extra
46+
uses: ./danger
47+
with:
48+
extra-dangerfile: '.github/test-dangerfile.js'
49+
50+
- name: Validate danger with extra-dangerfile outputs
51+
env:
52+
DANGER_OUTCOME: ${{ steps.danger-extra.outputs.outcome }}
53+
shell: pwsh
54+
run: |
55+
Write-Host "🔍 Validating Danger action with extra-dangerfile..."
56+
Write-Host "Danger Outcome: '$env:DANGER_OUTCOME'"
57+
58+
# Validate that Danger ran successfully
59+
$env:DANGER_OUTCOME | Should -Be "success"
60+
61+
Write-Host "✅ Danger with extra-dangerfile completed successfully!"
62+
63+
# Test extra-install-packages feature
64+
extra-packages-test:
65+
runs-on: ubuntu-latest
66+
steps:
67+
- uses: actions/checkout@v4
68+
69+
# Create a test dangerfile that requires curl
70+
- name: Create test dangerfile requiring curl
71+
shell: bash
72+
run: |
73+
cat > .github/test-dangerfile-curl.js << 'EOF'
74+
module.exports = async function ({ message, danger }) {
75+
const { execSync } = require('child_process');
76+
try {
77+
const curlVersion = execSync('curl --version', { encoding: 'utf-8' });
78+
message('✅ curl is available: ' + curlVersion.split('\n')[0]);
79+
} catch (err) {
80+
throw new Error('curl command not found - extra-install-packages failed');
81+
}
82+
};
83+
EOF
84+
85+
- name: Run danger with extra packages
86+
id: danger-packages
87+
uses: ./danger
88+
with:
89+
extra-dangerfile: '.github/test-dangerfile-curl.js'
90+
extra-install-packages: 'curl'
91+
92+
- name: Validate danger with extra-install-packages outputs
93+
env:
94+
DANGER_OUTCOME: ${{ steps.danger-packages.outputs.outcome }}
95+
shell: pwsh
96+
run: |
97+
Write-Host "🔍 Validating Danger action with extra-install-packages..."
98+
Write-Host "Danger Outcome: '$env:DANGER_OUTCOME'"
99+
100+
# Validate that Danger ran successfully
101+
$env:DANGER_OUTCOME | Should -Be "success"
102+
103+
Write-Host "✅ Danger with extra-install-packages completed successfully!"

0 commit comments

Comments
 (0)