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: add test seed to banner #2877

Merged
merged 7 commits into from Feb 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/runner/src/types/runner.ts
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
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
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
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
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