Skip to content

Commit 9c7bf80

Browse files
Migrate test framework to vitest (microsoft#2769)
Get rid of mocha and upgrade to vitest which is a more modern alternative providing, watch, direct typescript compilation out of the box, expect library and more. Advantage over mocha: - Much better cli - watch mode - better diff - Better extension: - tree organization for files too (not everything flattened) - update in real time the test(no more need to refresh manually to discover where are the tests) - just a little buggy - Compiles typescript directly - provides more expectation apis(like jest) Cons over mocha: - Slower(about 2x) but that means we don't need to build the test as part of build which would speed up that part(not as much as is lost) Todo: - typespec-azure migration
1 parent da99aa9 commit 9c7bf80

File tree

317 files changed

+3904
-4466
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

317 files changed

+3904
-4466
lines changed

.vscode/extensions.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
"recommendations": [
33
"dbaeumer.vscode-eslint",
44
"esbenp.prettier-vscode",
5-
"streetsidesoftware.code-spell-checker"
5+
"streetsidesoftware.code-spell-checker",
6+
"ZixuanChen.vitest-explorer"
67
]
78
}

.vscode/launch.json

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -20,26 +20,6 @@
2020
"order": 999
2121
}
2222
},
23-
{
24-
"type": "node",
25-
"request": "attach",
26-
"name": "Tests",
27-
"port": 9229,
28-
"smartStep": true,
29-
"sourceMaps": true,
30-
"continueOnAttach": true,
31-
"skipFiles": [
32-
"<node_internals>/**/*.js",
33-
"**/.vscode/extensions/hbenl.vscode-mocha-test-adapter-*/**.js"
34-
],
35-
"outFiles": [
36-
"${workspaceFolder}/packages/*/dist/**/*.js",
37-
"${workspaceFolder}/packages/*/dist-dev/**/*.js"
38-
],
39-
"presentation": {
40-
"hidden": true
41-
}
42-
},
4323
{
4424
"name": "Attach to Language Server",
4525
"type": "node",

.vscode/settings.json

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -54,23 +54,8 @@
5454
},
5555
"typescript.tsdk": "./packages/compiler/node_modules/typescript/lib",
5656
"git.ignoreLimitWarning": true,
57-
"testExplorer.useNativeTesting": true,
58-
"mochaExplorer.parallel": false,
59-
"mochaExplorer.files": [
60-
"./packages/*/dist/test/**/*.test.js",
61-
"./packages/*/dist/test/**/*.e2e.js",
62-
"./packages/*/dist-dev/test/**/*.test.js",
63-
"./packages/*/test/**/*.test.js"
64-
],
65-
"mochaExplorer.ignore": "./packages/*/dist/test/manual/**/*.js",
66-
"mochaExplorer.mochaPath": "./packages/compiler/node_modules/mocha",
67-
"mochaExplorer.timeout": 500000,
68-
"mochaExplorer.require": "source-map-support/register",
69-
"mochaExplorer.debuggerConfig": "Tests",
70-
"mochaExplorer.env": {
71-
"TYPESPEC_VERBOSE_TEST_OUTPUT": "true",
72-
"NODE_OPTIONS": "--stack-trace-limit=50"
73-
},
57+
"vitest.enable": true,
58+
"vitest.commandLine": "node ./packages/compiler/node_modules/vitest/vitest.mjs",
7459
"prettier.prettierPath": "./packages/compiler/node_modules/prettier/index.cjs",
7560
"prettier.documentSelectors": ["**/*.tsp"],
7661
"testExplorer.errorDecoration": false,

CONTRIBUTING.md

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -154,8 +154,8 @@ PR validation will ensure that reference docs are up to date.
154154

155155
## Recommended extensions
156156

157-
1. [Mocha Test Explorer](https://marketplace.visualstudio.com/items?itemName=hbenl.vscode-mocha-test-adapter):
158-
Run tests from the IDE.
157+
1. [Vitest Test Explorer](https://marketplace.visualstudio.com/items?itemName=ZixuanChen.vitest-explorer):
158+
Run tests from the IDE. (Version `0.2.43` is bugged on OSX, use `0.2.42` instead)
159159
2. [Prettier](https://marketplace.visualstudio.com/items?itemName=esbenp.prettier-vscode):
160160
Automatically keep code formatted correctly on save.
161161
3. [ESLint](https://marketplace.visualstudio.com/items?itemName=dbaeumer.vscode-eslint):
@@ -191,17 +191,13 @@ Terminal pane will have three parallel watch tasks running:
191191

192192
## Testing
193193

194-
With [Mocha Test
195-
Explorer](https://marketplace.visualstudio.com/items?itemName=hbenl.vscode-mocha-test-adapter)
196-
installed, click on its icon in the sidebar, then click on the play
197-
button at the top or on any individual test or test group to run just
198-
one test or just one group. You can also click on the bug icon next to
199-
an individual test to debug it.
200-
201-
You can see additional information logged by each test using
202-
`logVerboseTestOutput` by clicking on the test and looking at the
203-
output pane. Unlike the command line, no environment variable is
204-
needed.
194+
```bash
195+
# Run all the tests
196+
rush test
197+
198+
# Run in a specific package tests in watch mode
199+
npm run test:watch
200+
```
205201

206202
## Debugging
207203

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"changes": [
3+
{
4+
"packageName": "@typespec/bundler",
5+
"comment": "",
6+
"type": "none"
7+
}
8+
],
9+
"packageName": "@typespec/bundler"
10+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"changes": [
3+
{
4+
"packageName": "@typespec/compiler",
5+
"comment": "",
6+
"type": "none"
7+
}
8+
],
9+
"packageName": "@typespec/compiler"
10+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"changes": [
3+
{
4+
"packageName": "@typespec/eslint-config-typespec",
5+
"comment": "Migrate test rules to vitest",
6+
"type": "none"
7+
}
8+
],
9+
"packageName": "@typespec/eslint-config-typespec"
10+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"changes": [
3+
{
4+
"packageName": "@typespec/eslint-plugin",
5+
"comment": "",
6+
"type": "none"
7+
}
8+
],
9+
"packageName": "@typespec/eslint-plugin"
10+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"changes": [
3+
{
4+
"packageName": "@typespec/html-program-viewer",
5+
"comment": "",
6+
"type": "none"
7+
}
8+
],
9+
"packageName": "@typespec/html-program-viewer"
10+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"changes": [
3+
{
4+
"packageName": "@typespec/http",
5+
"comment": "",
6+
"type": "none"
7+
}
8+
],
9+
"packageName": "@typespec/http"
10+
}

0 commit comments

Comments
 (0)