Part of plan #15. Phase 8 — Testing & CI.
What's already in place
#3 — .github/workflows/pr.yml now runs on all PRs (not just to main):
lint-code — npm run lint.
verify-dist — rebuilds dist/index.js via ncc and fails if it drifts from committed bytes.
verify-runner-url — HEADs the pinned actions/runner release asset.
Coverage today is entirely build-side; zero unit tests.
What's missing
Real unit tests for:
- Config parsing (
src/config.js). Every action input has validation logic (mode must be start/stop; when mode=start, ec2-image-* + instance type + subnet + SG are required; etc.). None of that is tested.
- AWS parameter generation (
src/aws.js). startEc2Instance assembles a complex RunInstances request (ImageId, UserData, TagSpecifications, IamInstanceProfile, BlockDeviceMappings once Phase 6 lands). An errant change silently produces an instance that boots but can't register.
- User-data construction. The bash script assembled in
startEc2Instance is a template with interpolation; unit-testable as a string.
- GitHub API mocks (
src/gh.js). Registration-token retrieval, runner-registered polling, remove-runner flow. Mock @actions/http-client or stub at @actions/github.
Proposed stack
- Jest (already the de-facto GitHub Actions testing framework).
aws-sdk-client-mock once Phase 1 lands (v3 mocking is natively supported). Until then, stub the v2 client.
nock for GitHub API interactions.
Proposed structure
tests/
config.test.js # input parsing + validation
aws.test.js # RunInstances params, user-data string
gh.test.js # registration/removal token flows
index.test.js # start() / stop() orchestration
CI wiring
Extend .github/workflows/pr.yml:
unit-tests:
name: Unit tests
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 20
cache: npm
- run: npm ci
- run: npm test
Add npm test script to package.json → jest.
Acceptance criteria
Part of plan #15. Phase 8 — Testing & CI.
What's already in place
#3—.github/workflows/pr.ymlnow runs on all PRs (not just tomain):lint-code—npm run lint.verify-dist— rebuildsdist/index.jsvianccand fails if it drifts from committed bytes.verify-runner-url— HEADs the pinnedactions/runnerrelease asset.Coverage today is entirely build-side; zero unit tests.
What's missing
Real unit tests for:
src/config.js). Every action input has validation logic (modemust bestart/stop; whenmode=start,ec2-image-*+ instance type + subnet + SG are required; etc.). None of that is tested.src/aws.js).startEc2Instanceassembles a complexRunInstancesrequest (ImageId,UserData,TagSpecifications,IamInstanceProfile,BlockDeviceMappingsonce Phase 6 lands). An errant change silently produces an instance that boots but can't register.startEc2Instanceis a template with interpolation; unit-testable as a string.src/gh.js). Registration-token retrieval, runner-registered polling, remove-runner flow. Mock@actions/http-clientor stub at@actions/github.Proposed stack
aws-sdk-client-mockonce Phase 1 lands (v3 mocking is natively supported). Until then, stub the v2 client.nockfor GitHub API interactions.Proposed structure
CI wiring
Extend
.github/workflows/pr.yml:Add
npm testscript topackage.json→jest.Acceptance criteria
package.jsondevDependencies.tests/directory with files covering config / aws / gh / index.npm testruns the full suite locally in <10 s.unit-testsjob wired intopr.ymland green on this PR and feat: bump actions/runner to v2.333.1 for node24 support #3's follow-ups.jest --coverage) — no specific threshold, but the numbers are published on the PR.