diff --git a/src/polyfills/cpus.ts b/src/polyfills/cpus.ts new file mode 100644 index 00000000..633ee74e --- /dev/null +++ b/src/polyfills/cpus.ts @@ -0,0 +1,9 @@ +import { + availableParallelism as nodeAvailableParallelism, + cpus, +} from 'node:os'; + +export const availableParallelism = (): number => + typeof nodeAvailableParallelism === 'function' + ? Math.floor(nodeAvailableParallelism() / 2) + : (cpus()?.length ?? 1); diff --git a/src/services/run-tests.ts b/src/services/run-tests.ts index 50031fc4..b9a8daf9 100644 --- a/src/services/run-tests.ts +++ b/src/services/run-tests.ts @@ -14,6 +14,7 @@ import { format } from './format.js'; import { runTestFile } from './run-test-file.js'; import { isQuiet } from '../parsers/output.js'; import { results } from '../configs/poku.js'; +import { availableParallelism } from '../polyfills/cpus.js'; const cwd = processCWD(); @@ -101,7 +102,7 @@ export const runTestsParallel = async ( ? [sanitizePath(dir)] : await listFiles(testDir, configs); const filesByConcurrency: string[][] = []; - const concurrencyLimit = configs?.concurrency || 0; + const concurrencyLimit = configs?.concurrency ?? availableParallelism(); const concurrencyResults: (boolean | undefined)[][] = []; const showLogs = !isQuiet(configs);