|
1 | 1 | import * as vscode from 'vscode'
|
2 | 2 | import './polyfills'
|
| 3 | +import { normalize } from 'pathe' |
3 | 4 | import { version } from '../package.json'
|
4 | 5 | import { getConfig, testControllerId } from './config'
|
5 | 6 | import type { VitestAPI } from './api'
|
@@ -346,15 +347,30 @@ class VitestExtension {
|
346 | 347 | ]
|
347 | 348 | this.disposables.push(...configWatchers)
|
348 | 349 |
|
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-')) |
351 | 352 | 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 | + } |
353 | 369 | }, 300)
|
354 | 370 |
|
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'))) |
358 | 374 |
|
359 | 375 | try {
|
360 | 376 | await this.defineTestProfiles(true)
|
|
0 commit comments