fix!: don't exit process if config failed (#5715)

This commit is contained in:
Vladimir 2024-05-13 16:40:29 +02:00 committed by GitHub
parent 9eb84752b4
commit f232fdd618
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 8 additions and 26 deletions

View File

@ -193,15 +193,9 @@ export async function VitestPlugin(options: UserConfig = {}, ctx = new Vitest('t
console.log('[debug] watcher is ready')
})
}
try {
await ctx.setServer(options, server, userConfig)
if (options.api && options.watch)
(await import('../../api/setup')).setup(ctx)
}
catch (err) {
ctx.logger.printError(err, { fullStack: true })
process.exit(1)
}
await ctx.setServer(options, server, userConfig)
if (options.api && options.watch)
(await import('../../api/setup')).setup(ctx)
// #415, in run mode we don't need the watcher, close it would improve the performance
if (!options.watch)

View File

@ -1,4 +1,3 @@
import { Writable } from 'node:stream'
import type { UserConfig } from 'vitest'
import type { UserConfig as ViteUserConfig } from 'vite'
import { describe, expect, it } from 'vitest'
@ -291,7 +290,7 @@ describe.each([
waitForDebugger: inspectFlagName === '--inspect-brk' && inspect.enabled,
})
})
it('cannot use a URL', async () => {
it('cannot use URL', async () => {
const url = 'https://www.remote.com:1002'
const rawConfig = parseCLI([
'vitest',
@ -299,19 +298,8 @@ describe.each([
inspectFlagName,
url,
])
const errors: string[] = []
const stderr = new Writable({
write(chunk, _encoding, callback) {
errors.push(chunk.toString())
callback()
},
})
await expect(async () => {
await config(rawConfig.options, {}, {}, { stderr })
}).rejects.toThrowError()
expect(errors[0]).toEqual(
expect.stringContaining(`Inspector host cannot be a URL. Use "host:port" instead of "${url}"`),
)
await config(rawConfig.options)
}).rejects.toThrowError(`Inspector host cannot be a URL. Use "host:port" instead of "${url}"`)
})
})

View File

@ -43,8 +43,8 @@ export async function runVitest(config: UserConfig, cliFilters: string[] = [], m
})
}
catch (e: any) {
console.error(e.message)
cli.stderr += e.message
console.error(e)
cli.stderr += e.stack
}
finally {
exitCode = process.exitCode