From f232fdd6180e42109c72f650ee17ba659eca604e Mon Sep 17 00:00:00 2001 From: Vladimir Date: Mon, 13 May 2024 16:40:29 +0200 Subject: [PATCH] fix!: don't exit process if config failed (#5715) --- packages/vitest/src/node/plugins/index.ts | 12 +++--------- test/config/test/override.test.ts | 18 +++--------------- test/test-utils/index.ts | 4 ++-- 3 files changed, 8 insertions(+), 26 deletions(-) diff --git a/packages/vitest/src/node/plugins/index.ts b/packages/vitest/src/node/plugins/index.ts index 88c76cce0874..01791ac4cab7 100644 --- a/packages/vitest/src/node/plugins/index.ts +++ b/packages/vitest/src/node/plugins/index.ts @@ -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) diff --git a/test/config/test/override.test.ts b/test/config/test/override.test.ts index 847187b006b7..e52bc19770de 100644 --- a/test/config/test/override.test.ts +++ b/test/config/test/override.test.ts @@ -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}"`) }) }) diff --git a/test/test-utils/index.ts b/test/test-utils/index.ts index eb76ae6b4f2b..ae7e62944787 100644 --- a/test/test-utils/index.ts +++ b/test/test-utils/index.ts @@ -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