Skip to content

Commit 139dd9b

Browse files
authored
fix: log correct name when running in vite-plus (#760)
1 parent 8d90181 commit 139dd9b

File tree

3 files changed

+29
-13
lines changed

3 files changed

+29
-13
lines changed

packages/extension/src/spawn/pkg.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ export interface VitestPackage {
2121
id: string
2222
cwd: string
2323
version: string
24+
name: string
2425
arguments?: string
2526
configFile?: string
2627
workspaceFile?: string
@@ -90,6 +91,7 @@ function resolveVitestConfig(
9091
loader: vitest.pnp.loaderPath,
9192
pnp: vitest.pnp.pnpPath,
9293
runtime,
94+
name: vitest.packageName,
9395
}
9496
}
9597

@@ -105,6 +107,7 @@ function resolveVitestConfig(
105107
vitestNodePath: vitest.vitestNodePath,
106108
version: pkg.version,
107109
runtime,
110+
name: vitest.packageName,
108111
}
109112
}
110113

@@ -178,6 +181,7 @@ function resolveVitestWorkspacePackages(showWarning: boolean) {
178181
vitestNodePath: vitest.vitestNodePath,
179182
version: pkg.version,
180183
runtime,
184+
name: vitest.packageName,
181185
})
182186
})
183187
return {
@@ -240,6 +244,7 @@ export async function resolveVitestPackagesViaPackageJson(
240244
vitestNodePath: vitest.vitestNodePath,
241245
version: pkg.version,
242246
runtime,
247+
name: vitest.packageName,
243248
})
244249
})
245250

@@ -314,6 +319,7 @@ async function resolveVitestConfigs(showWarning: boolean) {
314319
config.configSearchPatternInclude || configGlob,
315320
config.configSearchPatternExclude,
316321
)
322+
console.log(configs, vscode.workspace.workspaceFolders)
317323

318324
const configsByFolder = configs.reduce<Record<string, vscode.Uri[]>>((acc, config) => {
319325
const dir = dirname(config.fsPath)

packages/extension/src/spawn/resolve.ts

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ const _require = require
88
export interface VitestResolution {
99
vitestPackageJsonPath: string
1010
vitestNodePath: string
11+
packageName: string
1112
pnp?: {
1213
loaderPath: string
1314
pnpPath: string
@@ -23,31 +24,40 @@ export function resolveVitestPackage(
2324
return {
2425
vitestNodePath: resolveVitestNodePath(vitestPackageJsonPath),
2526
vitestPackageJsonPath,
27+
packageName: 'Vitest',
2628
}
2729
}
2830
const vitePlus = resolveVitePlusPackagePath(cwd)
2931
if (vitePlus) {
3032
return {
3133
vitestNodePath: resolveViePlusVitestNodePath(vitePlus),
3234
vitestPackageJsonPath: vitePlus,
35+
packageName: 'VitePlus',
3336
}
3437
}
3538

3639
const pnpCwd = folder?.uri.fsPath || cwd
3740
const pnp = resolvePnp(pnpCwd)
3841
if (!pnp) return null
39-
const vitestNodePath =
40-
resolvePnpPackagePath(pnp.pnpApi, 'vitest/node', pnpCwd) ||
41-
resolvePnpPackagePath(pnp.pnpApi, 'vite-plus/test/node', pnpCwd)
42-
if (!vitestNodePath) return null
43-
return {
44-
vitestNodePath,
45-
vitestPackageJsonPath: '', // we don't read pkg.json for pnp
46-
pnp: {
47-
loaderPath: pnp.pnpLoader,
48-
pnpPath: pnp.pnpPath,
49-
},
42+
const vitestNodePath = resolvePnpPackagePath(pnp.pnpApi, 'vitest/node', pnpCwd)
43+
if (vitestNodePath) {
44+
return {
45+
vitestNodePath,
46+
vitestPackageJsonPath: '', // we don't read pkg.json for pnp
47+
pnp,
48+
packageName: 'Vitest',
49+
}
50+
}
51+
const vitePlusNodePath = resolvePnpPackagePath(pnp.pnpApi, 'vite-plus/test/node', pnpCwd)
52+
if (vitePlusNodePath) {
53+
return {
54+
vitestNodePath: vitePlusNodePath,
55+
vitestPackageJsonPath: '', // we don't read pkg.json for pnp
56+
pnp,
57+
packageName: 'VitePlus',
58+
}
5059
}
60+
return null
5161
}
5262

5363
export function resolveVitestPackagePath(cwd: string, folder: vscode.WorkspaceFolder | undefined) {
@@ -91,7 +101,7 @@ export function resolvePnp(cwd: string) {
91101
}
92102
const pnpApi = _require(pnpPath)
93103
return {
94-
pnpLoader: require.resolve('./.pnp.loader.mjs', {
104+
loaderPath: require.resolve('./.pnp.loader.mjs', {
95105
paths: [dirname(pnpPath)],
96106
}),
97107
pnpPath,

packages/extension/src/utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import { getTestData, TestFile } from './testTreeData'
1313
export function noop() {}
1414

1515
export function formatPkg(pkg: VitestPackage) {
16-
return `Vitest v${pkg.version} (${relative(dirname(pkg.cwd), pkg.id)})`
16+
return `${pkg.name} v${pkg.version} (${relative(dirname(pkg.cwd), pkg.id)})`
1717
}
1818

1919
function _showVitestError(message: string, error?: any) {

0 commit comments

Comments
 (0)