Skip to content

Commit 70e8a38

Browse files
inottnAriPerkkio
andauthoredJan 1, 2024
fix(vm-threads): don't crash on percentage based memoryLimit (#4802)
Co-authored-by: Ari Perkkiö <ari.perkkio@gmail.com>
1 parent f99fd6c commit 70e8a38

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed
 

‎packages/vitest/src/node/pools/vm-threads.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -170,9 +170,10 @@ function getMemoryLimit(config: ResolvedConfig) {
170170
)
171171
}
172172

173-
if (limit && limit > 1)
173+
// If totalmem is not supported we cannot resolve percentage based values like 0.5, "50%"
174+
if ((typeof limit === 'number' && limit > 1) || (typeof limit === 'string' && limit.at(-1) !== '%'))
174175
return stringToBytes(limit)
175176

176-
// just ignore "experimentalVmWorkerMemoryLimit" value because we cannot detect memory limit
177+
// just ignore "memoryLimit" value because we cannot detect memory limit
177178
return null
178179
}

‎packages/vitest/src/utils/memory-limit.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ export function getWorkerMemoryLimit(config: ResolvedConfig) {
2323
const memoryLimit = config.poolOptions?.vmThreads?.memoryLimit
2424

2525
if (memoryLimit)
26-
return stringToBytes(memoryLimit)
26+
return memoryLimit
2727

2828
return 1 / (config.poolOptions?.vmThreads?.maxThreads ?? getDefaultThreadsCount(config))
2929
}
@@ -94,7 +94,7 @@ export function stringToBytes(
9494
return Math.floor(input)
9595
}
9696
else {
97-
throw new Error('Unexpected numerical input for "experimentalVmWorkerMemoryLimit"')
97+
throw new Error('Unexpected numerical input for "memoryLimit"')
9898
}
9999
}
100100

0 commit comments

Comments
 (0)
Please sign in to comment.