Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 32 additions & 6 deletions config/test-dependencies.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,40 @@
[
{
"name": "@jsdevtools/coverage-istanbul-loader"
"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
},
Comment on lines +3 to +22

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.

{
"name": "@jsdevtools/coverage-istanbul-loader",
"frameworks": ["jasmine", "mocha", "qunit"]
},
{
"name": "karma",
"frameworks": ["jasmine", "mocha", "qunit"]
},
{
"name": "karma-coverage",
"frameworks": ["jasmine", "mocha", "qunit"]
},
{
"name": "karma-nativescript-launcher",
"frameworks": ["jasmine", "mocha", "qunit"]
},
{
"name": "mocha",
Expand Down Expand Up @@ -53,6 +78,7 @@
"projectType": ".ts"
},
{
"name": "nyc"
"name": "nyc",
"frameworks": ["jasmine", "mocha", "qunit"]
}
]
]
1 change: 1 addition & 0 deletions docs/man_pages/project/testing/test-android.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,5 @@ Command | Description
--------|------------
[test init](test-init.html) | Configures your project for unit testing with a selected framework.
[test ios](test-ios.html) | Runs the tests in your project on iOS devices or the iOS Simulator.
[test visionos](test-visionos.html) | Runs the tests in your project in the visionOS Simulator or on Apple Vision Pro devices.
<% } %>
5 changes: 4 additions & 1 deletion docs/man_pages/project/testing/test-init.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ position: 21

Configures your project for unit testing with a selected framework. This operation installs the @nativescript/unit-test-runner npm module and its dependencies and creates a `tests` folder in the `app` directory.

The recommended framework is `vitest`, which runs your specs inside real NativeScript runtimes on device/emulator and also supports UI testing. The Karma-based frameworks (jasmine, mocha, qunit) are deprecated and will be removed in a future release.

### Commands

Usage | Synopsis
Expand All @@ -17,7 +19,7 @@ General | `$ ns test init [--framework <Framework>]`

### Options

* `--framework <Framework>` - Sets the unit testing framework to install. The following frameworks are available: mocha, jasmine and qunit.
* `--framework <Framework>` - Sets the unit testing framework to install. The following frameworks are available: vitest (recommended), mocha, jasmine and qunit (deprecated).

<% if(isHtml) { %>

Expand All @@ -31,4 +33,5 @@ Command | Description
--------|------------
[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.
[test visionos](test-visionos.html) | Runs the tests in your project in the visionOS Simulator or on Apple Vision Pro devices.
<% } %>
1 change: 1 addition & 0 deletions docs/man_pages/project/testing/test-ios.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,5 @@ Command | Description
--------|------------
[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 visionos](test-visionos.html) | Runs the tests in your project in the visionOS Simulator or on Apple Vision Pro devices.
<% } %>
46 changes: 46 additions & 0 deletions docs/man_pages/project/testing/test-visionos.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<% if (isJekyll) { %>---
title: ns test visionos
position: 24
---<% } %>

# ns test visionos

### Description

Runs the tests in your project in the visionOS Simulator or on connected Apple Vision Pro devices.<% if(isConsole && isMacOS) { %> Your project must already be configured for unit testing with the Vitest framework by running `$ ns test init --framework vitest`.<% } %> Unit testing on visionOS requires the Vitest testing framework; the deprecated Karma-based frameworks are not supported on this platform.

<% if(isConsole && (isLinux || isWindows)) { %>WARNING: You can run this command only on macOS systems. To view the complete help for this command, run `$ ns help test visionos`<% } %>

### Commands

Usage | Synopsis
------|-------
Run tests in the visionOS Simulator | `$ ns test visionos`
Run tests on a selected device | `$ ns test visionos --device <Device ID>`

<% if((isConsole && isMacOS) || isHtml) { %>

### Options

* `--device` - Specifies the serial number or the index of the connected device on which you want to run tests. To list all connected devices, grouped by platform, run `$ ns device`. `<Device ID>` is the device index or identifier as listed by the `$ ns device` command.
* `--env.codeCoverage` - If set, collects code coverage for the test run.
* `--force` - If set, skips the application compatibility checks and forces `npm i` to ensure all dependencies are installed. Otherwise, the command will check the application compatibility with the current CLI version and could fail requiring `ns migrate`.

<% } %>

<% if(isHtml) { %>

### Prerequisites

* Verify that [you have configured your project for unit testing](test-init.html) with the Vitest framework.
* Verify that [you have stored your unit tests in `app` &#8594; `tests`](http://docs.nativescript.org/testing).
* Verify that [you have configured your system and devices properly](http://docs.nativescript.org/testing).

### Related Commands

Command | Description
--------|------------
[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

4 changes: 3 additions & 1 deletion docs/man_pages/project/testing/test.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ Usage | Synopsis
<% if((isConsole && isMacOS) || isHtml) { %>### Arguments
`<Platform>` is the target mobile platform on which you want to run the tests. You can set the following target platforms.
* `android` - Runs the tests in your project on connected Android devices or Android emulators.
* `ios` - Runs the tests in your project on connected iOS devices.<% } %>
* `ios` - Runs the tests in your project on connected iOS devices.
* `visionos` - Runs the tests in your project in the visionOS Simulator or on connected Apple Vision Pro devices. Requires the Vitest testing framework.<% } %>

<% if(isHtml) { %>

Expand All @@ -45,4 +46,5 @@ Command | Description
[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.
[test visionos](test-visionos.html) | Runs the tests in your project in the visionOS Simulator or on Apple Vision Pro devices.
<% } %>
8 changes: 6 additions & 2 deletions lib/bootstrap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -203,12 +203,16 @@ injector.requireCommand("deploy", "./commands/deploy");
injector.requireCommand("embed", "./commands/embedding/embed");

injector.require("testExecutionService", "./services/test-execution-service");
injector.require(
"vitestExecutionService",
"./services/vitest-execution-service",
);
injector.requireCommand("dev-test|android", "./commands/test");
injector.requireCommand("dev-test|ios", "./commands/test");
injector.requireCommand("test|android", "./commands/test");
injector.requireCommand("test|ios", "./commands/test");
// injector.requireCommand("test|vision", "./commands/test");
// injector.requireCommand("test|visionos", "./commands/test");
injector.requireCommand("test|vision", "./commands/test");
injector.requireCommand("test|visionos", "./commands/test");
injector.requireCommand("test|init", "./commands/test-init");
injector.requireCommand("dev-generate-help", "./commands/generate-help");

Expand Down
Loading