-
-
Notifications
You must be signed in to change notification settings - Fork 6.6k
feat: add a seed value to test runs #13400
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
Changes from all commits
886a1e2
d551da5
4e44bef
0877be4
d1f5311
49c060f
bc8b4eb
c5ca4d7
fecf106
c39e63f
923f556
07f7b55
3987577
dda334e
3c61bc2
08e53ac
e848382
9424589
83f5e9a
bfcc0b4
3e78642
ba7f269
40047fe
6730725
589d434
4eafd79
ebdf7cb
116bdca
b7d5faa
c7d196a
d2af3a6
2ea7dc6
b9b8abf
679521b
adda4f7
01ac6f3
71c04c4
1fee0a7
7b97aab
076eb02
d0eed4a
523b995
1328b7b
1aae653
d568629
e246b8a
3efe6fc
0fb3e79
d023a21
535730b
3cb272b
b8a70eb
b2021e5
91212a2
ed5f9c1
157ea7e
cf0230c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1614,6 +1614,12 @@ const config: Config = { | |
| export default config; | ||
| ``` | ||
|
|
||
| ### `showSeed` \[boolean] | ||
|
|
||
| Default: `false` | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Such a great option, I love it 💕
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I was just about to tag you 🙂 Does this (i.e. this entire implementation, not just this specific option) fit your use case and usage?
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm thinking you can just document setting this config flag instead of printing the seed yourself (as a major release I guess)
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It will definitely help a lot. So far
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I haven't documented the removal of the seed printing yet, but that was my idea when I opened dubzzz/fast-check#3287 |
||
|
|
||
| The equivalent of the [`--showSeed`](CLI.md#--showseed) flag to print the seed in the test report summary. | ||
|
|
||
| ### `slowTestThreshold` \[number] | ||
|
|
||
| Default: `5` | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| /** | ||
| * Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. | ||
| * | ||
| * This source code is licensed under the MIT license found in the | ||
| * LICENSE file in the root directory of this source tree. | ||
| */ | ||
|
|
||
| import * as path from 'path'; | ||
| import runJest from '../runJest'; | ||
|
|
||
| const dir = path.resolve(__dirname, '../jest-object'); | ||
|
|
||
| test('passes with seed', () => { | ||
| const result = runJest(dir, ['get-seed.test.js', '--seed', '1234']); | ||
| expect(result.exitCode).toBe(0); | ||
| }); | ||
|
|
||
| test('fails with wrong seed', () => { | ||
| const result = runJest(dir, ['get-seed.test.js', '--seed', '1111']); | ||
| expect(result.exitCode).toBe(1); | ||
| }); | ||
|
|
||
| test('seed always exists', () => { | ||
| const result = runJest(dir, ['any-seed.test.js']); | ||
| expect(result.exitCode).toBe(0); | ||
| }); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| /** | ||
| * Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. | ||
| * | ||
| * This source code is licensed under the MIT license found in the | ||
| * LICENSE file in the root directory of this source tree. | ||
| */ | ||
|
|
||
| import * as path from 'path'; | ||
| import {extractSummary, replaceSeed} from '../Utils'; | ||
| import runJest from '../runJest'; | ||
|
|
||
| const dir = path.resolve(__dirname, '../jest-object'); | ||
|
|
||
| const randomSeedValueRegExp = /Seed:\s+<<REPLACED>>/; | ||
| const seedValueRegExp = /Seed:\s+1234/; | ||
|
|
||
| test('--showSeed changes report to output seed', () => { | ||
| const {stderr} = runJest(dir, ['--showSeed', '--no-cache']); | ||
|
|
||
| const {summary} = extractSummary(stderr); | ||
|
|
||
| expect(replaceSeed(summary)).toMatch(randomSeedValueRegExp); | ||
| }); | ||
|
|
||
| test('if --showSeed is not present the report will not show the seed', () => { | ||
| const {stderr} = runJest(dir, ['--seed', '1234']); | ||
|
|
||
| const {summary} = extractSummary(stderr); | ||
|
|
||
| expect(replaceSeed(summary)).not.toMatch(randomSeedValueRegExp); | ||
| }); | ||
|
|
||
| test('if showSeed is present in the config the report will show the seed', () => { | ||
| const {stderr} = runJest(dir, [ | ||
| '--seed', | ||
| '1234', | ||
| '--config', | ||
| 'different-config.json', | ||
| ]); | ||
|
|
||
| const {summary} = extractSummary(stderr); | ||
|
|
||
| expect(summary).toMatch(seedValueRegExp); | ||
| }); | ||
|
|
||
| test('--seed --showSeed will show the seed in the report', () => { | ||
| const {stderr} = runJest(dir, ['--showSeed', '--seed', '1234']); | ||
|
|
||
| const {summary} = extractSummary(stderr); | ||
|
|
||
| expect(summary).toMatch(seedValueRegExp); | ||
| }); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| /** | ||
| * Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. | ||
| * | ||
| * This source code is licensed under the MIT license found in the | ||
| * LICENSE file in the root directory of this source tree. | ||
| */ | ||
|
|
||
| test('ensure seed exists', () => { | ||
| expect(jest.getSeed()).toEqual(expect.any(Number)); | ||
| }); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| /** | ||
| * Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. | ||
| * | ||
| * This source code is licensed under the MIT license found in the | ||
| * LICENSE file in the root directory of this source tree. | ||
| */ | ||
|
|
||
| test('getSeed', () => { | ||
| expect(jest.getSeed()).toBe(1234); | ||
| }); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| { | ||
| "displayName": "Config from different-config.json file", | ||
| "showSeed": true | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| { | ||
| "jest": { | ||
| "testEnvironment": "node" | ||
| } | ||
| } |
Uh oh!
There was an error while loading. Please reload this page.