Skip to content

Commit 98974ba

Browse files
poyohosheremet-va
andauthoredDec 2, 2022
feat: slow test threshold (#2396)
* feat: slowTestThreshold * feat: docs * test: slowTestThreshold * docs: seconds->milliseconds Co-authored-by: Vladimir <sleuths.slews0s@icloud.com> Co-authored-by: Vladimir <sheremet.va@icloud.com>
1 parent fd8292a commit 98974ba

File tree

5 files changed

+17
-2
lines changed

5 files changed

+17
-2
lines changed
 

‎docs/config/index.md

+7
Original file line numberDiff line numberDiff line change
@@ -923,3 +923,10 @@ By default, if Vitest finds source error, it will fail test suite.
923923
- **Default**: _tries to find closest tsconfig.json_
924924

925925
Path to custom tsconfig, relative to the project root.
926+
927+
### slowTestThreshold
928+
929+
- **Type**: `number`
930+
- **Default**: `300`
931+
932+
The number of milliseconds after which a test is considered slow and reported as such in the results.

‎packages/vitest/src/defaults.ts

+1
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ const config = {
9292
include: ['**/*.{test,spec}-d.{ts,js}'],
9393
exclude: defaultExclude,
9494
},
95+
slowTestThreshold: 300,
9596
}
9697

9798
export const configDefaults: Required<Pick<UserConfig, keyof typeof config>> = Object.freeze(config)

‎packages/vitest/src/node/reporters/base.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ const HELP_QUITE = `${c.dim('press ')}${c.bold('q')}${c.dim(' to quit')}`
1414
const WAIT_FOR_CHANGE_PASS = `\n${c.bold(c.inverse(c.green(' PASS ')))}${c.green(' Waiting for file changes...')}`
1515
const WAIT_FOR_CHANGE_FAIL = `\n${c.bold(c.inverse(c.red(' FAIL ')))}${c.red(' Tests failed. Watching for file changes...')}`
1616

17-
const DURATION_LONG = 300
1817
const LAST_RUN_LOG_TIMEOUT = 1_500
1918

2019
export abstract class BaseReporter implements Reporter {
@@ -76,7 +75,7 @@ export abstract class BaseReporter implements Reporter {
7675
state += ` ${c.dim('|')} ${c.yellow(`${skipped.length} skipped`)}`
7776
let suffix = c.dim(' (') + state + c.dim(')')
7877
if (task.result.duration) {
79-
const color = task.result.duration > DURATION_LONG ? c.yellow : c.gray
78+
const color = task.result.duration > this.ctx.config.slowTestThreshold ? c.yellow : c.gray
8079
suffix += color(` ${Math.round(task.result.duration)}${c.dim('ms')}`)
8180
}
8281
if (this.ctx.config.logHeapUsage && task.result.heap != null)

‎packages/vitest/src/types/config.ts

+7
Original file line numberDiff line numberDiff line change
@@ -457,6 +457,13 @@ export interface InlineConfig {
457457
* Options for configuring typechecking test environment.
458458
*/
459459
typecheck?: Partial<TypecheckConfig>
460+
461+
/**
462+
* The number of milliseconds after which a test is considered slow and reported as such in the results.
463+
*
464+
* @default 300
465+
*/
466+
slowTestThreshold?: number
460467
}
461468

462469
export interface TypecheckConfig {

‎test/core/vitest.config.ts

+1
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ export default defineConfig({
3737
],
3838
},
3939
test: {
40+
slowTestThreshold: 1000,
4041
testTimeout: 2000,
4142
setupFiles: [
4243
'./test/setup.ts',

0 commit comments

Comments
 (0)
Please sign in to comment.