Skip to content

Commit b53ec90

Browse files
Merge pull request #13417 from Mikejo5000/mikejo-br25
Update unit testing JSTS article for Vitest
2 parents 80dbcef + 2304dc6 commit b53ec90

File tree

2 files changed

+36
-20
lines changed

2 files changed

+36
-20
lines changed

docs/debugger/hot-reload.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ monikerRange: '>= vs-2022'
1616

1717
Starting in Visual Studio 2022, the Hot Reload experience in Visual Studio works for both managed .NET and native C++ apps. Regardless of the type of app you’re working on, the intention of Hot Reload is to save you as many app restarts between edits as possible, making you more productive by reducing the time you spend waiting for apps to rebuild, restart, re-navigate to the previous location where you were in the app itself, et al.
1818

19-
We accomplish this by making it possible for you to edit your application's code files and apply the code changes immediately to the running application, also known as *Hot Reload*. Once your changes are applied, re-execute your code again by taking an action in the app itself (or through some sort of timer, etc.) and see the changes immediately; no pausing of the app through breakpoints is required!
19+
We improve productivity by making it possible for you to edit your application's code files and apply the code changes immediately to the running application, also known as *Hot Reload*. Once your changes are applied, re-execute your code again by taking an action in the app itself (or through some sort of timer, etc.) and see the changes immediately; no pausing of the app through breakpoints is required!
2020

2121
## Update running code with Hot Reload
2222

@@ -34,9 +34,9 @@ To see the changes in the user interface, the code needs to be re-executed. For
3434

3535
## Support for .NET applications
3636

37-
* **When using Visual Studio 2022 and starting your app with the debugger**, the basic Hot Reload experience works with most types of .NET apps and framework versions. This includes .NET Framework, .NET Core and .NET 5+ (for both C# and Visual Basic as applicable). The expectation in this scenario is that if you’re using the debugger, assume Hot Reload is available to you and give it a try!
38-
* **When using Visual Studio 2022 but not using the debugger** (for example, using CTRL-F5 to start the app), Hot Reload is available when targeting most types of .NET 6 apps. This means that apps not targeting .NET 6 (.NET 5 or below) don't support the "no debugger" scenario and must use the debugger to get Hot Reload support.
39-
* **When using Visual Studio 2022 with a .NET 6 app, most scenarios are supported**. This isn't limited to the new "no debugger" feature mentioned above. It also includes other new capabilities, such as support for hot reloading Blazor projects and, more generally, editing Razor files in any ASP.NET Core apps, and CSS Hot Reload. Using Visual Studio 2022 and apps that target .NET 6 together will give you the most powerful Hot Reload experience.
37+
* **When using Visual Studio 2022 and starting your app with the debugger**, the basic Hot Reload experience works with most types of .NET apps and framework versions. This support includes .NET Framework, .NET Core and .NET 5+ (for both C# and Visual Basic as applicable). The expectation in this scenario is that if you’re using the debugger, assume Hot Reload is available to you and give it a try!
38+
* **When using Visual Studio 2022 but not using the debugger** (for example, using CTRL-F5 to start the app), Hot Reload is available when targeting most types of .NET 6 apps. In this scenario, apps not targeting .NET 6+ (that is, they target .NET 5 or below) don't support the "no debugger" scenario and must use the debugger to get Hot Reload support.
39+
* **When using Visual Studio 2022 with a .NET 6+ app, most scenarios are supported**. This support isn't limited to the new "no debugger" feature mentioned above. It also includes other new capabilities, such as support for hot reloading Blazor projects and, more generally, editing Razor files in any ASP.NET Core apps, and CSS Hot Reload. Using Visual Studio 2022 and apps that target .NET 6 together gives you the most powerful Hot Reload experience.
4040

4141
The following table shows which projects support .NET Hot Reload with the debugger attached (F5) and without the debugger attached (Ctrl+F5), according to the minimum .NET version required for support in Visual Studio 2022 (17.8).
4242

@@ -54,13 +54,13 @@ The following table shows which projects support .NET Hot Reload with the debugg
5454

5555
The [types of edits you can make](../debugger/supported-code-changes-csharp.md) with Hot Reload are determined by the runtime and compiler version, not by the method you used to start the application (F5 or Ctrl+F5).
5656

57-
In the following sections, we’ll expand on the above summary and dive into more details.
57+
In the following sections, we provide additional details.
5858

5959
## Support for C++ applications
6060

6161
When using Visual Studio 2022 and starting your app with the debugger, you can hot reload a native C++ application when running under the debugger (F5) using the **Hot Reload** button. Hot Reload is also supported for apps built using CMake and OpenFolder projects.
6262

63-
In order for your project to support Hot Reload, you will need:
63+
For your project to support Hot Reload, you need the following options set:
6464

6565
* Project > Properties > C/C++ > General > **Debug Information Format** must be set to "Program Database for Edit and Continue `/ZI`"
6666
* Project > Properties > Linker > General > **Enable Incremental Linking** must be set to "Yes `/INCREMENTAL`"
@@ -74,15 +74,15 @@ When using Visual Studio 2022 and starting the app with the debugger, Hot Reload
7474
Anywhere you have .NET and you’re using the Visual Studio managed debugger, you should get basic Hot Reload support. This fact means that even projects such as Azure Functions work great in this scenario.
7575

7676
> [!NOTE]
77-
> Some projects use by default mixed mode debugging, which does not support Hot Reload. You can modify this in project settings, by setting **Project > Properties > Debug > Open debug launch profiles UI > Enable native code debugging** to false.
77+
> By default, some projects use mixed mode debugging, which does not support Hot Reload. You can modify this setting in project settings, by setting **Project > Properties > Debug > Open debug launch profiles UI > Enable native code debugging** to false.
7878
7979
## Visual Studio 2022 with a .NET app, but not using the debugger
8080

8181
Hot Reload is available without the debugger when targeting most types of .NET 6+ apps.
8282

83-
This feature is exclusive to .NET 6+. Those apps not targeting .NET 6+ (that is, .NET 5 or below) will not support the "no debugger" scenario and must use the debugger to get access to Hot Reload functionality.
83+
This feature is exclusive to .NET 6+. Those apps not targeting .NET 6+ (that is, they target .NET 5 or below) do not support the "no debugger" scenario and must use the debugger to get access to Hot Reload functionality.
8484

85-
Also, be aware that not all project types currently support the "no debugger" scenario, see [Support for .NET applications](#support-for-net-applications).
85+
Also, not all project types currently support the "no debugger" scenario, see [Support for .NET applications](#support-for-net-applications).
8686

8787
## Visual Studio 2022 with a .NET 6+ app
8888

docs/javascript/unit-testing-javascript-with-visual-studio.md

Lines changed: 27 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
title: "Unit testing JavaScript and TypeScript"
33
description: Explore unit testing support in Visual Studio for JavaScript and TypeScript code by using the Node.js Tools for Visual Studio.
4-
ms.date: "11/16/2023"
4+
ms.date: "12/06/2024"
55
ms.topic: "how-to"
66
ms.devlang: javascript
77
author: "mikejo5000"
@@ -15,11 +15,22 @@ dev_langs:
1515

1616
You can write and run unit tests in Visual Studio using some of the more popular JavaScript frameworks without the need to switch to a command prompt. Both Node.js and ASP.NET Core projects are supported.
1717

18+
::: moniker range=">=vs-2022"
19+
The supported frameworks are:
20+
- Mocha ([mochajs.org](https://mochajs.org/))
21+
- Jasmine ([Jasmine.github.io](https://jasmine.github.io/))
22+
- Tape ([github.com/substack/tape](https://github.com/substack/tape))
23+
- Jest ([jestjs.io](https://jestjs.io/))
24+
- Vitest ([vitest.dev](https://vitest.dev/))
25+
::: moniker-end
26+
27+
::: moniker range="<=vs-2019"
1828
The supported frameworks are:
1929
- Mocha ([mochajs.org](https://mochajs.org/))
2030
- Jasmine ([Jasmine.github.io](https://jasmine.github.io/))
2131
- Tape ([github.com/substack/tape](https://github.com/substack/tape))
2232
- Jest ([jestjs.io](https://jestjs.io/))
33+
::: moniker-end
2334

2435
::: moniker range="<=vs-2019"
2536
If your favorite framework is not supported, see [Add support for a unit test framework](#addingFramework) for information on adding support.
@@ -28,12 +39,13 @@ If your favorite framework is not supported, see [Add support for a unit test fr
2839
::: moniker range=">=vs-2022"
2940
## Write unit tests for a CLI-based project (.esproj)
3041

31-
The [CLI-based projects](../javascript/javascript-in-vs-2022.md#project-templates) supported in Visual Studio 2022 work with Test Explorer. Jest is the built-in test framework for React and Vue projects, and Karma and Jasmine is used for Angular projects. By default, you will be able to run the default tests provided by each framework, as well as any additional tests you write. Just hit the **Run** button in Test Explorer. If you don’t already have Test Explorer open, you can find it by selecting **Test** > **Test Explorer** in the menu bar.
42+
The [CLI-based projects](../javascript/javascript-in-vs-2022.md#project-templates) supported in Visual Studio 2022 work with Test Explorer. Vitest is the built-in test framework for React and Vue projects (previously Jest), and Karma and Jasmine is used for Angular projects. By default, you will be able to run the default tests provided by each framework, as well as any additional tests you write. Just hit the **Run** button in Test Explorer. If you don’t already have Test Explorer open, you can find it by selecting **Test** > **Test Explorer** in the menu bar.
3243

3344
To run unit tests from the command-line, right-click the project in Solution Explorer, choose **Open in Terminal**, and run the command specific to the test type.
3445

3546
For information on setting up unit tests, see the following:
3647

48+
- [Testing with Vitest](https://vitest.dev/guide/)
3749
- [Testing React with Jest](https://jestjs.io/docs/tutorial-react)
3850
- [Angular testing](https://angular.io/guide/testing)
3951
- [Testing Vue.js](https://vuejs.org/guide/scaling-up/testing.html#unit-testing)
@@ -42,7 +54,7 @@ A simple example is also provided here. However, use the preceding links for com
4254

4355
### Add a unit test (.esproj)
4456

45-
The following example is based on the TypeScript React project template provided in Visual Studio 2022 version 17.8 or later, which is the **Standalone TypeScript React Project** template. For Vue and Angular, the steps are similar.
57+
The following example is based on the TypeScript React project template provided in Visual Studio 2022 version 17.12 or later, which is the **Standalone TypeScript React Project** template. For Vue and Angular, the steps are similar.
4658

4759
1. In Solution Explorer, right-click the React project and choose **Edit Project File**.
4860

@@ -51,29 +63,31 @@ The following example is based on the TypeScript React project template provided
5163
```xml
5264
<PropertyGroup>
5365
<JavaScriptTestRoot>src\</JavaScriptTestRoot>
54-
<JavaScriptTestFramework>Jest</JavaScriptTestFramework>
66+
<JavaScriptTestFramework>Vitest</JavaScriptTestFramework>
5567
</PropertyGroup>
5668
```
5769

58-
This example specifies Jest as the test framework. You could specify Mocha, Tape, or Jasmine instead.
70+
This example specifies Vitest as the test framework. You could specify Mocha, Tape, Jasmine, or Jest instead.
5971

60-
The `JavaScriptTestRoot` element specifies that your unit tests will be in the *src* folder of the project root.
72+
The `JavaScriptTestRoot` element specifies that your unit tests will be in the *src* folder of the project root. It's also common to specify the *test* folder.
6173

62-
1. In Solution Explorer, right-click the npm node and choose **Install new npm packages**.
74+
1. In Solution Explorer, right-click the **npm** node and choose **Install new npm packages**.
6375

6476
Use the npm package installation dialog to install the following npm packages:
6577

66-
- jest
67-
- jest-editor-support
78+
- vitest
6879

69-
These packages are added to the *package.json* file under dependencies.
80+
This package are added to the *package.json* file under dependencies.
81+
82+
> [!NOTE]
83+
> If you're using jest, the jest-editor-support npm package is required as well as the jest package.
7084
7185
1. In *package.json*, add the `test` section at the end of the `scripts` section:
7286

7387
```json
7488
"scripts": {
7589
...
76-
"test": "jest"
90+
"test": "vitest"
7791
},
7892
```
7993

@@ -84,6 +98,8 @@ The following example is based on the TypeScript React project template provided
8498
1. Add the following code to *App.test.tsx*.
8599

86100
```javascript
101+
import { describe, it, expect } from 'vitest';
102+
87103
describe('testAsuite', () => {
88104
it('testA1', async () => {
89105
expect(2).toBe(2);

0 commit comments

Comments
 (0)