Skip to content

Commit

Permalink
fix: resolve Vitest relative to the config instead of the workspace f…
Browse files Browse the repository at this point in the history
…older

Related: #286
  • Loading branch information
sheremet-va committed Mar 15, 2024
1 parent b8bd588 commit a7e7153
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ interface VitestMeta {

function resolveVitestConfig(showWarning: boolean, configOrWorkspaceFile: vscode.Uri) {
const folder = vscode.workspace.getWorkspaceFolder(configOrWorkspaceFile)!
const vitest = resolveVitestPackage(folder)
const vitest = resolveVitestPackage(dirname(configOrWorkspaceFile.fsPath), folder)

if (!vitest) {
if (showWarning)
Expand Down
8 changes: 4 additions & 4 deletions src/api/resolve.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ interface VitestPackage {
}
}

export function resolveVitestPackage(folder: vscode.WorkspaceFolder): VitestPackage | null {
const vitestPackageJsonPath = resolveVitestPackagePath(folder)
export function resolveVitestPackage(cwd: string, folder: vscode.WorkspaceFolder): VitestPackage | null {
const vitestPackageJsonPath = resolveVitestPackagePath(cwd, folder)
if (vitestPackageJsonPath) {
return {
vitestNodePath: resolveVitestNodePath(vitestPackageJsonPath),
Expand All @@ -36,13 +36,13 @@ export function resolveVitestPackage(folder: vscode.WorkspaceFolder): VitestPack
}
}

export function resolveVitestPackagePath(folder: vscode.WorkspaceFolder) {
export function resolveVitestPackagePath(cwd: string, folder: vscode.WorkspaceFolder) {
const customPackagePath = getConfig(folder).packagePath
if (customPackagePath && !customPackagePath.endsWith('package.json'))
throw new Error(`"vitest.packagePath" must point to a package.json file, instead got: ${customPackagePath}`)
try {
return customPackagePath || require.resolve('vitest/package.json', {
paths: [folder.uri.fsPath],
paths: [cwd],
})
}
catch (_) {
Expand Down
3 changes: 2 additions & 1 deletion src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ class VitestExtension {
return
}

this.testTree.reset(vitest.map(x => x.folder))
const folders = new Set(vitest.map(x => x.folder))
this.testTree.reset(Array.from(folders))

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

0 comments on commit a7e7153

Please sign in to comment.