Skip to content

[Test Improver] Add unit tests for useRuntimeFlag composable - #49

Draft
github-actions[bot] wants to merge 1 commit into
masterfrom
test-assist/use-runtime-flag-9bde3411d8062ca6
Draft

[Test Improver] Add unit tests for useRuntimeFlag composable#49
github-actions[bot] wants to merge 1 commit into
masterfrom
test-assist/use-runtime-flag-9bde3411d8062ca6

Conversation

@github-actions

Copy link
Copy Markdown

🤖 Test Improver — automated AI assistant

Goal and Rationale

shell/composables/useRuntimeFlag.ts had zero test coverage despite containing meaningful semver-based version-gating logic:

  • featureDropdownMenu uses semver.coerce() to normalise version strings (strips v prefixes, pre-release tags, uncoercible strings fall back to 0.0.0)
  • Then semver.gte() compares against the 2.11.0 boundary

Bugs here would silently disable the dropdown menu feature for all users.

Approach

  • Mock @shell/utils/version.getVersionInfo to return a reactive ref-backed version string
  • The featureDropdownMenu computed auto-invalidates when mockVersion.value changes (Vue reactive dependency tracking)
  • Single it.each table with 8 cases — no jest.isolateModules needed
  • useRuntimeFlag({} as any) called once at describe-level; the returned featureDropdownMenu ref is shared across all entries

Coverage Impact

File Stmts Branch Funcs Lines
Before 0 % 0 % 0 % 0 %
After 87 % 100 % 50 % 87 %

Statement/function coverage is < 100 % because useRuntimeFlag itself (the trivial one-liner setter) is not separately tested per project guidelines ("What NOT to Test").

Test Cases

Version input Expected
2.11.0 true (at boundary)
2.12.0 true (above boundary)
v2.11.0 true (v-prefixed, coerced to 2.11.0)
2.11.0-rc1 true (pre-release, coerced to 2.11.0)
2.10.9 false (just below boundary)
2.0.0 false (well below boundary)
dev false (uncoercible → falls back to 0.0.0)
unknown false (uncoercible → falls back to 0.0.0)

Test Status

PASS shell/composables/useRuntimeFlag.test.ts
Tests: 8 passed, 8 total
ESLint: 0 warnings, 0 errors

Reproducibility

# run tests
NODE_OPTIONS=--max_old_space_size=8192 node_modules/.bin/jest --no-coverage shell/composables/useRuntimeFlag.test.ts

# lint
node_modules/.bin/eslint --max-warnings 0 shell/composables/useRuntimeFlag.test.ts

Trade-offs

  • The reactive-ref mock approach avoids jest.isolateModules boilerplate while correctly invalidating Vue's computed cache between test entries
  • Low maintenance burden: tests are table-driven and only test meaningful logic branches

Warning

Firewall blocked 1 domain

The following domain was blocked by the firewall during workflow execution:

  • download.cypress.io

To allow these domains, add them to the network.allowed list in your workflow frontmatter:

network:
  allowed:
    - defaults
    - "download.cypress.io"

See Network Configuration for more information.

Generated by Daily Test Improver · ● 4M ·

8 table-driven tests covering featureDropdownMenu computed:
- versions at, above, and below the 2.11.0 boundary
- v-prefixed and pre-release version strings
- uncoercible strings (dev, unknown) fall back to 0.0.0

Uses a reactive ref mock so Vue's computed re-evaluates on
each it.each entry without needing jest.isolateModules.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

0 participants