Skip to content

Commit

Permalink
feat!: use Vitest public API instead of Vitest CLI (#253)
Browse files Browse the repository at this point in the history
  • Loading branch information
sheremet-va committed Mar 15, 2024
1 parent dd3e081 commit 0b70cb8
Show file tree
Hide file tree
Showing 63 changed files with 2,877 additions and 4,471 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Expand Up @@ -6,3 +6,5 @@ node_modules
.DS_Store
.eslintcache
test-results
.yarn
.pnp.*
20 changes: 20 additions & 0 deletions .vscode/launch.json
Expand Up @@ -15,6 +15,26 @@
],
"outFiles": ["${workspaceFolder}/dist/**/*.js"]
},
{
"name": "Run Extension In-Source Sample",
"type": "extensionHost",
"request": "launch",
"args": [
"--extensionDevelopmentPath=${workspaceFolder}",
"${workspaceFolder}/samples/in-source"
],
"outFiles": ["${workspaceFolder}/dist/**/*.js"]
},
{
"name": "Run Extension Yarn PnP Sample",
"type": "extensionHost",
"request": "launch",
"args": [
"--extensionDevelopmentPath=${workspaceFolder}",
"${workspaceFolder}/../vscode-vitest-pnp"
],
"outFiles": ["${workspaceFolder}/dist/**/*.js"]
},
{
"name": "Run Extension Multi-Root Workspace Sample",
"type": "extensionHost",
Expand Down
16 changes: 8 additions & 8 deletions README.md
Expand Up @@ -10,23 +10,23 @@

- **Run**, **debug**, and **watch** Vitest tests in Visual Studio Code.
- NX support (see the [NX sample](./samples/monorepo-nx/)).
- A `@open` tag can be used when filtering tests, to only show the tests open in the editor.
- An `@open` tag can be used when filtering tests, to only show the tests open in the editor.

## Requirements

- Visual Studio Code version >= July 2021 (version 1.59).
- Vitest version >= v0.12.0
- Vitest version >= v1.4.0

# Introduction

You can identify if your config is loaded by the extension with `process.env.VITEST_VSCODE` and change the configuration accordingly.

## Configuration

- `vitest.enable`: Extension will automatically detect if the current project is using Vitest. If detection fails, extension can be manually enabled via this option.
- `vitest.watchOnStartup`: Whether to activate Watch mode by default when the extension starts.
- `vitest.packagePath`: The path to a custom Vitest's `package.json` file. It will be used to resolve Vitest API paths.
- `vitest.nodeExecutable`: This extension spawns another process and will use this value as `execPath` argument.
- `vitest.nodeEnv`: Environment passed to the runner process in addition to
`process.env`
- `vitest.commandLine`: Command to execute Vitest tests. **It should have the ability
to append extra arguments**. For example
`npx vitest` or `yarn test --`. This is a workspace setting. Do not change it in
the user settings, since it will affect all the projects you open)
- `vitest.debugExclude`: Excludes files matching specified glob patterns from debugging. Default:
`[\"<node_internals>/**\", \"**/node_modules/**\"]`

Expand Down
53 changes: 13 additions & 40 deletions package.json
Expand Up @@ -33,11 +33,8 @@
"vscode": "^1.77.0"
},
"activationEvents": [
"workspaceContains:**/vitest.config.js",
"workspaceContains:**/vite.config.js",
"workspaceContains:**/vitest.config.ts",
"workspaceContains:**/vite.config.ts",
"workspaceContains:**/package.json"
"workspaceContains:**/*{vite,vitest}*.config.{ts,js,mjs,cjs,cts,mts}",
"workspaceContains:node_modules/.bin/vitest"
],
"contributes": {
"commands": [
Expand All @@ -63,23 +60,15 @@
"configuration": {
"title": "Vitest",
"properties": {
"vitest.enable": {
"description": "This plugin will try to detect whether the current project is set up with Vitest to activate itself. When it failed, you can enable the plugin manually.",
"type": "boolean",
"scope": "resource",
"default": false
},
"vitest.watchOnStartup": {
"description": "Start watching tests on startup",
"type": "boolean",
"scope": "resource",
"default": false
"vitest.packagePath": {
"description": "The path to the Vitest `package.json` file.",
"type": "string",
"scope": "resource"
},
"vitest.commandLine": {
"markdownDescription": "The command line to start vitest tests. **It should have with the ability to append extra arguments**. For example `npx vitest` or `yarn test --`\n\nThis is a workspace setting. Do not change it in the user setting directly, which will affect all the projects you open",
"vitest.nodeExecutable": {
"description": "The path to the Node.js executable. If not assigned, uses VSCode's Node.js instance.",
"type": "string",
"scope": "resource",
"default": ""
"scope": "window"
},
"vitest.debugExclude": {
"markdownDescription": "Automatically skip files covered by these glob patterns. \nDefault: `[\"<node_internals>/**\", \"**/node_modules/**\"]`",
Expand All @@ -98,24 +87,6 @@
],
"default": null,
"scope": "resource"
},
"vitest.showFailMessages": {
"description": "Get instant feedback when using Watch Mode. Pop-ups an error when a test fails.",
"type": "boolean",
"scope": "window",
"default": false
},
"vitest.changeBackgroundColor": {
"description": "Change background color of status bar item on failing tests.",
"type": "boolean",
"scope": "window",
"default": true
},
"vitest.disabledWorkspaceFolders": {
"description": "Disabled workspace folders names in multiroot environment",
"type": "array",
"scope": "resource",
"default": []
}
}
}
Expand All @@ -124,6 +95,7 @@
"vscode:prepublish": "pnpm compile",
"release": "bumpp package.json --commit --push --tag && git update-ref refs/heads/release refs/heads/main && git push origin release",
"compile": "tsup --minify",
"package": "vsce package --no-dependencies",
"watch": "tsup --watch --sourcemap",
"test": "vscode-test",
"test:watch": "vscode-test --watch-files src/**/*.ts --watch-files test/**/*.test.ts",
Expand All @@ -145,11 +117,12 @@
"@types/semver": "^7.3.9",
"@types/vscode": "^1.77.0",
"@types/ws": "^8.5.10",
"@vitest/utils": "^1.3.0",
"@vitest/ws-client": "^1.3.0",
"@vscode/test-cli": "^0.0.6",
"@vscode/test-electron": "^2.3.9",
"@vue/reactivity": "^3.2.33",
"birpc": "^0.2.15",
"birpc": "^0.2.17",
"bumpp": "^9.3.0",
"chai": "^5.1.0",
"changelogithub": "^0.13.3",
Expand All @@ -170,7 +143,7 @@
"tsup": "^8.0.1",
"tsx": "^4.7.1",
"typescript": "^5.3.3",
"vitest": "^1.3.1",
"vitest": "^1.4.0",
"ws": "^8.16.0"
},
"lint-staged": {
Expand Down

0 comments on commit 0b70cb8

Please sign in to comment.