Skip to content

Phase 8: unit tests for config, AWS params, and GitHub flow #14

@kurok

Description

@kurok

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-codenpm 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:

  1. 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.
  2. 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.
  3. User-data construction. The bash script assembled in startEc2Instance is a template with interpolation; unit-testable as a string.
  4. 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.jsonjest.

Acceptance criteria

  • Jest + supporting test deps added to package.json devDependencies.
  • tests/ directory with files covering config / aws / gh / index.
  • npm test runs the full suite locally in <10 s.
  • unit-tests job wired into pr.yml and green on this PR and feat: bump actions/runner to v2.333.1 for node24 support #3's follow-ups.
  • Coverage report produced (e.g., via jest --coverage) — no specific threshold, but the numbers are published on the PR.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions