Skip to content

Commit 19f3a08

Browse files
authored
fix: ignore changes to unrelated configs (#509)
* fix: ignore changes to unrelated configs * fix: always refresh if the config is created
1 parent 12de122 commit 19f3a08

File tree

1 file changed

+22
-6
lines changed

1 file changed

+22
-6
lines changed

src/extension.ts

+22-6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import * as vscode from 'vscode'
22
import './polyfills'
3+
import { normalize } from 'pathe'
34
import { version } from '../package.json'
45
import { getConfig, testControllerId } from './config'
56
import type { VitestAPI } from './api'
@@ -346,15 +347,30 @@ class VitestExtension {
346347
]
347348
this.disposables.push(...configWatchers)
348349

349-
const redefineTestProfiles = debounce((uri: vscode.Uri) => {
350-
if (uri.fsPath.includes('node_modules') || uri.fsPath.includes('.timestamp-'))
350+
const redefineTestProfiles = debounce((uri: vscode.Uri, event: 'create' | 'delete' | 'change') => {
351+
if (!this.api || uri.fsPath.includes('node_modules') || uri.fsPath.includes('.timestamp-'))
351352
return
352-
this.defineTestProfiles(false)
353+
// if new config is created, always check if it should be respected
354+
if (event === 'create') {
355+
this.defineTestProfiles(false)
356+
return
357+
}
358+
// otherwise ignore changes to unrelated configs
359+
const filePath = normalize(uri.fsPath)
360+
for (const api of this.api.folderAPIs) {
361+
if (
362+
api.package.configFile === filePath
363+
|| api.package.workspaceFile === filePath
364+
) {
365+
this.defineTestProfiles(false)
366+
return
367+
}
368+
}
353369
}, 300)
354370

355-
configWatchers.forEach(watcher => watcher.onDidChange(redefineTestProfiles))
356-
configWatchers.forEach(watcher => watcher.onDidCreate(redefineTestProfiles))
357-
configWatchers.forEach(watcher => watcher.onDidDelete(redefineTestProfiles))
371+
configWatchers.forEach(watcher => watcher.onDidChange(uri => redefineTestProfiles(uri, 'change')))
372+
configWatchers.forEach(watcher => watcher.onDidCreate(uri => redefineTestProfiles(uri, 'create')))
373+
configWatchers.forEach(watcher => watcher.onDidDelete(uri => redefineTestProfiles(uri, 'delete')))
358374

359375
try {
360376
await this.defineTestProfiles(true)

0 commit comments

Comments
 (0)