Skip to content

Commit

Permalink
fix: stop spinner if API fails to initialize
Browse files Browse the repository at this point in the history
  • Loading branch information
sheremet-va committed Mar 15, 2024
1 parent a209e3a commit b8bd588
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 12 deletions.
5 changes: 1 addition & 4 deletions src/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,6 @@ export async function resolveVitestPackages(showWarning: boolean): Promise<Vites
// if there is a workspace config, use it as root
return vitestWorkspaces.map((config) => {
const vitest = resolveVitestConfig(showWarning, config)
log.info('[API]', vitest)
if (!vitest)
return null
return {
Expand All @@ -238,9 +237,6 @@ export async function resolveVitestPackages(showWarning: boolean): Promise<Vites

const configs = await vscode.workspace.findFiles(configGlob, '**/node_modules/**')

if (!configs.length)
log.error('[API]', 'Failed to start Vitest: No vitest config files found')

return configs.map((config) => {
const vitest = resolveVitestConfig(showWarning, config)
if (!vitest)
Expand Down Expand Up @@ -272,6 +268,7 @@ function createChildVitestProcess(tree: TestTree, meta: VitestMeta[]) {
const vitest = fork(
workerPath,
{
// TODO: use findNode API
execPath: getConfig().nodeExecutable,
execArgv,
env: {
Expand Down
11 changes: 6 additions & 5 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,9 @@ class VitestExtension {
this.testTree.reset([])

const vitest = await resolveVitestPackages(showWarning)
// don't show any errors, they are already shown in resolveVitestPackages

if (!vitest.length) {
log.error('[API]', 'Failed to start Vitest: No vitest config files found')
this.testController.items.delete(this.loadingTestItem.id)

await this.api?.dispose()
Expand All @@ -53,14 +54,14 @@ class VitestExtension {

this.testTree.reset(vitest.map(x => x.folder))

await this.api?.dispose()

this.api = await resolveVitestAPI(this.testTree, vitest)

const previousRunProfiles = this.runProfiles
this.runProfiles = new Map()

try {
await this.api?.dispose()

this.api = await resolveVitestAPI(this.testTree, vitest)

for (const api of this.api.folderAPIs) {
await this.testTree.watchTestFilesInWorkspace(
api,
Expand Down
5 changes: 2 additions & 3 deletions src/testTree.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ export class TestTree extends vscode.Disposable {
this.folderItems.clear()
this.fileItems.clear()
this.flatTestItems.clear()
this.watchers.forEach(x => x.dispose())
this.watchers = []

this.loaderItem.busy = true

Expand Down Expand Up @@ -142,9 +144,6 @@ export class TestTree extends vscode.Disposable {
}

async watchTestFilesInWorkspace(api: VitestFolderAPI, testFiles: string[]) {
this.watchers.forEach(x => x.dispose())
this.watchers = []

await this.discoverAllTestFiles(api, testFiles)

const watcher = vscode.workspace.createFileSystemWatcher(
Expand Down

0 comments on commit b8bd588

Please sign in to comment.