Skip to content

test: add unit tests for src/main.ts#66

Open
ifauzeee wants to merge 2 commits into
vlang:mainfrom
ifauzeee:test/add-main-unit-tests
Open

test: add unit tests for src/main.ts#66
ifauzeee wants to merge 2 commits into
vlang:mainfrom
ifauzeee:test/add-main-unit-tests

Conversation

@ifauzeee

@ifauzeee ifauzeee commented Jul 15, 2026

Copy link
Copy Markdown
Contributor

Summary

Adds src/main.test.ts with vitest unit tests for src/main.ts, which previously had no coverage.

Covers the three fragile areas called out in #28:

  • Version file parsingparseVersionFile (strips v prefix, trims whitespace) and resolveVersionInput (explicit version vs. reading a version-file).
  • Cacherun() builds a v-<version>-<platform>-<arch> cache key and calls restoreCache.
  • Version string parsinggetVersion parses the second token of v version output and throws on stderr.

@actions/core, @actions/cache, @actions/tool-cache, ./installer, and child_process are mocked so no real V install/download occurs. dist/ was rebuilt via npm run package.

Test plan

  • npx vitest run src/main.test.ts — 10 passing.
  • npm run lint and npm run build clean.

Closes #28

@ulises-jeremias

Copy link
Copy Markdown
Member

@ifauzeee thanks for the tests! The CI build is failing — the error says the version file doesn't exist when running the run test. The issue might be that resolveVersionInput checks version-file first and the mock state leaks between tests. Try checking if getInput('version-file') is returning something unexpected during the run test. Also ensure all mocks are properly reset.

The test structure looks solid overall — once CI passes this is ready to merge!

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.
@ifauzeee ifauzeee force-pushed the test/add-main-unit-tests branch from c729406 to 2c9fc37 Compare July 16, 2026 08:59
… temp files

- Replace real temp file creation with vi.hoisted + vi.mock('fs')
  to avoid GITHUB_WORKSPACE path mismatch in CI
- Add execSync to child_process mock so cleanup() doesn't
  silently fail during module import (IS_POST=true)
- Reset fs mocks in beforeEach to prevent cross-test state leakage

Closes vlang#28
@ifauzeee

Copy link
Copy Markdown
Contributor Author

Quick correction to the previous comment — shell escaping mangled some characters.

The vitest build now passes (53/53 ✅). The test-action integration failures are pre-existing and unrelated to this PR:

  • macOS: V compiler fails to bootstrap — float.c.v throws invalid $if condition: unknown indent 'native' (V language syntax change in master that broke the bootstrap).
  • Windows: Linker fails with LNK2019: unresolved external symbol sscanf (Clang compatibility issue).
  • Linux: Bootstrap fails with transient/compiler errors.

These same failures appear on other PRs (Dependabot #62-#68) that only bump deps. The fix for tagged versions was already merged in #60 (prebuilt binary), but the test-action jobs that don't specify a version still build from source — which is currently broken upstream.

This PR only adds unit tests — none of the failures above are caused by this change. Ready to merge.

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.

test: add unit tests for src/main.ts

2 participants