feat: support vitest unit tests - #6123
Conversation
📝 WalkthroughWalkthroughThe CLI now supports Vitest project initialization and execution for NativeScript runtime and UI tests. It adds Vitest dependencies, resources, Android network configuration, framework detection, command routing, and documentation while preserving the Karma flow with deprecation notices. ChangesVitest testing integration
Estimated code review effort: 4 (Complex) | ~45 minutes Sequence Diagram(s)sequenceDiagram
participant TestCommandBase
participant VitestExecutionService
participant Vitest
TestCommandBase->>VitestExecutionService: detect project and validate readiness
VitestExecutionService->>Vitest: start platform-specific non-watch run
Vitest-->>VitestExecutionService: return process status
VitestExecutionService-->>TestCommandBase: complete or report failure
Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@config/test-dependencies.json`:
- Around line 3-22: Regenerate the generated dependency registry from
config/test-dependencies.json using scripts/generate-test-deps.js, and include
the resulting config/test-deps-versions-generated.json with entries for vitest,
`@vitest/runner`, `@nativescript/unit-test-runner`, and
`@valor/nativescript-websockets` so ns test init --framework vitest can resolve
them.
🪄 Autofix
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID: cbfc56e8-3737-417e-9205-85df7cbd4fbd
📒 Files selected for processing (16)
config/test-dependencies.jsondocs/man_pages/project/testing/test-init.mdlib/bootstrap.tslib/commands/test-init.tslib/commands/test.tslib/common/declarations.d.tslib/constants.tslib/definitions/project.d.tslib/services/test-initialization-service.tslib/services/vitest-execution-service.tsresources/test/example.vitest.jsresources/test/example.vitest.tsresources/test/network_security.xmlresources/test/test-main.vitest.jsresources/test/test-main.vitest.tsresources/test/vitest.config.mts
| "name": "vitest", | ||
| "framework": "vitest", | ||
| "version": "~4.1.10" | ||
| }, | ||
| { | ||
| "name": "karma" | ||
| "name": "@vitest/runner", | ||
| "framework": "vitest", | ||
| "version": "~4.1.10" | ||
| }, | ||
| { | ||
| "name": "karma-coverage" | ||
| "name": "@nativescript/unit-test-runner", | ||
| "framework": "vitest", | ||
| "version": "^5.0.0-alpha.0" | ||
| }, | ||
| { | ||
| "name": "karma-nativescript-launcher" | ||
| "name": "@valor/nativescript-websockets", | ||
| "framework": "vitest", | ||
| "version": "^2.0.3", | ||
| "saveInDependencies": true | ||
| }, |
There was a problem hiding this comment.
🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick win
🧩 Analysis chain
🏁 Script executed:
#!/bin/bash
set -euo pipefail
registry="$(fd -a '^test-deps-versions-generated\.json$' config | head -n 1)"
test -n "$registry"
jq -e '
has("vitest") and
has("`@vitest/runner`") and
has("`@nativescript/unit-test-runner`") and
has("`@valor/nativescript-websockets`")
' "$registry"Repository: NativeScript/nativescript-cli
Length of output: 167
🏁 Script executed:
#!/bin/bash
set -euo pipefail
echo "== candidate files =="
fd -a 'test-dependencies\.json|test-deps-versions-generated\.json|test-initialization-service\.ts' config . | sed 's#^\./##'
echo
echo "== generated registry keys matching Vitest/deps (if file exists) =="
registry="$(fd -a '^test-deps-versions-generated\.json$' config . | head -n 1 || true)"
if [ -n "${registry:-}" ]; then
jq 'keys' "$registry" | sed -n '1,120p'
echo
jq '. | {vitest, runner:."`@vitest/runner`", nativescript_runner:."`@nativescript/unit-test-runner`", valor:."`@valor/nativescript-websockets`"}' "$registry"
else
echo "registry file not found"
fi
echo
echo "== references to generated registry / getDependencies =="
rg -n "test-deps-versions-generated|getDependencies|test-initialization-service|vitest|nativescript-websockets" . --glob '!node_modules/**' --glob '!dist/**' --glob '!build/**' | sed -n '1,220p'Repository: NativeScript/nativescript-cli
Length of output: 15797
🏁 Script executed:
#!/bin/bash
set -euo pipefail
echo "== generate-test-deps.js outline and relevant contents =="
wc -l scripts/generate-test-deps.js
sed -n '1,240p' scripts/generate-test-deps.js
echo
echo "== test-initialization-service.ts relevant contents =="
sed -n '1,100p' lib/services/test-initialization-service.ts
echo
echo "== package-version script files =="
fd -a '(package|test)-deps|generate.*deps|deps.*version' scripts config lib test packages --glob '*.{js,ts,json}' | sed -n '1,120p'Repository: NativeScript/nativescript-cli
Length of output: 3992
Run the generated dependency-version script for the new Vitest packages.
scripts/generate-test-deps.js reads config/test-dependencies.json and writes config/test-deps-versions-generated.json. The generated registry is missing now, so ns test init --framework vitest fails before package installation. Add config/test-deps-versions-generated.json or regenerate it.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@config/test-dependencies.json` around lines 3 - 22, Regenerate the generated
dependency registry from config/test-dependencies.json using
scripts/generate-test-deps.js, and include the resulting
config/test-deps-versions-generated.json with entries for vitest,
`@vitest/runner`, `@nativescript/unit-test-runner`, and
`@valor/nativescript-websockets` so ns test init --framework vitest can resolve
them.
Support Vitest as first class default option on unit testing. Other options are still options as well on init.
Companion for NativeScript/nativescript-unit-test-runner#80
Summary by CodeRabbit
New Features
Documentation
Bug Fixes