Skip to content

test: add jest unit tests for utils and config (Phase 8.a)#16

Merged
kurok merged 1 commit into
feat/al2023-supportfrom
test/14-jest-unit-tests
Apr 20, 2026
Merged

test: add jest unit tests for utils and config (Phase 8.a)#16
kurok merged 1 commit into
feat/al2023-supportfrom
test/14-jest-unit-tests

Conversation

@kurok
Copy link
Copy Markdown

@kurok kurok commented Apr 20, 2026

Part of plan #15. Phase 8.a of the unit-test effort tracked in #14.

Scope note — why split Phase 8

Writing tests against src/aws.js, src/gh.js, and src/index.js right now means testing code that Phases 1, 4, and 5 will rewrite within this modernization plan. Those tests would be thrown away mid-rewrite. This PR lands tests only for the two files that are not on the rewrite list — src/utils.js and src/config.js — which gives the test harness a foothold without wasted effort. The remaining modules get their tests as part of each rewrite PR, under a Phase 8.b follow-up.

What's in

  • tests/utils.test.js — 5 tests for sortByCreationDate (sort order, in-place mutation, single-image, empty array, equal dates).
  • tests/config.test.js — 16 tests for the Config singleton. The existing module-scope try { module.exports = new Config(); } catch (...) { core.setFailed(...) } pattern means validation failures are surfaced via the core.setFailed mock, not via thrown exceptions — the test helper expectValidationFailure asserts against that mock's call history. Covers start-mode + stop-mode happy paths, tag-specifications logic, six validation-failure modes, and generateUniqueLabel output shape.
  • package.json — jest 29.7.0 devDependency (exact pin) and npm test script.
  • .github/workflows/pr.yml — new unit-tests job running npm ci && npm test on ubuntu-latest with Node 20.

Local verification

$ npm test
PASS tests/config.test.js
PASS tests/utils.test.js

Test Suites: 2 passed, 2 total
Tests:       21 passed, 21 total
Time:        0.273 s

Follow-ups

  • Phase 8.b issue will be filed once Phases 1 / 4 / 5 land — that issue tracks tests for aws.js (EC2Client command shape), gh.js (octokit registration + retry paths), and index.js (start/stop orchestration).
  • The existing verify-dist CI job (from feat: bump actions/runner to v2.333.1 for node24 support #3) is unaffected — jest has no runtime footprint in dist/index.js.

Scope note: this PR covers Phase 8 (issue #14) only for src/utils.js
and src/config.js. Tests for src/aws.js, src/gh.js, and src/index.js
are deferred to Phase 8.b, to be filed as a follow-up issue after
Phases 1, 4, and 5 rewrite those files — testing them now against
the aws-sdk v2 shape would be thrown away mid-rewrite.

What landed:

- tests/utils.test.js — sortByCreationDate covering sort order,
  in-place mutation, single-image, empty-array, and equal-date
  cases (5 tests).

- tests/config.test.js — Config constructor validation and outputs.
  The module-scope singleton pattern means every test case calls
  loadConfig(inputs) which jest.resetModules() + mocks
  @actions/core / @actions/github + re-requires. Validation
  failures don't throw — the try/catch around 'new Config()'
  routes them to core.setFailed(), so tests assert against that
  mock's .calls array via expectValidationFailure() helper.
  Covers start-mode happy path, tag specifications logic,
  stop-mode happy path, six validation-failure modes, and
  generateUniqueLabel output shape (16 tests).

Tooling:

- jest 29.7.0 added as devDependency (pinned exact).
- 'npm test' script wired in package.json.
- 'unit-tests' job added to .github/workflows/pr.yml alongside the
  existing lint-code / verify-dist / verify-runner-url jobs.

Verified locally: 'npm test' reports 'Test Suites: 2 passed,
Tests: 21 passed' in ~0.3 s.

Signed-off-by: yuriyryabikov <22548029+kurok@users.noreply.github.com>
@kurok kurok merged commit 8b8869f into feat/al2023-support Apr 20, 2026
4 checks passed
@kurok kurok deleted the test/14-jest-unit-tests branch April 20, 2026 21:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant