Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 4 commits into from
May 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading