Skip to content

Commit f232fdd

Browse files
authored
fix!: don't exit process if config failed (#5715)
1 parent 9eb8475 commit f232fdd

File tree

3 files changed

+8
-26
lines changed

3 files changed

+8
-26
lines changed

packages/vitest/src/node/plugins/index.ts

+3-9
Original file line numberDiff line numberDiff line change
@@ -193,15 +193,9 @@ export async function VitestPlugin(options: UserConfig = {}, ctx = new Vitest('t
193193
console.log('[debug] watcher is ready')
194194
})
195195
}
196-
try {
197-
await ctx.setServer(options, server, userConfig)
198-
if (options.api && options.watch)
199-
(await import('../../api/setup')).setup(ctx)
200-
}
201-
catch (err) {
202-
ctx.logger.printError(err, { fullStack: true })
203-
process.exit(1)
204-
}
196+
await ctx.setServer(options, server, userConfig)
197+
if (options.api && options.watch)
198+
(await import('../../api/setup')).setup(ctx)
205199

206200
// #415, in run mode we don't need the watcher, close it would improve the performance
207201
if (!options.watch)

test/config/test/override.test.ts

+3-15
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { Writable } from 'node:stream'
21
import type { UserConfig } from 'vitest'
32
import type { UserConfig as ViteUserConfig } from 'vite'
43
import { describe, expect, it } from 'vitest'
@@ -291,27 +290,16 @@ describe.each([
291290
waitForDebugger: inspectFlagName === '--inspect-brk' && inspect.enabled,
292291
})
293292
})
294-
it('cannot use a URL', async () => {
293+
it('cannot use URL', async () => {
295294
const url = 'https://www.remote.com:1002'
296295
const rawConfig = parseCLI([
297296
'vitest',
298297
'--no-file-parallelism',
299298
inspectFlagName,
300299
url,
301300
])
302-
const errors: string[] = []
303-
const stderr = new Writable({
304-
write(chunk, _encoding, callback) {
305-
errors.push(chunk.toString())
306-
callback()
307-
},
308-
})
309301
await expect(async () => {
310-
await config(rawConfig.options, {}, {}, { stderr })
311-
}).rejects.toThrowError()
312-
313-
expect(errors[0]).toEqual(
314-
expect.stringContaining(`Inspector host cannot be a URL. Use "host:port" instead of "${url}"`),
315-
)
302+
await config(rawConfig.options)
303+
}).rejects.toThrowError(`Inspector host cannot be a URL. Use "host:port" instead of "${url}"`)
316304
})
317305
})

test/test-utils/index.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ export async function runVitest(config: UserConfig, cliFilters: string[] = [], m
4343
})
4444
}
4545
catch (e: any) {
46-
console.error(e.message)
47-
cli.stderr += e.message
46+
console.error(e)
47+
cli.stderr += e.stack
4848
}
4949
finally {
5050
exitCode = process.exitCode

0 commit comments

Comments
 (0)