Skip to content

feat: support vitest unit tests - #6123

Open
NathanWalker wants to merge 1 commit into
mainfrom
feat/vitest-unit-tests
Open

feat: support vitest unit tests#6123
NathanWalker wants to merge 1 commit into
mainfrom
feat/vitest-unit-tests

Conversation

@NathanWalker

@NathanWalker NathanWalker commented Aug 8, 2026

Copy link
Copy Markdown
Contributor

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

    • Added Vitest support for project initialization and test execution.
    • Enabled NativeScript unit and UI tests on Android and iOS devices.
    • Added platform, device, and coverage options for Vitest runs.
    • Added sample Vitest configurations and test templates.
    • Added support for framework-specific dependency installation.
  • Documentation

    • Documented Vitest as the recommended testing framework.
    • Marked Karma-based testing frameworks as deprecated.
  • Bug Fixes

    • Improved Android test connectivity through local WebSocket network configuration.

@NathanWalker
NathanWalker requested a review from edusperoni August 8, 2026 04:03
@coderabbitai

coderabbitai Bot commented Aug 8, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

The 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.

Changes

Vitest testing integration

Layer / File(s) Summary
Framework contracts and dependency selection
config/test-dependencies.json, lib/constants.ts, lib/common/declarations.d.ts, lib/definitions/project.d.ts, lib/services/test-initialization-service.ts
Vitest is added as a supported framework. Dependency metadata supports multiple frameworks and native packages in dependencies. The Vitest execution service contract is defined.
Vitest project initialization
lib/commands/test-init.ts, resources/test/*, docs/man_pages/project/testing/test-init.md
Initialization creates Vitest configuration, entrypoints, sample tests, Android network security settings, and framework-specific instructions.
Vitest test execution
lib/bootstrap.ts, lib/commands/test.ts, lib/services/vitest-execution-service.ts
Vitest projects use readiness checks and platform-specific Vitest execution. Karma projects retain their existing flow and receive deprecation warnings.

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
Loading

Possibly related PRs

Poem

I hop through Vitest paths with cheer,
NativeScript tests now start clear.
WebSockets cross the local night,
Device checks guide each run right.
Karma fades, while new tests glow.
Squeak, said the rabbit, ship it so!

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the pull request's main change: adding Vitest support for unit tests.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

📥 Commits

Reviewing files that changed from the base of the PR and between 9322fdc and 51352d9.

📒 Files selected for processing (16)
  • config/test-dependencies.json
  • docs/man_pages/project/testing/test-init.md
  • lib/bootstrap.ts
  • lib/commands/test-init.ts
  • lib/commands/test.ts
  • lib/common/declarations.d.ts
  • lib/constants.ts
  • lib/definitions/project.d.ts
  • lib/services/test-initialization-service.ts
  • lib/services/vitest-execution-service.ts
  • resources/test/example.vitest.js
  • resources/test/example.vitest.ts
  • resources/test/network_security.xml
  • resources/test/test-main.vitest.js
  • resources/test/test-main.vitest.ts
  • resources/test/vitest.config.mts

Comment on lines +3 to +22
"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
},

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🗄️ 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.

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.

2 participants