Skip to content

Commit

Permalink
fix: conservatively display window error
Browse files Browse the repository at this point in the history
  • Loading branch information
zxch3n committed Aug 6, 2022
1 parent 1bd35a2 commit 1312f2e
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 17 deletions.
2 changes: 1 addition & 1 deletion src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ export async function getVitestWorkspaceConfigs(): Promise<VitestWorkspaceConfig
errorMsg += 'Cannot spawn node process. Please try setting vitest.nodeEnv as {"PATH": "/path/to/node"} in your settings.'
}

vscode.window.showErrorMessage(errorMsg)
log.error(errorMsg)
return undefined
})

Expand Down
38 changes: 22 additions & 16 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,25 @@ export async function activate(context: vscode.ExtensionContext) {

const workspaceConfigs = await getVitestWorkspaceConfigs()
// enable run/debug/watch tests only if vitest version >= 0.12.0
if (!workspacesCompatibilityCheck(workspaceConfigs, context))
if (!workspacesCompatibilityCheck(workspaceConfigs)) {
const msg = 'Because Vitest version < 0.12.0 for every workspace folder, run/debug/watch tests from Vitest extension disabled.\n'
log.error(msg)
// if the vitest detection is false positive, we may still reach here.
// but we can still use `.version` to filter some false positive
if (workspaceConfigs.some(x => x.version))
vscode.window.showWarningMessage(msg)

context.subscriptions.push(
vscode.commands.registerCommand(Command.ToggleWatching, () => {
vscode.window.showWarningMessage(msg)
}),
vscode.commands.registerCommand(Command.UpdateSnapshot, () => {
vscode.window.showWarningMessage(msg)
}),
)

return
}

registerRunDebugWatchHandler(ctrl, workspaceConfigs, fileDiscoverer, context)
context.subscriptions.push(
Expand All @@ -49,30 +66,19 @@ export async function activate(context: vscode.ExtensionContext) {
)
}

function workspacesCompatibilityCheck(workspaceConfigs: VitestWorkspaceConfig[], context: vscode.ExtensionContext) {
function workspacesCompatibilityCheck(workspaceConfigs: VitestWorkspaceConfig[]) {
workspaceConfigs.forEach((vitest) => {
log.info(`Vitest Workspace [${vitest.workspace.name}]: Vitest version = ${vitest.version}`)
})

workspaceConfigs.filter(x => !x.isCompatible).forEach((config) => {
// prompt error message if we can get the version from vitest, but it's not compatible with the extension
workspaceConfigs.filter(x => !x.isCompatible && x.version).forEach((config) => {
vscode.window.showWarningMessage('Because Vitest version < 0.12.0'
+ `, run/debug/watch tests are disabled in workspace "${config.workspace.name}" \n`)
})

if (workspaceConfigs.every(x => !x.isCompatible)) {
const msg = 'Because Vitest version < 0.12.0 for every workspace folder, run/debug/watch tests from Vitest extension disabled.\n'
context.subscriptions.push(
vscode.commands.registerCommand(Command.ToggleWatching, () => {
vscode.window.showWarningMessage(msg)
}),
vscode.commands.registerCommand(Command.UpdateSnapshot, () => {
vscode.window.showWarningMessage(msg)
}),
)

vscode.window.showWarningMessage(msg)
if (workspaceConfigs.every(x => !x.isCompatible))
return false
}

return true
}
Expand Down

0 comments on commit 1312f2e

Please sign in to comment.