Skip to content

Commit ba9d4c2

Browse files
committed
fix: show an error if terminal could not connect
1 parent 8acc39c commit ba9d4c2

File tree

2 files changed

+17
-6
lines changed

2 files changed

+17
-6
lines changed

src/api.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -326,11 +326,13 @@ export async function resolveVitestAPI(workspaceConfigs: VitestPackage[], config
326326
}
327327

328328
if (!apis.length) {
329-
log.error('There were errors during config load.', errors)
329+
log.error('There were errors during config load.')
330+
errors.forEach(e => log.error(e))
330331
throw new Error('The extension could not load any config.')
331332
}
332333
else if (errors.length) {
333-
log.error('There were errors during config load.', errors)
334+
log.error('There were errors during config load.')
335+
errors.forEach(e => log.error(e))
334336
showVitestError('The extension could not load some configs')
335337
}
336338

src/api/terminal.ts

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ import { WebSocketServer } from 'ws'
1111
import { getConfig } from '../config'
1212
import { workerPath } from '../constants'
1313
import { createErrorLogger, log } from '../log'
14-
import { formatPkg } from '../utils'
15-
import { waitForWsConnection } from './ws'
14+
import { formatPkg, showVitestError } from '../utils'
15+
import { waitForWsConnection, WsConnectionMetadata } from './ws'
1616

1717
export async function createVitestTerminalProcess(pkg: VitestPackage): Promise<ResolvedMeta> {
1818
const pnpLoader = pkg.loader
@@ -26,9 +26,10 @@ export async function createVitestTerminalProcess(pkg: VitestPackage): Promise<R
2626
const config = getConfig(pkg.folder)
2727
const env = config.env || {}
2828
const terminal = vscode.window.createTerminal({
29-
hideFromUser: true,
29+
hideFromUser: false,
3030
cwd: pkg.cwd,
3131
isTransient: false,
32+
name: 'vitest',
3233
shellArgs: config.terminalShellArgs,
3334
shellPath: config.terminalShellPath,
3435
env: {
@@ -49,7 +50,15 @@ export async function createVitestTerminalProcess(pkg: VitestPackage): Promise<R
4950
log.info('[API]', `Initiated ws connection via ${wsAddress}`)
5051
log.info('[API]', `Starting ${formatPkg(pkg)} in the terminal: ${command}`)
5152
terminal.sendText(command, true)
52-
const meta = await waitForWsConnection(wss, pkg, false, 'terminal')
53+
const meta = await new Promise<WsConnectionMetadata>((resolve, reject) => {
54+
const timeout = setTimeout(() => {
55+
terminal.show(false)
56+
reject(new Error(`The extension could not connect to the terminal in 5 seconds. See the "vitest" terminal output for more details.`))
57+
}, 5000)
58+
waitForWsConnection(wss, pkg, false, 'terminal').then(resolve, reject).finally(() => {
59+
clearTimeout(timeout)
60+
})
61+
})
5362
const processId = (await terminal.processId) ?? Math.random()
5463
log.info('[API]', `${formatPkg(pkg)} terminal process ${processId} created`)
5564
const vitestProcess = new ExtensionTerminalProcess(

0 commit comments

Comments
 (0)