MCPcopy
hub / github.com/vitest-dev/vitest / getMemoryLimit

Function getMemoryLimit

packages/vitest/src/node/pool.ts:322–344  ·  view source on GitHub ↗
(config: ResolvedConfig, pool: string)

Source from the content-addressed store, hash-verified

320}
321
322function getMemoryLimit(config: ResolvedConfig, pool: string) {
323 if (pool !== 'vmForks' && pool !== 'vmThreads') {
324 return null
325 }
326
327 const memory = nodeos.totalmem()
328 const limit = getWorkerMemoryLimit(config)
329
330 if (typeof memory === 'number') {
331 return stringToBytes(limit, config.watch ? memory / 2 : memory)
332 }
333
334 // If totalmem is not supported we cannot resolve percentage based values like 0.5, "50%"
335 if (
336 (typeof limit === 'number' && limit > 1)
337 || (typeof limit === 'string' && limit.at(-1) !== '%')
338 ) {
339 return stringToBytes(limit)
340 }
341
342 // just ignore "memoryLimit" value because we cannot detect memory limit
343 return null
344}
345
346function groupSpecs(specs: TestSpecification[], environments: WeakMap<TestSpecification, ContextTestEnvironment>) {
347 // Test files are passed to test runner one at a time, except for Typechecker or when "--maxWorker=1 --no-isolate"

Callers 1

executeTestsFunction · 0.85

Calls 3

getWorkerMemoryLimitFunction · 0.90
stringToBytesFunction · 0.90
atMethod · 0.80

Tested by

no test coverage detected