Skip to content

test(openui-cli): add unit tests for CLI helper functions#611

Open
Shinyaigeek wants to merge 1 commit into
thesysdev:mainfrom
Shinyaigeek:test/openui-cli-helper-tests
Open

test(openui-cli): add unit tests for CLI helper functions#611
Shinyaigeek wants to merge 1 commit into
thesysdev:mainfrom
Shinyaigeek:test/openui-cli-helper-tests

Conversation

@Shinyaigeek
Copy link
Copy Markdown
Contributor

Summary

Closes #554.

Adds a Vitest test suite for packages/openui-cli, which previously had no test coverage, covering the two isolated helper functions called out in the issue.

Tests added

  • src/lib/__tests__/detect-package-manager.test.ts (7 tests) — detectPackageManager() returns pnpm dlx / yarn dlx / bunx / npx based on npm_config_user_agent, plus edge cases (unset agent, unrecognized agent, and that matching is prefix-based rather than substring). The env var is saved/restored around each test.
  • src/lib/__tests__/resolve-args.test.ts (8 tests) — resolveArgs():
    • returns provided { value } args without prompting (interactive and non-interactive)
    • exits with code 1 + logs an error on a missing required arg when non-interactive
    • prompts via input and select when interactive (@inquirer/prompts mocked — no real input)
    • mixes provided values with prompted ones, preserving keys
    • exits cleanly (code 0) on user cancel (ExitPromptError)
    • rethrows unexpected prompt errors

Supporting changes

  • package.json: added a test script (vitest run) and vitest devDependency (matching the version used by lang-core).
  • tsconfig.test.json: added to match the convention used by the other packages so the repo's typed ESLint config can lint the test files.
  • tsconfig.json: excluded **/__tests__/** and **/*.test.ts from the tsc build so test files don't leak into the published dist/.

Acceptance criteria

  • The CLI package has a working test script — 15 tests pass
  • Helper tests are deterministic and do not require real interactive input (inquirer + process.exit mocked)
  • Existing build/lint scripts continue to work (build, lint:check, format:check/ci all pass; dist/ stays free of test artifacts)

🤖 Generated with Claude Code

Add a Vitest setup for the openui-cli package covering the isolated
helper functions, which previously had no test coverage.

- detectPackageManager(): asserts pnpm dlx / yarn dlx / bunx / npx
  selection based on npm_config_user_agent, plus unset/unknown and
  prefix-vs-substring edge cases
- resolveArgs(): provided values returned without prompting, missing
  required arg exits 1 when non-interactive, interactive input/select
  prompting (inquirer mocked), user-cancel exits 0, and unexpected
  prompt errors rethrow

Adds a `test` script and vitest devDependency, a tsconfig.test.json
matching the other packages so typed ESLint can lint the tests, and
excludes test files from the tsc build so they stay out of dist/.

Closes thesysdev#554

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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.

Add unit tests for OpenUI CLI helper functions

1 participant