diff --git a/docs/config/index.md b/docs/config/index.md index 877b2e36b11..881d8c94414 100644 --- a/docs/config/index.md +++ b/docs/config/index.md @@ -923,3 +923,10 @@ By default, if Vitest finds source error, it will fail test suite. - **Default**: _tries to find closest tsconfig.json_ Path to custom tsconfig, relative to the project root. + +### slowTestThreshold + +- **Type**: `number` +- **Default**: `300` + +The number of milliseconds after which a test is considered slow and reported as such in the results. diff --git a/packages/vitest/src/defaults.ts b/packages/vitest/src/defaults.ts index dd84c7a1438..2f2144c1f54 100644 --- a/packages/vitest/src/defaults.ts +++ b/packages/vitest/src/defaults.ts @@ -92,6 +92,7 @@ const config = { include: ['**/*.{test,spec}-d.{ts,js}'], exclude: defaultExclude, }, + slowTestThreshold: 300, } export const configDefaults: Required> = Object.freeze(config) diff --git a/packages/vitest/src/node/reporters/base.ts b/packages/vitest/src/node/reporters/base.ts index 624ff3bd6fb..51f3477f500 100644 --- a/packages/vitest/src/node/reporters/base.ts +++ b/packages/vitest/src/node/reporters/base.ts @@ -14,7 +14,6 @@ const HELP_QUITE = `${c.dim('press ')}${c.bold('q')}${c.dim(' to quit')}` const WAIT_FOR_CHANGE_PASS = `\n${c.bold(c.inverse(c.green(' PASS ')))}${c.green(' Waiting for file changes...')}` const WAIT_FOR_CHANGE_FAIL = `\n${c.bold(c.inverse(c.red(' FAIL ')))}${c.red(' Tests failed. Watching for file changes...')}` -const DURATION_LONG = 300 const LAST_RUN_LOG_TIMEOUT = 1_500 export abstract class BaseReporter implements Reporter { @@ -76,7 +75,7 @@ export abstract class BaseReporter implements Reporter { state += ` ${c.dim('|')} ${c.yellow(`${skipped.length} skipped`)}` let suffix = c.dim(' (') + state + c.dim(')') if (task.result.duration) { - const color = task.result.duration > DURATION_LONG ? c.yellow : c.gray + const color = task.result.duration > this.ctx.config.slowTestThreshold ? c.yellow : c.gray suffix += color(` ${Math.round(task.result.duration)}${c.dim('ms')}`) } if (this.ctx.config.logHeapUsage && task.result.heap != null) diff --git a/packages/vitest/src/types/config.ts b/packages/vitest/src/types/config.ts index 05c8595f24d..81453e184fe 100644 --- a/packages/vitest/src/types/config.ts +++ b/packages/vitest/src/types/config.ts @@ -457,6 +457,13 @@ export interface InlineConfig { * Options for configuring typechecking test environment. */ typecheck?: Partial + + /** + * The number of milliseconds after which a test is considered slow and reported as such in the results. + * + * @default 300 + */ + slowTestThreshold?: number } export interface TypecheckConfig { diff --git a/test/core/vitest.config.ts b/test/core/vitest.config.ts index 97d043a2613..1b28a90cef9 100644 --- a/test/core/vitest.config.ts +++ b/test/core/vitest.config.ts @@ -37,6 +37,7 @@ export default defineConfig({ ], }, test: { + slowTestThreshold: 1000, testTimeout: 2000, setupFiles: [ './test/setup.ts',