Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: slow test threshold #2396

Merged
merged 5 commits into from
Dec 2, 2022
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions docs/config/index.md
Original file line number Diff line number Diff line change
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 seconds after which a test is considered as slow and reported as such in the results.
sheremet-va marked this conversation as resolved.
Show resolved Hide resolved
1 change: 1 addition & 0 deletions packages/vitest/src/defaults.ts
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
Expand Up @@ -457,6 +457,13 @@ export interface InlineConfig {
* Options for configuring typechecking test environment.
*/
typecheck?: Partial<TypecheckConfig>

/**
* The number of seconds after which a test is considered as slow and reported as such in the results.
sheremet-va marked this conversation as resolved.
Show resolved Hide resolved
*
* @default 300
*/
slowTestThreshold?: number
}

export interface TypecheckConfig {
Expand Down
1 change: 1 addition & 0 deletions test/core/vitest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ export default defineConfig({
],
},
test: {
slowTestThreshold: 1000,
testTimeout: 2000,
setupFiles: [
'./test/setup.ts',
Expand Down