Skip to content

feat: support vitest unit tests - #6123

Open
NathanWalker wants to merge 2 commits into
mainfrom
feat/vitest-unit-tests
Open

feat: support vitest unit tests#6123
NathanWalker wants to merge 2 commits 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 testing on Android, iOS, and visionOS devices.
    • Added platform, device, and coverage options for Vitest runs.
    • Added sample Vitest configurations and test templates.
    • Added framework-specific dependency installation support.
  • Documentation

    • Documented Vitest as the recommended testing framework.
    • Added visionOS testing commands and guidance.
    • 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 initialization and execution for NativeScript runtime, UI, and visionOS tests. It adds 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/*
Initialization creates Vitest configuration, entrypoints, sample tests, Android network security settings, and framework-specific instructions. Documentation adds visionOS testing.
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. The test visionos command is enabled. 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

Suggested reviewers: edusperoni

Poem

I hop through Vitest paths with cheer,
NativeScript tests now start clear.
WebSockets cross the local night,
VisionOS runs come into sight.
Karma waits 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 unit-test support.
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.

@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 `@docs/man_pages/project/testing/test-visionos.md`:
- Line 46: Insert a blank line immediately before the `<% } %>` template
directive in the Markdown table section so the table is terminated before the
directive and markdownlint MD056 no longer treats it as a table row.
🪄 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: 10473ce5-0101-4493-9052-9b4c7954cabe

📥 Commits

Reviewing files that changed from the base of the PR and between 51352d9 and 764e577.

📒 Files selected for processing (9)
  • docs/man_pages/project/testing/test-android.md
  • docs/man_pages/project/testing/test-init.md
  • docs/man_pages/project/testing/test-ios.md
  • docs/man_pages/project/testing/test-visionos.md
  • docs/man_pages/project/testing/test.md
  • lib/bootstrap.ts
  • lib/commands/test-init.ts
  • lib/commands/test.ts
  • resources/test/vitest.config.mts
🚧 Files skipped from review as they are similar to previous changes (4)
  • lib/bootstrap.ts
  • resources/test/vitest.config.mts
  • docs/man_pages/project/testing/test-init.md
  • lib/commands/test-init.ts

[test init](test-init.html) | Configures your project for unit testing with a selected framework.
[test android](test-android.html) | Runs the tests in your project on Android devices or native emulators.
[test ios](test-ios.html) | Runs the tests in your project on iOS devices or the iOS Simulator.
<% } %>

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win

End the Markdown table before the template directive.

Line 46 is parsed as a one-column table row. markdownlint-cli2 reports MD056. Insert a blank line before <% } %>.

Proposed fix
 [test ios](test-ios.html) | Runs the tests in your project on iOS devices or the iOS Simulator.
+
 <% } %>
🧰 Tools
🪛 markdownlint-cli2 (0.23.2)

[warning] 46-46: Table column count
Expected: 2; Actual: 1; Too few cells, row will be missing data

(MD056, table-column-count)

🤖 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 `@docs/man_pages/project/testing/test-visionos.md` at line 46, Insert a blank
line immediately before the `<% } %>` template directive in the Markdown table
section so the table is terminated before the directive and markdownlint MD056
no longer treats it as a table row.

Source: Linters/SAST tools

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