Skip to content

Add CLI tests and run the build in CI - #25

Merged
friederbluemle merged 2 commits into
fbluemle:masterfrom
friederbluemle:cli-tests
Sep 4, 2026
Merged

friederbluemle merged 2 commits into
fbluemle:masterfrom
friederbluemle:cli-tests

Conversation

@friederbluemle

Copy link
Copy Markdown
Contributor

Nothing exercised the CLI layer so far: option parsing and validation, the stdout/stderr split, exit codes, and the package.json lookup relative to dist/ were only checked by hand. This adds black-box tests that spawn node dist/cli.js in temporary projects and assert exact output, so the flags, formats and exit codes are pinned down as a contract ahead of 1.0.

  • 26 tests across sync (--dry-run, --version-name, --version-code, --reserve-builds, --project-dir, the missing-file warning and failure), reads (each --print* flag, --format, --configuration, a relative --gradle-path), option validation (every rejected combination with its exact message), and --version / --help.
  • A vitest globalSetup builds dist before each run, so yarn test never tests a stale binary. The whole suite still runs in about 1.5 s. The config is vitest.config.mts because Vite loads a .ts config as CommonJS in a package without "type": "module" and warns about it.
  • CI runs yarn build between yarn tsc and yarn test. The type-check is noEmit, so declaration emit was only exercised at release time. The test setup rebuilds anyway; the explicit step documents the intent and does not depend on how the tests are wired.

The library was covered, but nothing exercised the CLI itself: option
parsing and validation, the stdout/stderr split that scripts and
GITHUB_ENV rely on, exit codes, or the package.json lookup relative to
dist/. The new tests spawn node dist/cli.js in temporary projects and
assert exact output, so the flags and formats are pinned down as a
contract.

A vitest globalSetup builds dist before each run, so `yarn test` never
tests a stale binary. The config uses the .mts extension because Vite
loads a .ts config as CommonJS in a package without "type": "module".
`yarn tsc` type-checks with noEmit and covers the tests, but declaration
emit is only exercised by the build, so an emit-only error would have
surfaced first during a release. CI now builds explicitly between the
type-check and the tests. The test setup rebuilds dist as well; the
separate step makes the intent visible in the workflow and does not
depend on how the tests are wired.
@friederbluemle
friederbluemle merged commit cb59e6b into fbluemle:master Sep 4, 2026
3 checks passed
@friederbluemle
friederbluemle deleted the cli-tests branch September 4, 2026 06:33
@github-actions

github-actions Bot commented Sep 4, 2026

Copy link
Copy Markdown
Contributor

🎉 Released in v0.7.0

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