Skip to content

Commit 8182b77

Browse files
kaigritunKai Gritunsheremet-va
authored
fix: log seed when only sequence.shuffle.tests is enabled (#9576)
Co-authored-by: Kai Gritun <kai@kaigritun.com> Co-authored-by: Vladimir <sleuths.slews0s@icloud.com>
1 parent 3eb2cd5 commit 8182b77

File tree

3 files changed

+51
-2
lines changed

3 files changed

+51
-2
lines changed

packages/vitest/src/node/config/resolveConfig.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -742,7 +742,8 @@ export function resolveConfig(
742742
}
743743
resolved.sequence.groupOrder ??= 0
744744
resolved.sequence.hooks ??= 'stack'
745-
if (resolved.sequence.sequencer === RandomSequencer) {
745+
// Set seed if either files or tests are shuffled
746+
if (resolved.sequence.sequencer === RandomSequencer || resolved.sequence.shuffle) {
746747
resolved.sequence.seed ??= Date.now()
747748
}
748749

packages/vitest/src/node/logger.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,8 @@ export class Logger {
232232

233233
this.log(withLabel(color, mode, `v${this.ctx.version} `) + c.gray(this.ctx.config.root))
234234

235-
if (this.ctx.config.sequence.sequencer === RandomSequencer) {
235+
// Log seed if either files (RandomSequencer) or tests are shuffled
236+
if (this.ctx.config.sequence.sequencer === RandomSequencer || this.ctx.config.sequence.shuffle) {
236237
this.log(PAD + c.gray(`Running tests with seed "${this.ctx.config.sequence.seed}"`))
237238
}
238239

test/cli/test/config/sequence-shuffle.test.ts

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,3 +115,50 @@ test('shuffle with a known seed', async () => {
115115
}
116116
`)
117117
})
118+
119+
test('should log seed when only shuffle.tests is enabled', async () => {
120+
const { stdout } = await runInlineTests({
121+
'basic.test.js': /* js */ `
122+
import { test } from 'vitest'
123+
test('example', () => {})
124+
`,
125+
}, {
126+
sequence: {
127+
seed: 12345,
128+
shuffle: { files: false, tests: true },
129+
},
130+
})
131+
132+
expect(stdout).toContain('Running tests with seed "12345"')
133+
})
134+
135+
test('should log seed when shuffle is true', async () => {
136+
const { stdout } = await runInlineTests({
137+
'basic.test.js': /* js */ `
138+
import { test } from 'vitest'
139+
test('example', () => {})
140+
`,
141+
}, {
142+
sequence: {
143+
seed: 67890,
144+
shuffle: true,
145+
},
146+
})
147+
148+
expect(stdout).toContain('Running tests with seed "67890"')
149+
})
150+
151+
test('should not log seed when shuffle is disabled', async () => {
152+
const { stdout } = await runInlineTests({
153+
'basic.test.js': /* js */ `
154+
import { test } from 'vitest'
155+
test('example', () => {})
156+
`,
157+
}, {
158+
sequence: {
159+
shuffle: false,
160+
},
161+
})
162+
163+
expect(stdout).not.toContain('Running tests with seed')
164+
})

0 commit comments

Comments
 (0)