From 4da333b294b6ea13029a81bc6736420c808517df Mon Sep 17 00:00:00 2001 From: Vladimir Sheremet Date: Thu, 3 Oct 2024 13:32:28 +0200 Subject: [PATCH] fix(vitest): don't hang with maxConcurrency 0 --- packages/vitest/src/node/config/resolveConfig.ts | 7 +++++++ test/config/test/failures.test.ts | 7 +++++++ test/config/vitest.config.ts | 1 + 3 files changed, 15 insertions(+) diff --git a/packages/vitest/src/node/config/resolveConfig.ts b/packages/vitest/src/node/config/resolveConfig.ts index fba6f40e1c6b..51babc9840be 100644 --- a/packages/vitest/src/node/config/resolveConfig.ts +++ b/packages/vitest/src/node/config/resolveConfig.ts @@ -207,6 +207,13 @@ export function resolveConfig( resolved.minWorkers = 1 } + if (resolved.maxConcurrency === 0) { + logger.console.warn( + c.yellow(`The option "maxConcurrency" cannot be set to 0. Using default value ${configDefaults.maxConcurrency} instead.`), + ) + resolved.maxConcurrency = configDefaults.maxConcurrency + } + if (resolved.inspect || resolved.inspectBrk) { const isSingleThread = resolved.pool === 'threads' diff --git a/test/config/test/failures.test.ts b/test/config/test/failures.test.ts index 22a08200dbb1..b9a39d5f587f 100644 --- a/test/config/test/failures.test.ts +++ b/test/config/test/failures.test.ts @@ -279,3 +279,10 @@ test('mergeReports doesn\'t work with watch mode enabled', async () => { expect(stderr).toMatch('Cannot merge reports with --watch enabled') }) + +test('maxConcurrency 0 prints a warning', async () => { + const { stderr, ctx } = await runVitest({ maxConcurrency: 0 }) + + expect(ctx?.config.maxConcurrency).toBe(5) + expect(stderr).toMatch('The option "maxConcurrency" cannot be set to 0. Using default value 5 instead.') +}) diff --git a/test/config/vitest.config.ts b/test/config/vitest.config.ts index d15b5ad03bb9..19ce7e1ff204 100644 --- a/test/config/vitest.config.ts +++ b/test/config/vitest.config.ts @@ -19,6 +19,7 @@ export default defineConfig({ truncateThreshold: 999, }, coverage: { + // test that empty reporter does not throw reporter: [], }, },