Skip to content

Commit

Permalink
feat: add test seed to banner (#2877)
Browse files Browse the repository at this point in the history
  • Loading branch information
btkostner authored Feb 21, 2023
1 parent 1f858e0 commit bdb3956
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 5 deletions.
2 changes: 1 addition & 1 deletion packages/runner/src/types/runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export interface VitestRunnerConfig {
allowOnly?: boolean
sequence: {
shuffle?: boolean
seed?: number
seed: number
hooks: SequenceHooks
}
maxConcurrency: number
Expand Down
2 changes: 2 additions & 0 deletions packages/vitest/src/node/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,8 @@ export function resolveConfig(
: BaseSequencer
}
resolved.sequence.hooks ??= 'parallel'
if (resolved.sequence.sequencer === RandomSequencer)
resolved.sequence.seed ??= Date.now()

resolved.typecheck = {
...configDefaults.typecheck,
Expand Down
4 changes: 4 additions & 0 deletions packages/vitest/src/node/logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { version } from '../../../../package.json'
import type { ErrorWithDiff } from '../types'
import type { TypeCheckError } from '../typecheck/typechecker'
import { divider } from './reporters/renderers/utils'
import { RandomSequencer } from './sequencers/RandomSequencer'
import type { Vitest } from './core'
import { printError } from './error'

Expand Down Expand Up @@ -105,6 +106,9 @@ export class Logger {

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

if (this.ctx.config.sequence.sequencer === RandomSequencer)
this.log(c.gray(` Running tests with seed "${this.ctx.config.sequence.seed}"`))

if (this.ctx.config.browser)
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}`)}`)))
else if (this.ctx.config.ui)
Expand Down
4 changes: 1 addition & 3 deletions packages/vitest/src/node/sequencers/RandomSequencer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ export class RandomSequencer extends BaseSequencer {
public async sort(files: string[]) {
const { sequence } = this.ctx.config

const seed = sequence?.seed ?? Date.now()

return shuffle(files, seed)
return shuffle(files, sequence.seed)
}
}
2 changes: 1 addition & 1 deletion packages/vitest/src/types/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -636,7 +636,7 @@ export interface ResolvedConfig extends Omit<Required<UserConfig>, 'config' | 'f
sequencer: TestSequencerConstructor
hooks: SequenceHooks
shuffle?: boolean
seed?: number
seed: number
}

typecheck: TypecheckConfig
Expand Down

0 comments on commit bdb3956

Please sign in to comment.