Skip to content

Commit

Permalink
fix!: don't exit process if config failed (#5715)
Browse files Browse the repository at this point in the history
  • Loading branch information
sheremet-va authored May 13, 2024
1 parent 9eb8475 commit f232fdd
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 26 deletions.
12 changes: 3 additions & 9 deletions packages/vitest/src/node/plugins/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
18 changes: 3 additions & 15 deletions test/config/test/override.test.ts
Original file line number Diff line number Diff line change
@@ -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'
Expand Down Expand Up @@ -291,27 +290,16 @@ 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',
'--no-file-parallelism',
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}"`)
})
})
4 changes: 2 additions & 2 deletions test/test-utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit f232fdd

Please sign in to comment.