Skip to content

Commit 9737223

Browse files
authored
feat: support vitest unit tests (#6123)
1 parent 9322fdc commit 9737223

20 files changed

Lines changed: 612 additions & 102 deletions

config/test-dependencies.json

Lines changed: 32 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,40 @@
11
[
22
{
3-
"name": "@jsdevtools/coverage-istanbul-loader"
3+
"name": "vitest",
4+
"framework": "vitest",
5+
"version": "~4.1.10"
46
},
57
{
6-
"name": "karma"
8+
"name": "@vitest/runner",
9+
"framework": "vitest",
10+
"version": "~4.1.10"
711
},
812
{
9-
"name": "karma-coverage"
13+
"name": "@nativescript/unit-test-runner",
14+
"framework": "vitest",
15+
"version": "^5.0.0-alpha.0"
1016
},
1117
{
12-
"name": "karma-nativescript-launcher"
18+
"name": "@valor/nativescript-websockets",
19+
"framework": "vitest",
20+
"version": "^2.0.3",
21+
"saveInDependencies": true
22+
},
23+
{
24+
"name": "@jsdevtools/coverage-istanbul-loader",
25+
"frameworks": ["jasmine", "mocha", "qunit"]
26+
},
27+
{
28+
"name": "karma",
29+
"frameworks": ["jasmine", "mocha", "qunit"]
30+
},
31+
{
32+
"name": "karma-coverage",
33+
"frameworks": ["jasmine", "mocha", "qunit"]
34+
},
35+
{
36+
"name": "karma-nativescript-launcher",
37+
"frameworks": ["jasmine", "mocha", "qunit"]
1338
},
1439
{
1540
"name": "mocha",
@@ -53,6 +78,7 @@
5378
"projectType": ".ts"
5479
},
5580
{
56-
"name": "nyc"
81+
"name": "nyc",
82+
"frameworks": ["jasmine", "mocha", "qunit"]
5783
}
58-
]
84+
]

docs/man_pages/project/testing/test-android.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,4 +43,5 @@ Command | Description
4343
--------|------------
4444
[test init](test-init.html) | Configures your project for unit testing with a selected framework.
4545
[test ios](test-ios.html) | Runs the tests in your project on iOS devices or the iOS Simulator.
46+
[test visionos](test-visionos.html) | Runs the tests in your project in the visionOS Simulator or on Apple Vision Pro devices.
4647
<% } %>

docs/man_pages/project/testing/test-init.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ position: 21
99

1010
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.
1111

12+
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.
13+
1214
### Commands
1315

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

1820
### Options
1921

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

2224
<% if(isHtml) { %>
2325

@@ -31,4 +33,5 @@ Command | Description
3133
--------|------------
3234
[test android](test-android.html) | Runs the tests in your project on Android devices or native emulators.
3335
[test ios](test-ios.html) | Runs the tests in your project on iOS devices or the iOS Simulator.
36+
[test visionos](test-visionos.html) | Runs the tests in your project in the visionOS Simulator or on Apple Vision Pro devices.
3437
<% } %>

docs/man_pages/project/testing/test-ios.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,4 +45,5 @@ Command | Description
4545
--------|------------
4646
[test init](test-init.html) | Configures your project for unit testing with a selected framework.
4747
[test android](test-android.html) | Runs the tests in your project on Android devices or native emulators.
48+
[test visionos](test-visionos.html) | Runs the tests in your project in the visionOS Simulator or on Apple Vision Pro devices.
4849
<% } %>
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
<% if (isJekyll) { %>---
2+
title: ns test visionos
3+
position: 24
4+
---<% } %>
5+
6+
# ns test visionos
7+
8+
### Description
9+
10+
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.
11+
12+
<% 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`<% } %>
13+
14+
### Commands
15+
16+
Usage | Synopsis
17+
------|-------
18+
Run tests in the visionOS Simulator | `$ ns test visionos`
19+
Run tests on a selected device | `$ ns test visionos --device <Device ID>`
20+
21+
<% if((isConsole && isMacOS) || isHtml) { %>
22+
23+
### Options
24+
25+
* `--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.
26+
* `--env.codeCoverage` - If set, collects code coverage for the test run.
27+
* `--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`.
28+
29+
<% } %>
30+
31+
<% if(isHtml) { %>
32+
33+
### Prerequisites
34+
35+
* Verify that [you have configured your project for unit testing](test-init.html) with the Vitest framework.
36+
* Verify that [you have stored your unit tests in `app` &#8594; `tests`](http://docs.nativescript.org/testing).
37+
* Verify that [you have configured your system and devices properly](http://docs.nativescript.org/testing).
38+
39+
### Related Commands
40+
41+
Command | Description
42+
--------|------------
43+
[test init](test-init.html) | Configures your project for unit testing with a selected framework.
44+
[test android](test-android.html) | Runs the tests in your project on Android devices or native emulators.
45+
[test ios](test-ios.html) | Runs the tests in your project on iOS devices or the iOS Simulator.
46+
<% } %>

docs/man_pages/project/testing/test.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ Usage | Synopsis
2828
<% if((isConsole && isMacOS) || isHtml) { %>### Arguments
2929
`<Platform>` is the target mobile platform on which you want to run the tests. You can set the following target platforms.
3030
* `android` - Runs the tests in your project on connected Android devices or Android emulators.
31-
* `ios` - Runs the tests in your project on connected iOS devices.<% } %>
31+
* `ios` - Runs the tests in your project on connected iOS devices.
32+
* `visionos` - Runs the tests in your project in the visionOS Simulator or on connected Apple Vision Pro devices. Requires the Vitest testing framework.<% } %>
3233

3334
<% if(isHtml) { %>
3435

@@ -45,4 +46,5 @@ Command | Description
4546
[test init](test-init.html) | Configures your project for unit testing with a selected framework.
4647
[test android](test-android.html) | Runs the tests in your project on Android devices or native emulators.
4748
[test ios](test-ios.html) | Runs the tests in your project on iOS devices or the iOS Simulator.
49+
[test visionos](test-visionos.html) | Runs the tests in your project in the visionOS Simulator or on Apple Vision Pro devices.
4850
<% } %>

lib/bootstrap.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -203,12 +203,16 @@ injector.requireCommand("deploy", "./commands/deploy");
203203
injector.requireCommand("embed", "./commands/embedding/embed");
204204

205205
injector.require("testExecutionService", "./services/test-execution-service");
206+
injector.require(
207+
"vitestExecutionService",
208+
"./services/vitest-execution-service",
209+
);
206210
injector.requireCommand("dev-test|android", "./commands/test");
207211
injector.requireCommand("dev-test|ios", "./commands/test");
208212
injector.requireCommand("test|android", "./commands/test");
209213
injector.requireCommand("test|ios", "./commands/test");
210-
// injector.requireCommand("test|vision", "./commands/test");
211-
// injector.requireCommand("test|visionos", "./commands/test");
214+
injector.requireCommand("test|vision", "./commands/test");
215+
injector.requireCommand("test|visionos", "./commands/test");
212216
injector.requireCommand("test|init", "./commands/test-init");
213217
injector.requireCommand("dev-generate-help", "./commands/generate-help");
214218

0 commit comments

Comments
 (0)