This GitHub Action can be tested in several ways:
Run the comprehensive test suite:
npm testThis runs:
- Unit tests for
fetchWithRetryanddeleteBranchfunctions - Integration tests with mocked API calls
- Error handling tests for various failure scenarios
npm run test:coverageThis generates a coverage report showing which parts of the code are tested.
npm run test:watchRuns tests in watch mode, re-running when files change.
Test the action against a real LaunchDarkly instance:
# Set your LaunchDarkly credentials
export LAUNCHDARKLY_TOKEN="your-api-token"
export LAUNCHDARKLY_REPO="your-repo-key"
export LAUNCHDARKLY_BRANCH="branch-to-delete"
# Run the manual test
npm run test:manualInstall act to run GitHub Actions locally:
# Install act
brew install act # macOS
# or
curl https://raw.githubusercontent.com/nektos/act/master/install.sh | sudo bash
# Test the action locally
act -j delete-branch --secret GITHUB_TOKEN=your-tokenCreate a test workflow in .github/workflows/test.yml:
name: Test Branch Delete Action
on:
push:
branches: [ test-branch ]
delete:
branches: [ test-branch ]
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Delete LaunchDarkly Branch
uses: ./ # Use local action
with:
access-token: ${{ secrets.LAUNCHDARKLY_TOKEN }}
repo: ${{ github.repository }}
branch: ${{ github.ref_name }}
force: true # Optional: force delete even on non-branch eventsTest the LaunchDarkly API directly:
curl -X POST https://app.launchdarkly.com/api/v2/code-refs/repositories/your-repo/branch-delete-tasks \
-H "Authorization: your-token" \
-H "Content-Type: application/json" \
-d '["branch-to-delete"]'The force option allows you to delete LaunchDarkly branches even when the GitHub event is not a branch delete event:
- Default behavior: Only runs on branch delete events (
ref_type: "branch") - With
force: true: Runs on any delete event (tags, branches, etc.) - Use case: Useful for cleanup workflows or manual branch deletion
Example:
- name: Force Delete Branch
uses: ./
with:
access-token: ${{ secrets.LAUNCHDARKLY_TOKEN }}
branch: "feature-branch"
force: trueThe test suite covers:
- Successful branch deletion
- Custom base URI handling
- URL encoding of repository keys
- Retry logic for rate limits
- API errors (400, 500)
- Network failures
- Missing inputs
- Invalid responses
- Rate limiting (429 responses)
- Server errors (5xx responses)
- Network timeouts
- Exponential backoff
Set the ACTIONS_STEP_DEBUG environment variable:
export ACTIONS_STEP_DEBUG=true
npm run test:manualThe action logs detailed information about:
- Request URLs
- Response status codes
- Error messages
- Retry attempts
The action includes:
- Linting with ESLint
- Formatting with Prettier
- Type checking with TypeScript
- Testing with Jest
- Build verification with NCC
Run all checks:
npm run lint
npm run format
npm run build
npm test
npm run package