Skip to content

Commit bdb3956

Browse files
authored
feat: add test seed to banner (#2877)
1 parent 1f858e0 commit bdb3956

File tree

5 files changed

+9
-5
lines changed

5 files changed

+9
-5
lines changed

packages/runner/src/types/runner.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ export interface VitestRunnerConfig {
99
allowOnly?: boolean
1010
sequence: {
1111
shuffle?: boolean
12-
seed?: number
12+
seed: number
1313
hooks: SequenceHooks
1414
}
1515
maxConcurrency: number

packages/vitest/src/node/config.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,8 @@ export function resolveConfig(
231231
: BaseSequencer
232232
}
233233
resolved.sequence.hooks ??= 'parallel'
234+
if (resolved.sequence.sequencer === RandomSequencer)
235+
resolved.sequence.seed ??= Date.now()
234236

235237
resolved.typecheck = {
236238
...configDefaults.typecheck,

packages/vitest/src/node/logger.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { version } from '../../../../package.json'
44
import type { ErrorWithDiff } from '../types'
55
import type { TypeCheckError } from '../typecheck/typechecker'
66
import { divider } from './reporters/renderers/utils'
7+
import { RandomSequencer } from './sequencers/RandomSequencer'
78
import type { Vitest } from './core'
89
import { printError } from './error'
910

@@ -105,6 +106,9 @@ export class Logger {
105106

106107
this.log(`${c.inverse(c.bold(mode))} ${versionTest} ${c.gray(this.ctx.config.root)}`)
107108

109+
if (this.ctx.config.sequence.sequencer === RandomSequencer)
110+
this.log(c.gray(` Running tests with seed "${this.ctx.config.sequence.seed}"`))
111+
108112
if (this.ctx.config.browser)
109113
this.log(c.dim(c.green(` Browser runner started at http://${this.ctx.config.api?.host || 'localhost'}:${c.bold(`${this.ctx.server.config.server.port}`)}`)))
110114
else if (this.ctx.config.ui)

packages/vitest/src/node/sequencers/RandomSequencer.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@ export class RandomSequencer extends BaseSequencer {
55
public async sort(files: string[]) {
66
const { sequence } = this.ctx.config
77

8-
const seed = sequence?.seed ?? Date.now()
9-
10-
return shuffle(files, seed)
8+
return shuffle(files, sequence.seed)
119
}
1210
}

packages/vitest/src/types/config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -636,7 +636,7 @@ export interface ResolvedConfig extends Omit<Required<UserConfig>, 'config' | 'f
636636
sequencer: TestSequencerConstructor
637637
hooks: SequenceHooks
638638
shuffle?: boolean
639-
seed?: number
639+
seed: number
640640
}
641641

642642
typecheck: TypecheckConfig

0 commit comments

Comments
 (0)