mirror of
https://github.com/hanzoai/vitest.git
synced 2026-09-24 17:04:25 +00:00
feat: support configure maxTheads and minThreads (#59)
Co-authored-by: Anthony Fu <[email protected]>
This commit is contained in:
committed by
GitHub
co-authored by
Anthony Fu
parent
eb6c24a085
commit
f76f893dc7
@@ -81,7 +81,7 @@ $ npx vitest
|
||||
- Create `vitest.config.ts`, which will have the higher priority
|
||||
- Pass `--config` option to CLI, e.g. `vitest --config ./path/to/vitest.config.ts`
|
||||
- Use `process.env.VITEST` to conditionally apply differnet configuration in `vite.config.ts`
|
||||
|
||||
- Use `process.env.VITEST_MAX_THREADS` to limit amount of worker threads
|
||||
To configure `vitest` itself, add `test` property in your Vite config
|
||||
|
||||
```ts
|
||||
|
||||
+8
-4
@@ -54,10 +54,8 @@ export async function initViteServer(options: CliOptions = {}) {
|
||||
|
||||
resolved.interpretDefault = resolved.interpretDefault || true
|
||||
|
||||
const env = process.env
|
||||
const CI = !!env.CI
|
||||
const UPDATE_SNAPSHOT = resolved.update || env.UPDATE_SNAPSHOT
|
||||
|
||||
const CI = !!process.env.CI
|
||||
const UPDATE_SNAPSHOT = resolved.update || process.env.UPDATE_SNAPSHOT
|
||||
resolved.snapshotOptions = {
|
||||
updateSnapshot: CI && !UPDATE_SNAPSHOT
|
||||
? 'none'
|
||||
@@ -66,6 +64,12 @@ export async function initViteServer(options: CliOptions = {}) {
|
||||
: 'new',
|
||||
} as SnapshotStateOptions
|
||||
|
||||
if (process.env.VITEST_MAX_THREADS)
|
||||
resolved.maxThreads = parseInt(process.env.VITEST_MAX_THREADS)
|
||||
|
||||
if (process.env.VITEST_MIN_THREADS)
|
||||
resolved.minThreads = parseInt(process.env.VITEST_MIN_THREADS)
|
||||
|
||||
return {
|
||||
server,
|
||||
config: resolved,
|
||||
|
||||
@@ -15,6 +15,8 @@ export interface WorkerPool {
|
||||
export function createWorkerPool(ctx: VitestContext) {
|
||||
const piscina = new Piscina({
|
||||
filename: new URL('./dist/node/worker.js', pathToFileURL(distDir)).href,
|
||||
maxThreads: ctx.config.maxThreads,
|
||||
minThreads: ctx.config.minThreads,
|
||||
})
|
||||
|
||||
const runTestFiles: WorkerPool['runTestFiles'] = async(files, invalidates) => {
|
||||
|
||||
@@ -81,6 +81,27 @@ export interface UserOptions {
|
||||
reporter?: Reporter
|
||||
|
||||
/**
|
||||
* Enable multi-threading
|
||||
*
|
||||
* @default true
|
||||
*/
|
||||
threads?: boolean
|
||||
|
||||
/**
|
||||
* Maximum number of threads
|
||||
*
|
||||
* @default available CPUs
|
||||
*/
|
||||
maxThreads?: number
|
||||
|
||||
/**
|
||||
* Minimum number of threads
|
||||
*
|
||||
* @default available CPUs
|
||||
*/
|
||||
minThreads?: number
|
||||
|
||||
/*
|
||||
* Interpret CJS module's default as named exports
|
||||
*
|
||||
* @default true
|
||||
|
||||
Reference in New Issue
Block a user