test: add unit tests for src/main.ts (#28)#47
Closed
ifauzeee wants to merge 1 commit into
Closed
Conversation
Adds src/main.test.ts (vitest) covering: - parseVersionFile (strips leading v, trims whitespace) - strToBoolean (true/false-ish, case-insensitive) - getVersion (parses the version token; throws on stderr) - resolveVersionInput (explicit version + version-file) - run() cache-key generation (restores cache with key v-<version>-...) Modules are mocked (@actions/core, @actions/cache, @actions/tool-cache, ./installer, child_process) and ./state-helper is mocked so the module does not auto-run during import. The tested functions were exported from main.ts (behavior-preserving) so they can be imported. Rebuild dist via ncc.
Member
|
Thanks @ifauzeee! This PR and #36 by @Neev213 both address the same issue (#28 — add unit tests for src/main.ts). Since #36 has a more comprehensive test suite (539 lines with full mock coverage), would you consider closing this in favor of #36? Or if you prefer to keep this one, could you fix the build failure so we can review it? |
Contributor
Author
|
Closing in favor of #36 by @Neev213, which provides a more comprehensive test suite covering #28. Thanks @ulises-jeremias for the review! |
Member
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.
Summary
Adds
src/main.test.ts(vitest) for #28, covering the entry point's pure/exported logic:parseVersionFile— strips a leadingvand trims whitespace.strToBoolean— true/false-ish inputs, case-insensitive.getVersion— parses the version token fromv versionoutput; throws when stderr is present (the fragile parser called out in the issue).resolveVersionInput— explicit version and version-file inputs.run()— asserts the cache is restored with a key prefixed byv-<version>-.How it's tested
@actions/core,@actions/cache,@actions/tool-cache,./installerandchild_processare mocked;./state-helperis mocked (IS_POST: true) so the module does not auto-runrun()at import.Source change
To make the functions importable from the test,
run,resolveVersionInput,parseVersionFile,strToBooleanandgetVersionwere givenexport(behavior-preserving).dist/was rebuilt.Verification
npx vitest run src/main.test.ts— 10/10 pass.npm run build/npm run packagepass.Closes #28