Skip to content

Commit

Permalink
feat: slow test threshold (#2396)
Browse files Browse the repository at this point in the history
* 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>
  • Loading branch information
3 people committed Dec 2, 2022
1 parent fd8292a commit 98974ba
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 2 deletions.
7 changes: 7 additions & 0 deletions docs/config/index.md
Expand Up @@ -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.
1 change: 1 addition & 0 deletions packages/vitest/src/defaults.ts
Expand Up @@ -92,6 +92,7 @@ const config = {
include: ['**/*.{test,spec}-d.{ts,js}'],
exclude: defaultExclude,
},
slowTestThreshold: 300,
}

export const configDefaults: Required<Pick<UserConfig, keyof typeof config>> = Object.freeze(config)
3 changes: 1 addition & 2 deletions packages/vitest/src/node/reporters/base.ts
Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
Expand Down
7 changes: 7 additions & 0 deletions packages/vitest/src/types/config.ts
Expand Up @@ -457,6 +457,13 @@ export interface InlineConfig {
* Options for configuring typechecking test environment.
*/
typecheck?: Partial<TypecheckConfig>

/**
* 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 {
Expand Down
1 change: 1 addition & 0 deletions test/core/vitest.config.ts
Expand Up @@ -37,6 +37,7 @@ export default defineConfig({
],
},
test: {
slowTestThreshold: 1000,
testTimeout: 2000,
setupFiles: [
'./test/setup.ts',
Expand Down

0 comments on commit 98974ba

Please sign in to comment.