fix(config): type issue of pool and poolMatchGlobs in defineConfig (#4282)

This commit is contained in:
InfiniteXyy 2023-10-14 00:08:59 +08:00 committed by GitHub
parent e836b2b8bc
commit 9112cc96b4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 7 additions and 10 deletions

View File

@ -62,7 +62,7 @@ const config = {
watch: !isCI,
globals: false,
environment: 'node' as const,
pool: 'threads',
pool: 'threads' as const,
clearMocks: false,
restoreMocks: false,
mockReset: false,

View File

@ -398,9 +398,6 @@ export function resolveConfig(
return resolved
}
export function isBrowserEnabled(config: ResolvedConfig) {
if (config.browser?.enabled)
return true
return config.poolMatchGlobs?.length && config.poolMatchGlobs.some(([, pool]) => pool === 'browser')
export function isBrowserEnabled(config: ResolvedConfig): boolean {
return Boolean(config.browser?.enabled)
}

View File

@ -46,7 +46,7 @@ export function createPool(ctx: Vitest): ProcessPool {
function getPoolName([project, file]: WorkspaceSpec) {
for (const [glob, pool] of project.config.poolMatchGlobs || []) {
if (pool === 'browser')
if ((pool as Pool) === 'browser')
throw new Error('Since Vitest 0.31.0 "browser" pool is not supported in "poolMatchGlobs". You can create a workspace to run some of your tests in browser in parallel. Read more: https://vitest.dev/guide/workspace')
if (mm.isMatch(file, glob, { cwd: project.config.root }))
return pool as Pool

View File

@ -294,7 +294,7 @@ export interface InlineConfig {
*
* @default 'threads'
*/
pool?: Omit<Pool, 'browser'>
pool?: Exclude<Pool, 'browser'>
/**
* Pool options
@ -314,7 +314,7 @@ export interface InlineConfig {
* // ...
* ]
*/
poolMatchGlobs?: [string, Omit<Pool, 'browser'>][]
poolMatchGlobs?: [string, Exclude<Pool, 'browser'>][]
/**
* Update snapshot
@ -704,7 +704,7 @@ export interface UserConfig extends InlineConfig {
shard?: string
}
export interface ResolvedConfig extends Omit<Required<UserConfig>, 'config' | 'filters' | 'browser' | 'coverage' | 'testNamePattern' | 'related' | 'api' | 'reporters' | 'resolveSnapshotPath' | 'benchmark' | 'shard' | 'cache' | 'sequence' | 'typecheck' | 'runner' | 'poolOptions'> {
export interface ResolvedConfig extends Omit<Required<UserConfig>, 'config' | 'filters' | 'browser' | 'coverage' | 'testNamePattern' | 'related' | 'api' | 'reporters' | 'resolveSnapshotPath' | 'benchmark' | 'shard' | 'cache' | 'sequence' | 'typecheck' | 'runner' | 'poolOptions' | 'pool'> {
mode: VitestRunMode
base?: string