test: add jest unit tests for utils and config (Phase 8.a)#16
Merged
Conversation
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>
This was referenced Apr 20, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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, andsrc/index.jsright 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.jsandsrc/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 forsortByCreationDate(sort order, in-place mutation, single-image, empty array, equal dates).tests/config.test.js— 16 tests for theConfigsingleton. The existing module-scopetry { module.exports = new Config(); } catch (...) { core.setFailed(...) }pattern means validation failures are surfaced via thecore.setFailedmock, not via thrown exceptions — the test helperexpectValidationFailureasserts against that mock's call history. Covers start-mode + stop-mode happy paths, tag-specifications logic, six validation-failure modes, andgenerateUniqueLabeloutput shape.package.json— jest29.7.0devDependency (exact pin) andnpm testscript..github/workflows/pr.yml— newunit-testsjob runningnpm ci && npm testonubuntu-latestwith Node 20.Local verification
Follow-ups
aws.js(EC2Client command shape),gh.js(octokit registration + retry paths), andindex.js(start/stop orchestration).verify-distCI job (from feat: bump actions/runner to v2.333.1 for node24 support #3) is unaffected — jest has no runtime footprint indist/index.js.