Skip to content

Commit

Permalink
feat: auto watch on startup setting
Browse files Browse the repository at this point in the history
  • Loading branch information
ffMathy committed Feb 18, 2024
1 parent b6de2b9 commit 82222ab
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 7 deletions.
6 changes: 6 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,12 @@
"scope": "resource",
"default": false
},
"vitest.watchOnStartup": {
"description": "Start watching tests on startup",
"type": "boolean",
"scope": "resource",
"default": false
},
"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",
"type": "string",
Expand Down
7 changes: 4 additions & 3 deletions src/config.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import * as vscode from 'vscode'
import semver from 'semver'
import type { WorkspaceConfiguration, WorkspaceFolder } from 'vscode'
import type { ResolvedConfig } from 'vitest'
import type { WorkspaceConfiguration, WorkspaceFolder } from 'vscode'
import * as vscode from 'vscode'
import { log } from './log'
import { isDefinitelyVitestEnv, mayBeVitestEnv } from './pure/isVitestEnv'
import { getVitestCommand, getVitestVersion, isNodeAvailable } from './pure/utils'
import { log } from './log'
export const extensionId = 'zxch3n.vitest-explorer'

// Copied from https://github.com/vitest-dev/vitest/blob/main/packages/vitest/src/defaults.ts
Expand Down Expand Up @@ -42,6 +42,7 @@ export function getConfig(workspaceFolder?: WorkspaceFolder | vscode.Uri | strin
return {
env: get<null | Record<string, string>>('nodeEnv', null),
commandLine: get<string | undefined>('commandLine', undefined),
watchOnStartup: get<boolean>('watchOnStartup', false),
include: get<string[]>('include'),
exclude: get<string[]>('exclude'),
enable: get<boolean>('enable', false),
Expand Down
13 changes: 9 additions & 4 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { effect } from '@vue/reactivity'
import type { ResolvedConfig } from 'vitest'
import { Command } from './command'
import {
detectVitestEnvironmentFolders, extensionId, getVitestWorkspaceConfigs,
detectVitestEnvironmentFolders, extensionId, getConfig, getVitestWorkspaceConfigs,
vitestEnvironmentFolders,
} from './config'
import { TestFileDiscoverer } from './discover'
Expand Down Expand Up @@ -140,9 +140,14 @@ function registerWatchHandlers(
fileDiscoverer: TestFileDiscoverer,
context: vscode.ExtensionContext,
) {
const testWatchers = vitestConfigs.map((vitestConfig, index) =>
TestWatcher.create(ctrl, fileDiscoverer, vitestConfig, vitestConfig.workspace, index),
) ?? []
const testWatchers = vitestConfigs.map((vitestConfig, index) => {
const watcher = TestWatcher.create(ctrl, fileDiscoverer, vitestConfig, vitestConfig.workspace, index)

if (getConfig(vitestConfig.workspace).watchOnStartup)
watcher.watch()

return watcher
}) ?? []

statusBarItem = new StatusBarItem()
effect(() => {
Expand Down

0 comments on commit 82222ab

Please sign in to comment.