File tree 3 files changed +24
-9
lines changed
3 files changed +24
-9
lines changed Original file line number Diff line number Diff line change 1
1
import { MessageChannel } from 'node:worker_threads'
2
- import { cpus } from 'node:os'
2
+ import * as nodeos from 'node:os'
3
3
import { pathToFileURL } from 'node:url'
4
4
import { createBirpc } from 'birpc'
5
5
import { resolve } from 'pathe'
@@ -39,9 +39,14 @@ function createWorkerChannel(project: WorkspaceProject) {
39
39
}
40
40
41
41
export function createThreadsPool ( ctx : Vitest , { execArgv, env } : PoolProcessOptions ) : ProcessPool {
42
+ const numCpus
43
+ = typeof nodeos . availableParallelism === 'function'
44
+ ? nodeos . availableParallelism ( )
45
+ : nodeos . cpus ( ) . length
46
+
42
47
const threadsCount = ctx . config . watch
43
- ? Math . max ( Math . floor ( cpus ( ) . length / 2 ) , 1 )
44
- : Math . max ( cpus ( ) . length - 1 , 1 )
48
+ ? Math . max ( Math . floor ( numCpus / 2 ) , 1 )
49
+ : Math . max ( numCpus - 1 , 1 )
45
50
46
51
const maxThreads = ctx . config . maxThreads ?? threadsCount
47
52
const minThreads = ctx . config . minThreads ?? threadsCount
Original file line number Diff line number Diff line change 1
1
import { MessageChannel } from 'node:worker_threads'
2
- import { cpus } from 'node:os'
2
+ import * as nodeos from 'node:os'
3
3
import { pathToFileURL } from 'node:url'
4
4
import { createBirpc } from 'birpc'
5
5
import { resolve } from 'pathe'
@@ -40,9 +40,14 @@ function createWorkerChannel(project: WorkspaceProject) {
40
40
}
41
41
42
42
export function createVmThreadsPool ( ctx : Vitest , { execArgv, env } : PoolProcessOptions ) : ProcessPool {
43
+ const numCpus
44
+ = typeof nodeos . availableParallelism === 'function'
45
+ ? nodeos . availableParallelism ( )
46
+ : nodeos . cpus ( ) . length
47
+
43
48
const threadsCount = ctx . config . watch
44
- ? Math . max ( Math . floor ( cpus ( ) . length / 2 ) , 1 )
45
- : Math . max ( cpus ( ) . length - 1 , 1 )
49
+ ? Math . max ( Math . floor ( numCpus / 2 ) , 1 )
50
+ : Math . max ( numCpus - 1 , 1 )
46
51
47
52
const maxThreads = ctx . config . maxThreads ?? threadsCount
48
53
const minThreads = ctx . config . minThreads ?? threadsCount
Original file line number Diff line number Diff line change 5
5
* LICENSE file in the root directory of facebook/jest GitHub project tree.
6
6
*/
7
7
8
- import { cpus } from 'node:os'
8
+ import * as nodeos from 'node:os'
9
9
import type { ResolvedConfig } from '../types'
10
10
11
11
function getDefaultThreadsCount ( config : ResolvedConfig ) {
12
+ const numCpus
13
+ = typeof nodeos . availableParallelism === 'function'
14
+ ? nodeos . availableParallelism ( )
15
+ : nodeos . cpus ( ) . length
16
+
12
17
return config . watch
13
- ? Math . max ( Math . floor ( cpus ( ) . length / 2 ) , 1 )
14
- : Math . max ( cpus ( ) . length - 1 , 1 )
18
+ ? Math . max ( Math . floor ( numCpus / 2 ) , 1 )
19
+ : Math . max ( numCpus - 1 , 1 )
15
20
}
16
21
17
22
export function getWorkerMemoryLimit ( config : ResolvedConfig ) {
You can’t perform that action at this time.
0 commit comments