From 886a1e2ff082c9b4af74de9a99d50b6dcdd68ad8 Mon Sep 17 00:00:00 2001 From: josh <41476440+Joshua-Hwang@users.noreply.github.com> Date: Thu, 6 Oct 2022 20:56:38 +1000 Subject: [PATCH 01/53] planned documentation --- docs/CLI.md | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/docs/CLI.md b/docs/CLI.md index 75eaa78a052f..9439ddb896dc 100644 --- a/docs/CLI.md +++ b/docs/CLI.md @@ -350,6 +350,15 @@ The default regex matching works fine on small runs, but becomes slow if provide ::: +### `--seed=` + +TODO jhwang make a clearer description +Provide a seed number that the tests have access to via `jest.getSeed()`. + +```bash +jest --seed=1324 +``` + ### `--selectProjects ... ` Run the tests of the specified projects. Jest uses the attribute `displayName` in the configuration to identify each project. If you use this option, you should provide a `displayName` to all your projects. From d551da5bdeaeed179703e2d75f4a5a1cbf31be7a Mon Sep 17 00:00:00 2001 From: josh <41476440+Joshua-Hwang@users.noreply.github.com> Date: Thu, 6 Oct 2022 20:57:52 +1000 Subject: [PATCH 02/53] expose seed to runtime --- packages/jest-cli/src/cli/args.ts | 5 +++++ packages/jest-config/src/index.ts | 1 + packages/jest-config/src/normalize.ts | 3 +++ packages/jest-environment-jsdom/src/index.ts | 4 +++- packages/jest-environment-node/src/index.ts | 4 +++- packages/jest-environment/src/index.ts | 6 ++++++ packages/jest-runtime/src/index.ts | 1 + packages/jest-types/src/Config.ts | 2 ++ packages/test-utils/src/config.ts | 1 + 9 files changed, 25 insertions(+), 2 deletions(-) diff --git a/packages/jest-cli/src/cli/args.ts b/packages/jest-cli/src/cli/args.ts index f58194047977..c22770d70726 100644 --- a/packages/jest-cli/src/cli/args.ts +++ b/packages/jest-cli/src/cli/args.ts @@ -510,6 +510,11 @@ export const options: {[key: string]: Options} = { "Allows to use a custom runner instead of Jest's default test runner.", type: 'string', }, + seed: { + description: + 'TODO jhwang Specify the seed that will be exposed to tests via jest.getSeed().', + type: 'number', + }, selectProjects: { description: 'Run the tests of the specified projects. ' + diff --git a/packages/jest-config/src/index.ts b/packages/jest-config/src/index.ts index f8fb20d3590a..bbe76f06f5b8 100644 --- a/packages/jest-config/src/index.ts +++ b/packages/jest-config/src/index.ts @@ -115,6 +115,7 @@ const groupOptions = ( reporters: options.reporters, rootDir: options.rootDir, runTestsByPath: options.runTestsByPath, + seed: options.seed, shard: options.shard, silent: options.silent, skipFilter: options.skipFilter, diff --git a/packages/jest-config/src/normalize.ts b/packages/jest-config/src/normalize.ts index 3d13af7e2bb7..a72fa32da84c 100644 --- a/packages/jest-config/src/normalize.ts +++ b/packages/jest-config/src/normalize.ts @@ -1135,6 +1135,9 @@ export default async function normalize( newOptions.logHeapUsage = false; } + console.log('newOptions.seed', newOptions.seed); + console.log('argv.seed', argv.seed); + if (argv.shard) { newOptions.shard = parseShardPair(argv.shard); } diff --git a/packages/jest-environment-jsdom/src/index.ts b/packages/jest-environment-jsdom/src/index.ts index 5973678a40f8..edbf300d6928 100644 --- a/packages/jest-environment-jsdom/src/index.ts +++ b/packages/jest-environment-jsdom/src/index.ts @@ -38,9 +38,11 @@ export default class JSDOMEnvironment implements JestEnvironment { private errorEventListener: ((event: Event & {error: Error}) => void) | null; moduleMocker: ModuleMocker | null; customExportConditions = ['browser']; + seed: number; constructor(config: JestEnvironmentConfig, context: EnvironmentContext) { - const {projectConfig} = config; + const {projectConfig, globalConfig} = config; + this.seed = globalConfig.seed; const virtualConsole = new VirtualConsole(); virtualConsole.sendTo(context.console, {omitJSDOMErrors: true}); diff --git a/packages/jest-environment-node/src/index.ts b/packages/jest-environment-node/src/index.ts index 5d326167e133..095e62762096 100644 --- a/packages/jest-environment-node/src/index.ts +++ b/packages/jest-environment-node/src/index.ts @@ -64,10 +64,12 @@ export default class NodeEnvironment implements JestEnvironment { global: Global.Global; moduleMocker: ModuleMocker | null; customExportConditions = ['node', 'node-addons']; + seed: number; // while `context` is unused, it should always be passed constructor(config: JestEnvironmentConfig, _context: EnvironmentContext) { - const {projectConfig} = config; + const {projectConfig, globalConfig} = config; + this.seed = globalConfig.seed; this.context = createContext(); const global = runInContext( 'this', diff --git a/packages/jest-environment/src/index.ts b/packages/jest-environment/src/index.ts index 793473b1d51c..ca344f310146 100644 --- a/packages/jest-environment/src/index.ts +++ b/packages/jest-environment/src/index.ts @@ -44,6 +44,7 @@ export declare class JestEnvironment { fakeTimersModern: ModernFakeTimers | null; moduleMocker: ModuleMocker | null; getVmContext(): Context | null; + seed: number; setup(): Promise; teardown(): Promise; handleTestEvent?: Circus.EventHandler; @@ -148,6 +149,11 @@ export interface Jest { * Not available when using legacy fake timers implementation. */ getRealSystemTime(): number; + /** + * Fetches the seed generated for this particular running of Jest. + * It can also be manually set with --seed CLI argument. + */ + getSeed(): number; /** * Returns the number of fake timers still left to run. */ diff --git a/packages/jest-runtime/src/index.ts b/packages/jest-runtime/src/index.ts index 5b64adeb2ea2..fafd340a26ac 100644 --- a/packages/jest-runtime/src/index.ts +++ b/packages/jest-runtime/src/index.ts @@ -2123,6 +2123,7 @@ export default class Runtime { ); } }, + getSeed: () => this._environment.seed, getTimerCount: () => _getFakeTimers().getTimerCount(), isMockFunction: this._moduleMocker.isMockFunction, isolateModules, diff --git a/packages/jest-types/src/Config.ts b/packages/jest-types/src/Config.ts index e331247ab634..7ec8a8f915da 100644 --- a/packages/jest-types/src/Config.ts +++ b/packages/jest-types/src/Config.ts @@ -394,6 +394,7 @@ export type GlobalConfig = { reporters?: Array; runTestsByPath: boolean; rootDir: string; + seed: number; shard?: ShardConfig; silent?: boolean; skipFilter: boolean; @@ -537,6 +538,7 @@ export type Argv = Arguments< rootDir: string; roots: Array; runInBand: boolean; + seed: number; selectProjects: Array; setupFiles: Array; setupFilesAfterEnv: Array; diff --git a/packages/test-utils/src/config.ts b/packages/test-utils/src/config.ts index 92e65d53e91b..adb637b4b9c9 100644 --- a/packages/test-utils/src/config.ts +++ b/packages/test-utils/src/config.ts @@ -47,6 +47,7 @@ const DEFAULT_GLOBAL_CONFIG: Config.GlobalConfig = { reporters: [], rootDir: '/test_root_dir/', runTestsByPath: false, + seed: 1234, silent: false, skipFilter: false, snapshotFormat: {}, From 4e44bef2b8404ae50cbc8e323bfd779344e18ab8 Mon Sep 17 00:00:00 2001 From: josh <41476440+Joshua-Hwang@users.noreply.github.com> Date: Thu, 6 Oct 2022 21:10:35 +1000 Subject: [PATCH 03/53] WIP documentation --- docs/JestObjectAPI.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/docs/JestObjectAPI.md b/docs/JestObjectAPI.md index d91ed7d768e2..f88b95f6a230 100644 --- a/docs/JestObjectAPI.md +++ b/docs/JestObjectAPI.md @@ -908,6 +908,9 @@ This function is not available when using legacy fake timers implementation. ## Misc +### `jest.getSeed()` +TODO jhwang + ### `jest.setTimeout(timeout)` Set the default timeout interval (in milliseconds) for all tests and before/after hooks in the test file. This only affects the test file from which this function is called. The default timeout interval is 5 seconds if this method is not called. From 0877be4729adad9cda758105e31ed285511a4141 Mon Sep 17 00:00:00 2001 From: josh <41476440+Joshua-Hwang@users.noreply.github.com> Date: Thu, 6 Oct 2022 22:55:21 +1000 Subject: [PATCH 04/53] integration tests for passing the seed to runtime --- e2e/__tests__/jestObject.test.ts | 27 +++++++++++++++++++++++ e2e/jest-object/__test__/any-seed.test.js | 3 +++ e2e/jest-object/__test__/get-seed.test.js | 9 ++++++++ e2e/jest-object/package.json | 5 +++++ packages/jest-config/src/normalize.ts | 1 + packages/jest-types/src/Config.ts | 1 + 6 files changed, 46 insertions(+) create mode 100644 e2e/__tests__/jestObject.test.ts create mode 100644 e2e/jest-object/__test__/any-seed.test.js create mode 100644 e2e/jest-object/__test__/get-seed.test.js create mode 100644 e2e/jest-object/package.json diff --git a/e2e/__tests__/jestObject.test.ts b/e2e/__tests__/jestObject.test.ts new file mode 100644 index 000000000000..61054fd62b92 --- /dev/null +++ b/e2e/__tests__/jestObject.test.ts @@ -0,0 +1,27 @@ +/** + * 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); + expect(result.exitCode).toBe(expect.any(Number)) +}); + +test('failes 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); +}); diff --git a/e2e/jest-object/__test__/any-seed.test.js b/e2e/jest-object/__test__/any-seed.test.js new file mode 100644 index 000000000000..5db3e7797dea --- /dev/null +++ b/e2e/jest-object/__test__/any-seed.test.js @@ -0,0 +1,3 @@ +test('ensure seed exists', () => { + expect(jest.getSeed()).toBe(expect.any(Number)); +}); diff --git a/e2e/jest-object/__test__/get-seed.test.js b/e2e/jest-object/__test__/get-seed.test.js new file mode 100644 index 000000000000..17d2954be64d --- /dev/null +++ b/e2e/jest-object/__test__/get-seed.test.js @@ -0,0 +1,9 @@ +/** + * 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()).toEqual(1234); +}); diff --git a/e2e/jest-object/package.json b/e2e/jest-object/package.json new file mode 100644 index 000000000000..148788b25446 --- /dev/null +++ b/e2e/jest-object/package.json @@ -0,0 +1,5 @@ +{ + "jest": { + "testEnvironment": "node" + } +} diff --git a/packages/jest-config/src/normalize.ts b/packages/jest-config/src/normalize.ts index a72fa32da84c..bfb54e2fb437 100644 --- a/packages/jest-config/src/normalize.ts +++ b/packages/jest-config/src/normalize.ts @@ -917,6 +917,7 @@ export default async function normalize( case 'rootDir': case 'runTestsByPath': case 'sandboxInjectedGlobals': + case 'seed': case 'silent': case 'skipFilter': case 'skipNodeResolution': diff --git a/packages/jest-types/src/Config.ts b/packages/jest-types/src/Config.ts index 7ec8a8f915da..b41124d0089e 100644 --- a/packages/jest-types/src/Config.ts +++ b/packages/jest-types/src/Config.ts @@ -289,6 +289,7 @@ export type InitialOptions = Partial<{ runTestsByPath: boolean; runtime: string; sandboxInjectedGlobals: Array; + seed: number; setupFiles: Array; setupFilesAfterEnv: Array; silent: boolean; From d1f5311871bf32b35bddebb1386521da6381a1b8 Mon Sep 17 00:00:00 2001 From: josh <41476440+Joshua-Hwang@users.noreply.github.com> Date: Thu, 6 Oct 2022 23:22:37 +1000 Subject: [PATCH 05/53] seed is generated when not supplied --- e2e/__tests__/jestObject.test.ts | 1 - e2e/jest-object/__test__/any-seed.test.js | 2 +- packages/jest-config/src/normalize.ts | 14 ++++++++++---- 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/e2e/__tests__/jestObject.test.ts b/e2e/__tests__/jestObject.test.ts index 61054fd62b92..53b5ce2ce05e 100644 --- a/e2e/__tests__/jestObject.test.ts +++ b/e2e/__tests__/jestObject.test.ts @@ -13,7 +13,6 @@ 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); - expect(result.exitCode).toBe(expect.any(Number)) }); test('failes with wrong seed', () => { diff --git a/e2e/jest-object/__test__/any-seed.test.js b/e2e/jest-object/__test__/any-seed.test.js index 5db3e7797dea..1100fcfbe47f 100644 --- a/e2e/jest-object/__test__/any-seed.test.js +++ b/e2e/jest-object/__test__/any-seed.test.js @@ -1,3 +1,3 @@ test('ensure seed exists', () => { - expect(jest.getSeed()).toBe(expect.any(Number)); + expect(jest.getSeed()).toEqual(expect.any(Number)); }); diff --git a/packages/jest-config/src/normalize.ts b/packages/jest-config/src/normalize.ts index bfb54e2fb437..f13430a373b3 100644 --- a/packages/jest-config/src/normalize.ts +++ b/packages/jest-config/src/normalize.ts @@ -917,7 +917,6 @@ export default async function normalize( case 'rootDir': case 'runTestsByPath': case 'sandboxInjectedGlobals': - case 'seed': case 'silent': case 'skipFilter': case 'skipNodeResolution': @@ -1022,6 +1021,16 @@ export default async function normalize( newOptions.onlyChanged = newOptions.watch; } + // xoroshiro128plus is used in v8 and is used here (at time of writing) + newOptions.seed = + argv.seed ?? Math.floor(0xffffffff * Math.random() - 0x80000000); + if (newOptions.seed < -0x80000000 || newOptions.seed > 0x7fffffff) { + throw new ValidationError( + 'Validation Error', + 'seed value is limited from -0x80000000 to 0x7fffffff', + ); + } + if (!newOptions.onlyChanged) { newOptions.onlyChanged = false; } @@ -1136,9 +1145,6 @@ export default async function normalize( newOptions.logHeapUsage = false; } - console.log('newOptions.seed', newOptions.seed); - console.log('argv.seed', argv.seed); - if (argv.shard) { newOptions.shard = parseShardPair(argv.shard); } From 49c060fdc72d64591f95775a5e651895d67f0918 Mon Sep 17 00:00:00 2001 From: josh <41476440+Joshua-Hwang@users.noreply.github.com> Date: Thu, 6 Oct 2022 23:59:28 +1000 Subject: [PATCH 06/53] fixed other tests --- .../__snapshots__/showConfig.test.ts.snap | 1 + e2e/__tests__/showConfig.test.ts | 3 +- .../src/__tests__/normalize.test.ts | 28 +++++++++++++------ .../logDebugMessages.test.ts.snap | 1 + 4 files changed, 24 insertions(+), 9 deletions(-) diff --git a/e2e/__tests__/__snapshots__/showConfig.test.ts.snap b/e2e/__tests__/__snapshots__/showConfig.test.ts.snap index 5bedd1a8bd54..79a0e38b919b 100644 --- a/e2e/__tests__/__snapshots__/showConfig.test.ts.snap +++ b/e2e/__tests__/__snapshots__/showConfig.test.ts.snap @@ -125,6 +125,7 @@ exports[`--showConfig outputs config info and exits 1`] = ` "projects": [], "rootDir": "<>", "runTestsByPath": false, + "seed": <>, "skipFilter": false, "snapshotFormat": { "escapeString": false, diff --git a/e2e/__tests__/showConfig.test.ts b/e2e/__tests__/showConfig.test.ts index 41570e07e1da..13be5474965d 100644 --- a/e2e/__tests__/showConfig.test.ts +++ b/e2e/__tests__/showConfig.test.ts @@ -37,7 +37,8 @@ test('--showConfig outputs config info and exits', () => { .replace(/"version": "(.+)"/g, '"version": "[version]"') .replace(/"maxWorkers": (\d+)/g, '"maxWorkers": "[maxWorkers]"') .replace(/"\S*show-config-test/gm, '"<>') - .replace(/"\S*\/jest\/packages/gm, '"<>'); + .replace(/"\S*\/jest\/packages/gm, '"<>') + .replace(/"seed": (-?\d+)/g, '"seed": <>'); expect(stdout).toMatchSnapshot(); }); diff --git a/packages/jest-config/src/__tests__/normalize.test.ts b/packages/jest-config/src/__tests__/normalize.test.ts index 4b6f7e7dd41a..629cf498a7c2 100644 --- a/packages/jest-config/src/__tests__/normalize.test.ts +++ b/packages/jest-config/src/__tests__/normalize.test.ts @@ -110,14 +110,12 @@ it('keeps custom ids based on the rootDir', async () => { }); it('minimal config is stable across runs', async () => { - const firstNormalization = await normalize( - {rootDir: '/root/path/foo'}, - {} as Config.Argv, - ); - const secondNormalization = await normalize( - {rootDir: '/root/path/foo'}, - {} as Config.Argv, - ); + const firstNormalization = await normalize({rootDir: '/root/path/foo'}, { + seed: 55555, + } as Config.Argv); + const secondNormalization = await normalize({rootDir: '/root/path/foo'}, { + seed: 55555, + } as Config.Argv); expect(firstNormalization).toEqual(secondNormalization); expect(JSON.stringify(firstNormalization)).toBe( @@ -2080,3 +2078,17 @@ it('parses workerIdleMemoryLimit', async () => { expect(options.workerIdleMemoryLimit).toBe(47185920); }); + +describe('seed', () => { + it('generates seed when not specified', async () => { + const {options} = await normalize({rootDir: '/root/'}, {} as Config.Argv); + expect(options.seed).toEqual(expect.any(Number)); + }); + + it('uses seed specified', async () => { + const {options} = await normalize({rootDir: '/root/'}, { + seed: 4321, + } as Config.Argv); + expect(options.seed).toBe(4321); + }); +}); diff --git a/packages/jest-core/src/lib/__tests__/__snapshots__/logDebugMessages.test.ts.snap b/packages/jest-core/src/lib/__tests__/__snapshots__/logDebugMessages.test.ts.snap index b27bc6754017..663431ffd099 100644 --- a/packages/jest-core/src/lib/__tests__/__snapshots__/logDebugMessages.test.ts.snap +++ b/packages/jest-core/src/lib/__tests__/__snapshots__/logDebugMessages.test.ts.snap @@ -95,6 +95,7 @@ exports[`prints the config object 1`] = ` "reporters": [], "rootDir": "/test_root_dir/", "runTestsByPath": false, + "seed": 1234, "silent": false, "skipFilter": false, "snapshotFormat": {}, From bc8b4eb38e636c002c664c78baa347e16fdd3c6a Mon Sep 17 00:00:00 2001 From: josh <41476440+Joshua-Hwang@users.noreply.github.com> Date: Fri, 7 Oct 2022 00:11:56 +1000 Subject: [PATCH 07/53] improved documentation --- docs/CLI.md | 6 ++++-- docs/JestObjectAPI.md | 8 +++++++- packages/jest-cli/src/cli/args.ts | 2 +- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/docs/CLI.md b/docs/CLI.md index 9439ddb896dc..4828ad01666f 100644 --- a/docs/CLI.md +++ b/docs/CLI.md @@ -352,8 +352,10 @@ The default regex matching works fine on small runs, but becomes slow if provide ### `--seed=` -TODO jhwang make a clearer description -Provide a seed number that the tests have access to via `jest.getSeed()`. +Provides a seed number that the tests have access to via `jest.getSeed()`. +If this option isn't specified Jest will randomly generate a seed. + +The seed value must be between `-0x80000000` to `0x7fffffff` inclusive. ```bash jest --seed=1324 diff --git a/docs/JestObjectAPI.md b/docs/JestObjectAPI.md index f88b95f6a230..5c3b63ad623d 100644 --- a/docs/JestObjectAPI.md +++ b/docs/JestObjectAPI.md @@ -909,7 +909,13 @@ This function is not available when using legacy fake timers implementation. ## Misc ### `jest.getSeed()` -TODO jhwang +Every time Jest runs a seed value is randomly generated which you could use in a pseudorandom number generator or anywhere else. + +:::tip + +You can manually define this value with the CLI argument `--seed=`. + +::: ### `jest.setTimeout(timeout)` diff --git a/packages/jest-cli/src/cli/args.ts b/packages/jest-cli/src/cli/args.ts index c22770d70726..7ca5ec28c66e 100644 --- a/packages/jest-cli/src/cli/args.ts +++ b/packages/jest-cli/src/cli/args.ts @@ -512,7 +512,7 @@ export const options: {[key: string]: Options} = { }, seed: { description: - 'TODO jhwang Specify the seed that will be exposed to tests via jest.getSeed().', + 'Provides a seed number that the tests have access to via jest.getSeed(). If this option is not specified Jest will randomly generate a seed. The seed value must be between -0x80000000 to 0x7fffffff inclusive.', type: 'number', }, selectProjects: { From fecf1064caecd80a455413a56ed26f68258a8c80 Mon Sep 17 00:00:00 2001 From: josh <41476440+Joshua-Hwang@users.noreply.github.com> Date: Fri, 7 Oct 2022 00:21:30 +1000 Subject: [PATCH 08/53] added copyright --- e2e/jest-object/__test__/any-seed.test.js | 7 +++++++ e2e/jest-object/__test__/get-seed.test.js | 1 + 2 files changed, 8 insertions(+) diff --git a/e2e/jest-object/__test__/any-seed.test.js b/e2e/jest-object/__test__/any-seed.test.js index 1100fcfbe47f..89dd98360471 100644 --- a/e2e/jest-object/__test__/any-seed.test.js +++ b/e2e/jest-object/__test__/any-seed.test.js @@ -1,3 +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)); }); diff --git a/e2e/jest-object/__test__/get-seed.test.js b/e2e/jest-object/__test__/get-seed.test.js index 17d2954be64d..97b65af39c5f 100644 --- a/e2e/jest-object/__test__/get-seed.test.js +++ b/e2e/jest-object/__test__/get-seed.test.js @@ -4,6 +4,7 @@ * 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()).toEqual(1234); }); From c39e63f0ae35e61569daf3488de6fa22545c1581 Mon Sep 17 00:00:00 2001 From: josh <41476440+Joshua-Hwang@users.noreply.github.com> Date: Fri, 7 Oct 2022 19:42:47 +1000 Subject: [PATCH 09/53] added replace seed function --- e2e/Utils.ts | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/e2e/Utils.ts b/e2e/Utils.ts index 112f7412b181..56f42f0ce7eb 100644 --- a/e2e/Utils.ts +++ b/e2e/Utils.ts @@ -157,6 +157,9 @@ export const copyDir = (src: string, dest: string) => { } }; +export const replaceSeed = (str: string) => + str.replace(/Seed: (-?\d+)/g, 'Seed: <>'); + export const replaceTime = (str: string) => str .replace(/\d*\.?\d+ m?s\b/g, '<>') @@ -201,7 +204,7 @@ export const extractSummary = (stdout: string) => { const match = stdout .replace(/(?:\\[rn])+/g, '\n') .match( - /Test Suites:.*\nTests.*\nSnapshots.*\nTime.*(\nRan all test suites)*.*\n*$/gm, + /Seed:.*\nTest Suites:.*\nTests.*\nSnapshots.*\nTime.*(\nRan all test suites)*.*\n*$/gm, ); if (!match) { throw new Error(dedent` @@ -211,7 +214,7 @@ export const extractSummary = (stdout: string) => { `); } - const summary = replaceTime(match[0]); + const summary = replaceSeed(replaceTime(match[0])); const rest = stdout .replace(match[0], '') @@ -245,7 +248,7 @@ const sortTests = (stdout: string) => export const extractSortedSummary = (stdout: string) => { const {rest, summary} = extractSummary(stdout); return { - rest: sortTests(replaceTime(rest)), + rest: sortTests(replaceSeed(replaceTime(rest))), summary, }; }; @@ -254,7 +257,7 @@ export const extractSummaries = ( stdout: string, ): Array<{rest: string; summary: string}> => { const regex = - /Test Suites:.*\nTests.*\nSnapshots.*\nTime.*(\nRan all test suites)*.*\n*$/gm; + /Seed:.*\nTest Suites:.*\nTests.*\nSnapshots.*\nTime.*(\nRan all test suites)*.*\n*$/gm; let match = regex.exec(stdout); const matches: Array = []; From 923f556b54a93c0aaa1591dec5bb5c19d22fb31d Mon Sep 17 00:00:00 2001 From: josh <41476440+Joshua-Hwang@users.noreply.github.com> Date: Fri, 7 Oct 2022 19:45:19 +1000 Subject: [PATCH 10/53] added Seed to reporter --- packages/jest-reporters/src/DefaultReporter.ts | 2 +- packages/jest-reporters/src/Status.ts | 3 ++- packages/jest-reporters/src/SummaryReporter.ts | 1 + packages/jest-reporters/src/getSummary.ts | 7 ++++++- packages/jest-reporters/src/types.ts | 1 + 5 files changed, 11 insertions(+), 3 deletions(-) diff --git a/packages/jest-reporters/src/DefaultReporter.ts b/packages/jest-reporters/src/DefaultReporter.ts index c8451b3a9468..1c51ed94bfd0 100644 --- a/packages/jest-reporters/src/DefaultReporter.ts +++ b/packages/jest-reporters/src/DefaultReporter.ts @@ -47,7 +47,7 @@ export default class DefaultReporter extends BaseReporter { this._clear = ''; this._out = process.stdout.write.bind(process.stdout); this._err = process.stderr.write.bind(process.stderr); - this._status = new Status(); + this._status = new Status(globalConfig); this._bufferedOutput = new Set(); this.__wrapStdio(process.stdout); this.__wrapStdio(process.stderr); diff --git a/packages/jest-reporters/src/Status.ts b/packages/jest-reporters/src/Status.ts index f0a993f2eb96..f724dadfd634 100644 --- a/packages/jest-reporters/src/Status.ts +++ b/packages/jest-reporters/src/Status.ts @@ -85,7 +85,7 @@ export default class Status { private _aggregatedResults?: AggregatedResult; private _showStatus: boolean; - constructor() { + constructor(private _globalConfig: Config.GlobalConfig) { this._cache = null; this._currentTests = new CurrentTestList(); this._currentTestCases = []; @@ -185,6 +185,7 @@ export default class Status { estimatedTime: this._estimatedTime, roundTime: true, width, + seed: this._globalConfig.seed, })}`; } diff --git a/packages/jest-reporters/src/SummaryReporter.ts b/packages/jest-reporters/src/SummaryReporter.ts index ea7b8a0b037a..2168121fd579 100644 --- a/packages/jest-reporters/src/SummaryReporter.ts +++ b/packages/jest-reporters/src/SummaryReporter.ts @@ -108,6 +108,7 @@ export default class SummaryReporter extends BaseReporter { if (numTotalTestSuites) { let message = getSummary(aggregatedResults, { + seed: this._globalConfig.seed, estimatedTime: this._estimatedTime, }); diff --git a/packages/jest-reporters/src/getSummary.ts b/packages/jest-reporters/src/getSummary.ts index dbb42c8d0411..c14b17b8f55d 100644 --- a/packages/jest-reporters/src/getSummary.ts +++ b/packages/jest-reporters/src/getSummary.ts @@ -114,6 +114,11 @@ export default function getSummary( const testsTotal = aggregatedResults.numTotalTests; const width = (options && options.width) || 0; + const seed = `${ + chalk.bold('Seed: ') + (options?.seed?.toString() ?? 'XXXX') + }`; + + const suites = `${ chalk.bold('Test Suites: ') + (suitesFailed ? `${chalk.bold.red(`${suitesFailed} failed`)}, ` : '') + @@ -183,5 +188,5 @@ export default function getSummary( }${snapshotsTotal} total`; const time = renderTime(runTime, estimatedTime, width); - return [suites, tests, snapshots, time].join('\n'); + return [seed, suites, tests, snapshots, time].join('\n'); } diff --git a/packages/jest-reporters/src/types.ts b/packages/jest-reporters/src/types.ts index 16567d30fc33..ef9927d649a0 100644 --- a/packages/jest-reporters/src/types.ts +++ b/packages/jest-reporters/src/types.ts @@ -60,4 +60,5 @@ export type SummaryOptions = { estimatedTime?: number; roundTime?: boolean; width?: number; + seed?: number; }; From 07f7b55b0cab157ae177d1a93783349be828882c Mon Sep 17 00:00:00 2001 From: josh <41476440+Joshua-Hwang@users.noreply.github.com> Date: Fri, 7 Oct 2022 19:45:39 +1000 Subject: [PATCH 11/53] fixed some e2e tests for new Seed report --- e2e/__tests__/domDiffing.test.ts | 4 ++-- e2e/__tests__/requireAfterTeardown.test.ts | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/e2e/__tests__/domDiffing.test.ts b/e2e/__tests__/domDiffing.test.ts index b61baff2d6eb..feb0625b724d 100644 --- a/e2e/__tests__/domDiffing.test.ts +++ b/e2e/__tests__/domDiffing.test.ts @@ -6,11 +6,11 @@ * */ -import {replaceTime} from '../Utils'; +import {replaceSeed, replaceTime} from '../Utils'; import runJest from '../runJest'; test('should work without error', () => { const output = runJest('dom-diffing'); expect(output.failed).toBe(true); - expect(replaceTime(output.stderr)).toMatchSnapshot(); + expect(replaceSeed(replaceTime(output.stderr))).toMatchSnapshot(); }); diff --git a/e2e/__tests__/requireAfterTeardown.test.ts b/e2e/__tests__/requireAfterTeardown.test.ts index c7e2b1d3f898..c28b2a20dd44 100644 --- a/e2e/__tests__/requireAfterTeardown.test.ts +++ b/e2e/__tests__/requireAfterTeardown.test.ts @@ -10,10 +10,10 @@ import runJest from '../runJest'; test('prints useful error for requires after test is done', () => { const {stderr} = runJest('require-after-teardown'); - const interestingLines = stderr.split('\n').slice(9, 18).join('\n'); + const interestingLines = stderr.split('\n').slice(10, 19).join('\n'); expect(interestingLines).toMatchSnapshot(); - expect(stderr.split('\n')[19]).toMatch( + expect(stderr.split('\n')[20]).toMatch( new RegExp('(__tests__/lateRequire.test.js:11:20)'), ); }); From 3987577976942e04f90354f2f52b11f7948a3024 Mon Sep 17 00:00:00 2001 From: josh <41476440+Joshua-Hwang@users.noreply.github.com> Date: Fri, 7 Oct 2022 19:57:56 +1000 Subject: [PATCH 12/53] updated line number of e2e test --- e2e/__tests__/environmentAfterTeardown.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/e2e/__tests__/environmentAfterTeardown.test.ts b/e2e/__tests__/environmentAfterTeardown.test.ts index 103e33d1d43c..e0b8e10b871b 100644 --- a/e2e/__tests__/environmentAfterTeardown.test.ts +++ b/e2e/__tests__/environmentAfterTeardown.test.ts @@ -12,7 +12,7 @@ test('prints useful error for environment methods after test is done', () => { const interestingLines = stderr.split('\n').slice(9, 18).join('\n'); expect(interestingLines).toMatchSnapshot(); - expect(stderr.split('\n')[9]).toBe( + expect(stderr.split('\n')[10]).toBe( 'ReferenceError: You are trying to access a property or method of the Jest environment after it has been torn down. From __tests__/afterTeardown.test.js.', ); }); From dda334e6f0ce7a2c3e15a23b92d6c09d70f80761 Mon Sep 17 00:00:00 2001 From: josh <41476440+Joshua-Hwang@users.noreply.github.com> Date: Fri, 7 Oct 2022 20:01:04 +1000 Subject: [PATCH 13/53] updated snapshots --- .../cliHandlesExactFilenames.test.ts.snap | 3 +- .../__snapshots__/console.test.ts.snap | 21 +++++--- .../consoleDebugging.test.ts.snap | 3 +- ...consoleLogOutputWhenRunInBand.test.ts.snap | 3 +- .../__snapshots__/coverageReport.test.ts.snap | 3 +- .../coverageThreshold.test.ts.snap | 12 +++-- .../customReporters.test.ts.snap | 3 +- .../__snapshots__/domDiffing.test.ts.snap | 1 + .../emptyDescribeWithHooks.test.ts.snap | 12 +++-- .../findRelatedFiles.test.ts.snap | 9 ++-- .../__snapshots__/globals.test.ts.snap | 33 ++++++++---- .../__snapshots__/injectGlobals.test.ts.snap | 6 ++- .../__snapshots__/jest.config.js.test.ts.snap | 6 ++- .../__snapshots__/jest.config.ts.test.ts.snap | 9 ++-- .../multiProjectRunner.test.ts.snap | 9 ++-- .../__snapshots__/nativeEsm.test.ts.snap | 9 ++-- .../__snapshots__/resolveAsync.test.ts.snap | 3 +- ...grammaticallyMultipleProjects.test.ts.snap | 3 +- .../__snapshots__/snapshot.test.ts.snap | 51 ++++++++++++------- .../__snapshots__/snapshotMockFs.test.ts.snap | 3 +- .../__snapshots__/stackTrace.test.ts.snap | 21 +++++--- .../__snapshots__/testMatch.test.ts.snap | 3 +- .../testNamePattern.test.ts.snap | 3 +- .../testNamePatternSkipped.test.ts.snap | 3 +- .../__snapshots__/timeouts.test.ts.snap | 12 +++-- .../watchModeOnlyFailed.test.ts.snap | 6 ++- .../watchModePatterns.test.ts.snap | 12 +++-- .../watchModeUpdateSnapshot.test.ts.snap | 6 ++- .../workerRestarting.test.ts.snap | 3 +- .../environmentAfterTeardown.test.ts | 2 +- 30 files changed, 182 insertions(+), 91 deletions(-) diff --git a/e2e/__tests__/__snapshots__/cliHandlesExactFilenames.test.ts.snap b/e2e/__tests__/__snapshots__/cliHandlesExactFilenames.test.ts.snap index 4eb172dc686b..ba6d7d8e2bb4 100644 --- a/e2e/__tests__/__snapshots__/cliHandlesExactFilenames.test.ts.snap +++ b/e2e/__tests__/__snapshots__/cliHandlesExactFilenames.test.ts.snap @@ -9,7 +9,8 @@ Force exiting Jest: Have you considered using \`--detectOpenHandles\` to detect `; exports[`CLI accepts exact file names if matchers matched 2`] = ` -"Test Suites: 1 passed, 1 total +"Seed: <> +Test Suites: 1 passed, 1 total Tests: 1 passed, 1 total Snapshots: 0 total Time: <> diff --git a/e2e/__tests__/__snapshots__/console.test.ts.snap b/e2e/__tests__/__snapshots__/console.test.ts.snap index 849933bd86c4..dc629daa255a 100644 --- a/e2e/__tests__/__snapshots__/console.test.ts.snap +++ b/e2e/__tests__/__snapshots__/console.test.ts.snap @@ -41,7 +41,8 @@ exports[`console printing 1`] = ` `; exports[`console printing 2`] = ` -"Test Suites: 1 passed, 1 total +"Seed: <> +Test Suites: 1 passed, 1 total Tests: 1 passed, 1 total Snapshots: 0 total Time: <> @@ -92,7 +93,8 @@ exports[`console printing with --verbose 2`] = ` `; exports[`console printing with --verbose 3`] = ` -"Test Suites: 1 passed, 1 total +"Seed: <> +Test Suites: 1 passed, 1 total Tests: 1 passed, 1 total Snapshots: 0 total Time: <> @@ -127,7 +129,8 @@ exports[`does not error out when using winston 2`] = ` `; exports[`does not error out when using winston 3`] = ` -"Test Suites: 1 passed, 1 total +"Seed: <> +Test Suites: 1 passed, 1 total Tests: 1 passed, 1 total Snapshots: 0 total Time: <> @@ -139,7 +142,8 @@ exports[`does not print to console with --silent 1`] = `""`; exports[`does not print to console with --silent 2`] = `"PASS __tests__/console.test.js"`; exports[`does not print to console with --silent 3`] = ` -"Test Suites: 1 passed, 1 total +"Seed: <> +Test Suites: 1 passed, 1 total Tests: 1 passed, 1 total Snapshots: 0 total Time: <>" @@ -174,7 +178,8 @@ exports[`respects --noStackTrace 2`] = ` `; exports[`respects --noStackTrace 3`] = ` -"Test Suites: 1 passed, 1 total +"Seed: <> +Test Suites: 1 passed, 1 total Tests: 1 passed, 1 total Snapshots: 0 total Time: <> @@ -210,7 +215,8 @@ exports[`respects noStackTrace in config 2`] = ` `; exports[`respects noStackTrace in config 3`] = ` -"Test Suites: 1 passed, 1 total +"Seed: <> +Test Suites: 1 passed, 1 total Tests: 1 passed, 1 total Snapshots: 0 total Time: <> @@ -225,7 +231,8 @@ exports[`the jsdom console is the same as the test console 2`] = ` `; exports[`the jsdom console is the same as the test console 3`] = ` -"Test Suites: 1 passed, 1 total +"Seed: <> +Test Suites: 1 passed, 1 total Tests: 1 passed, 1 total Snapshots: 0 total Time: <> diff --git a/e2e/__tests__/__snapshots__/consoleDebugging.test.ts.snap b/e2e/__tests__/__snapshots__/consoleDebugging.test.ts.snap index 4bc14067c0cf..1a0bf9db5b60 100644 --- a/e2e/__tests__/__snapshots__/consoleDebugging.test.ts.snap +++ b/e2e/__tests__/__snapshots__/consoleDebugging.test.ts.snap @@ -14,7 +14,8 @@ exports[`console debugging with --verbose 2`] = ` `; exports[`console debugging with --verbose 3`] = ` -"Test Suites: 1 passed, 1 total +"Seed: <> +Test Suites: 1 passed, 1 total Tests: 1 passed, 1 total Snapshots: 1 passed, 1 total Time: <> diff --git a/e2e/__tests__/__snapshots__/consoleLogOutputWhenRunInBand.test.ts.snap b/e2e/__tests__/__snapshots__/consoleLogOutputWhenRunInBand.test.ts.snap index e092acb545d1..2d0ab2f2a0cc 100644 --- a/e2e/__tests__/__snapshots__/consoleLogOutputWhenRunInBand.test.ts.snap +++ b/e2e/__tests__/__snapshots__/consoleLogOutputWhenRunInBand.test.ts.snap @@ -9,7 +9,8 @@ Force exiting Jest: Have you considered using \`--detectOpenHandles\` to detect `; exports[`prints console.logs when run with forceExit 2`] = ` -"Test Suites: 1 passed, 1 total +"Seed: <> +Test Suites: 1 passed, 1 total Tests: 1 passed, 1 total Snapshots: 0 total Time: <> diff --git a/e2e/__tests__/__snapshots__/coverageReport.test.ts.snap b/e2e/__tests__/__snapshots__/coverageReport.test.ts.snap index bf48e0520423..f13878bac359 100644 --- a/e2e/__tests__/__snapshots__/coverageReport.test.ts.snap +++ b/e2e/__tests__/__snapshots__/coverageReport.test.ts.snap @@ -61,7 +61,8 @@ All files | 60 | 0 | 50 | 60 | `; exports[`json reporter printing with --coverage 1`] = ` -"Test Suites: 1 failed, 1 total +"Seed: <> +Test Suites: 1 failed, 1 total Tests: 1 failed, 1 skipped, 2 passed, 4 total Snapshots: 0 total Time: <> diff --git a/e2e/__tests__/__snapshots__/coverageThreshold.test.ts.snap b/e2e/__tests__/__snapshots__/coverageThreshold.test.ts.snap index 0fe03e7e827b..8d0581625776 100644 --- a/e2e/__tests__/__snapshots__/coverageThreshold.test.ts.snap +++ b/e2e/__tests__/__snapshots__/coverageThreshold.test.ts.snap @@ -8,7 +8,8 @@ Jest: "global" coverage threshold for lines (100%) not met: 0%" `; exports[`excludes tests matched by path threshold groups from global group 2`] = ` -"Test Suites: 1 passed, 1 total +"Seed: <> +Test Suites: 1 passed, 1 total Tests: 1 passed, 1 total Snapshots: 0 total Time: <> @@ -42,7 +43,8 @@ Jest: "global" coverage threshold for lines (90%) not met: 50%" `; exports[`exits with 1 if coverage threshold is not met 2`] = ` -"Test Suites: 1 passed, 1 total +"Seed: <> +Test Suites: 1 passed, 1 total Tests: 1 passed, 1 total Snapshots: 0 total Time: <> @@ -66,7 +68,8 @@ Jest: Coverage data for apple.js was not found." `; exports[`exits with 1 if path threshold group is not found in coverage data 2`] = ` -"Test Suites: 1 passed, 1 total +"Seed: <> +Test Suites: 1 passed, 1 total Tests: 1 passed, 1 total Snapshots: 0 total Time: <> @@ -92,7 +95,8 @@ Jest: "./banana.js" coverage threshold for lines (100%) not met: 50%" `; exports[`file is matched by all path and glob threshold groups 2`] = ` -"Test Suites: 1 passed, 1 total +"Seed: <> +Test Suites: 1 passed, 1 total Tests: 1 passed, 1 total Snapshots: 0 total Time: <> diff --git a/e2e/__tests__/__snapshots__/customReporters.test.ts.snap b/e2e/__tests__/__snapshots__/customReporters.test.ts.snap index 7506630b07d2..0493a07f8801 100644 --- a/e2e/__tests__/__snapshots__/customReporters.test.ts.snap +++ b/e2e/__tests__/__snapshots__/customReporters.test.ts.snap @@ -78,7 +78,8 @@ exports[`Custom Reporters Integration default reporters enabled 1`] = ` `; exports[`Custom Reporters Integration default reporters enabled 2`] = ` -"Test Suites: 1 passed, 1 total +"Seed: <> +Test Suites: 1 passed, 1 total Tests: 1 passed, 1 total Snapshots: 0 total Time: <> diff --git a/e2e/__tests__/__snapshots__/domDiffing.test.ts.snap b/e2e/__tests__/__snapshots__/domDiffing.test.ts.snap index d137c76c46ae..3f81fa9af30c 100644 --- a/e2e/__tests__/__snapshots__/domDiffing.test.ts.snap +++ b/e2e/__tests__/__snapshots__/domDiffing.test.ts.snap @@ -43,6 +43,7 @@ exports[`should work without error 1`] = ` at Object.toBe (__tests__/dom.test.js:18:41) +Seed: <> Test Suites: 1 failed, 1 total Tests: 2 failed, 2 total Snapshots: 0 total diff --git a/e2e/__tests__/__snapshots__/emptyDescribeWithHooks.test.ts.snap b/e2e/__tests__/__snapshots__/emptyDescribeWithHooks.test.ts.snap index ad2f6318c6ed..bc8fb3efedca 100644 --- a/e2e/__tests__/__snapshots__/emptyDescribeWithHooks.test.ts.snap +++ b/e2e/__tests__/__snapshots__/emptyDescribeWithHooks.test.ts.snap @@ -3,7 +3,8 @@ exports[`hook in describe with skipped test 1`] = ` Object { "rest": "", - "summary": "Test Suites: 1 skipped, 0 of 1 total + "summary": "Seed: <> +Test Suites: 1 skipped, 0 of 1 total Tests: 1 skipped, 1 total Snapshots: 0 total Time: <> @@ -30,7 +31,8 @@ Object { at beforeEach (__tests__/hookInEmptyDescribe.test.js:9:3) at Object.describe (__tests__/hookInEmptyDescribe.test.js:8:1)", - "summary": "Test Suites: 1 failed, 1 total + "summary": "Seed: <> +Test Suites: 1 failed, 1 total Tests: 1 passed, 1 total Snapshots: 0 total Time: <> @@ -57,7 +59,8 @@ Object { at beforeEach (__tests__/hookInEmptyNestedDescribe.test.js:9:3) at Object.describe (__tests__/hookInEmptyNestedDescribe.test.js:8:1)", - "summary": "Test Suites: 1 failed, 1 total + "summary": "Seed: <> +Test Suites: 1 failed, 1 total Tests: 1 passed, 1 total Snapshots: 0 total Time: <> @@ -129,7 +132,8 @@ Object { at beforeAll (__tests__/multipleHooksInEmptyDescribe.test.js:12:3) at Object.describe (__tests__/multipleHooksInEmptyDescribe.test.js:8:1)", - "summary": "Test Suites: 1 failed, 1 total + "summary": "Seed: <> +Test Suites: 1 failed, 1 total Tests: 1 passed, 1 total Snapshots: 0 total Time: <> diff --git a/e2e/__tests__/__snapshots__/findRelatedFiles.test.ts.snap b/e2e/__tests__/__snapshots__/findRelatedFiles.test.ts.snap index d21e158b8bf1..9ce6ddab28a7 100644 --- a/e2e/__tests__/__snapshots__/findRelatedFiles.test.ts.snap +++ b/e2e/__tests__/__snapshots__/findRelatedFiles.test.ts.snap @@ -1,7 +1,8 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP exports[`--findRelatedTests flag coverage configuration is applied correctly 1`] = ` -"Test Suites: 1 passed, 1 total +"Seed: <> +Test Suites: 1 passed, 1 total Tests: 1 passed, 1 total Snapshots: 0 total Time: <> @@ -23,7 +24,8 @@ All files | 100 | 100 | 100 | 100 | `; exports[`--findRelatedTests flag generates coverage report for filename 1`] = ` -"Test Suites: 2 passed, 2 total +"Seed: <> +Test Suites: 2 passed, 2 total Tests: 2 passed, 2 total Snapshots: 0 total Time: <> @@ -46,7 +48,8 @@ All files | 100 | 100 | 100 | 100 | `; exports[`--findRelatedTests flag generates coverage report for filename 4`] = ` -"Test Suites: 1 passed, 1 total +"Seed: <> +Test Suites: 1 passed, 1 total Tests: 1 passed, 1 total Snapshots: 0 total Time: <> diff --git a/e2e/__tests__/__snapshots__/globals.test.ts.snap b/e2e/__tests__/__snapshots__/globals.test.ts.snap index 47e0dd3db70d..de691f9a2c6e 100644 --- a/e2e/__tests__/__snapshots__/globals.test.ts.snap +++ b/e2e/__tests__/__snapshots__/globals.test.ts.snap @@ -10,7 +10,8 @@ exports[`basic test constructs 1`] = ` `; exports[`basic test constructs 2`] = ` -"Test Suites: 1 passed, 1 total +"Seed: <> +Test Suites: 1 passed, 1 total Tests: 4 passed, 4 total Snapshots: 0 total Time: <> @@ -30,7 +31,8 @@ exports[`cannot have describe with no implementation 1`] = ` `; exports[`cannot have describe with no implementation 2`] = ` -"Test Suites: 1 failed, 1 total +"Seed: <> +Test Suites: 1 failed, 1 total Tests: 0 total Snapshots: 0 total Time: <> @@ -52,7 +54,8 @@ exports[`cannot test with no implementation 1`] = ` `; exports[`cannot test with no implementation 2`] = ` -"Test Suites: 1 failed, 1 total +"Seed: <> +Test Suites: 1 failed, 1 total Tests: 0 total Snapshots: 0 total Time: <> @@ -74,7 +77,8 @@ exports[`cannot test with no implementation with expand arg 1`] = ` `; exports[`cannot test with no implementation with expand arg 2`] = ` -"Test Suites: 1 failed, 1 total +"Seed: <> +Test Suites: 1 failed, 1 total Tests: 0 total Snapshots: 0 total Time: <> @@ -88,7 +92,8 @@ exports[`function as describe() descriptor 1`] = ` `; exports[`function as describe() descriptor 2`] = ` -"Test Suites: 1 passed, 1 total +"Seed: <> +Test Suites: 1 passed, 1 total Tests: 1 passed, 1 total Snapshots: 0 total Time: <> @@ -101,7 +106,8 @@ exports[`function as it() descriptor 1`] = ` `; exports[`function as it() descriptor 2`] = ` -"Test Suites: 1 passed, 1 total +"Seed: <> +Test Suites: 1 passed, 1 total Tests: 1 passed, 1 total Snapshots: 0 total Time: <> @@ -117,7 +123,8 @@ exports[`interleaved describe and test children order 1`] = ` `; exports[`interleaved describe and test children order 2`] = ` -"Test Suites: 1 passed, 1 total +"Seed: <> +Test Suites: 1 passed, 1 total Tests: 3 passed, 3 total Snapshots: 0 total Time: <> @@ -140,7 +147,8 @@ exports[`only 1`] = ` `; exports[`only 2`] = ` -"Test Suites: 1 passed, 1 total +"Seed: <> +Test Suites: 1 passed, 1 total Tests: 1 skipped, 7 passed, 8 total Snapshots: 0 total Time: <> @@ -163,7 +171,8 @@ exports[`only with expand arg 1`] = ` `; exports[`only with expand arg 2`] = ` -"Test Suites: 1 passed, 1 total +"Seed: <> +Test Suites: 1 passed, 1 total Tests: 1 skipped, 7 passed, 8 total Snapshots: 0 total Time: <> @@ -187,7 +196,8 @@ exports[`skips 1`] = ` `; exports[`skips 2`] = ` -"Test Suites: 1 passed, 1 total +"Seed: <> +Test Suites: 1 passed, 1 total Tests: 8 skipped, 1 passed, 9 total Snapshots: 0 total Time: <> @@ -211,7 +221,8 @@ exports[`skips with expand arg 1`] = ` `; exports[`skips with expand arg 2`] = ` -"Test Suites: 1 passed, 1 total +"Seed: <> +Test Suites: 1 passed, 1 total Tests: 8 skipped, 1 passed, 9 total Snapshots: 0 total Time: <> diff --git a/e2e/__tests__/__snapshots__/injectGlobals.test.ts.snap b/e2e/__tests__/__snapshots__/injectGlobals.test.ts.snap index 74c718ed91b9..de97464b6e34 100644 --- a/e2e/__tests__/__snapshots__/injectGlobals.test.ts.snap +++ b/e2e/__tests__/__snapshots__/injectGlobals.test.ts.snap @@ -6,7 +6,8 @@ exports[`globals are undefined if passed \`false\` from CLI 1`] = ` `; exports[`globals are undefined if passed \`false\` from CLI 2`] = ` -"Test Suites: 1 passed, 1 total +"Seed: <> +Test Suites: 1 passed, 1 total Tests: 1 passed, 1 total Snapshots: 0 total Time: <> @@ -19,7 +20,8 @@ exports[`globals are undefined if passed \`false\` from config 1`] = ` `; exports[`globals are undefined if passed \`false\` from config 2`] = ` -"Test Suites: 1 passed, 1 total +"Seed: <> +Test Suites: 1 passed, 1 total Tests: 1 passed, 1 total Snapshots: 0 total Time: <> diff --git a/e2e/__tests__/__snapshots__/jest.config.js.test.ts.snap b/e2e/__tests__/__snapshots__/jest.config.js.test.ts.snap index 45f2b0bcb85b..9b74d9e719f4 100644 --- a/e2e/__tests__/__snapshots__/jest.config.js.test.ts.snap +++ b/e2e/__tests__/__snapshots__/jest.config.js.test.ts.snap @@ -15,7 +15,8 @@ exports[`traverses directory tree up until it finds jest.config 2`] = ` `; exports[`traverses directory tree up until it finds jest.config 3`] = ` -"Test Suites: 1 passed, 1 total +"Seed: <> +Test Suites: 1 passed, 1 total Tests: 2 passed, 2 total Snapshots: 0 total Time: <> @@ -28,7 +29,8 @@ exports[`works with jest.config.js 1`] = ` `; exports[`works with jest.config.js 2`] = ` -"Test Suites: 1 passed, 1 total +"Seed: <> +Test Suites: 1 passed, 1 total Tests: 1 passed, 1 total Snapshots: 0 total Time: <> diff --git a/e2e/__tests__/__snapshots__/jest.config.ts.test.ts.snap b/e2e/__tests__/__snapshots__/jest.config.ts.test.ts.snap index 7ecbcfe06551..8215365a75ba 100644 --- a/e2e/__tests__/__snapshots__/jest.config.ts.test.ts.snap +++ b/e2e/__tests__/__snapshots__/jest.config.ts.test.ts.snap @@ -15,7 +15,8 @@ exports[`traverses directory tree up until it finds jest.config 2`] = ` `; exports[`traverses directory tree up until it finds jest.config 3`] = ` -"Test Suites: 1 passed, 1 total +"Seed: <> +Test Suites: 1 passed, 1 total Tests: 2 passed, 2 total Snapshots: 0 total Time: <> @@ -28,7 +29,8 @@ exports[`works with jest.config.ts 1`] = ` `; exports[`works with jest.config.ts 2`] = ` -"Test Suites: 1 passed, 1 total +"Seed: <> +Test Suites: 1 passed, 1 total Tests: 1 passed, 1 total Snapshots: 0 total Time: <> @@ -41,7 +43,8 @@ exports[`works with tsconfig.json 1`] = ` `; exports[`works with tsconfig.json 2`] = ` -"Test Suites: 1 passed, 1 total +"Seed: <> +Test Suites: 1 passed, 1 total Tests: 1 passed, 1 total Snapshots: 0 total Time: <> diff --git a/e2e/__tests__/__snapshots__/multiProjectRunner.test.ts.snap b/e2e/__tests__/__snapshots__/multiProjectRunner.test.ts.snap index bf72a9f9bf37..1869d98a1d60 100644 --- a/e2e/__tests__/__snapshots__/multiProjectRunner.test.ts.snap +++ b/e2e/__tests__/__snapshots__/multiProjectRunner.test.ts.snap @@ -1,7 +1,8 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP exports[`can pass projects or global config 1`] = ` -"Test Suites: 3 failed, 3 total +"Seed: <> +Test Suites: 3 failed, 3 total Tests: 0 total Snapshots: 0 total Time: <> @@ -9,7 +10,8 @@ Ran all test suites." `; exports[`can pass projects or global config 2`] = ` -"Test Suites: 3 passed, 3 total +"Seed: <> +Test Suites: 3 passed, 3 total Tests: 3 passed, 3 total Snapshots: 0 total Time: <> @@ -23,7 +25,8 @@ PASS project2/__tests__/file1.test.js" `; exports[`can pass projects or global config 4`] = ` -"Test Suites: 3 passed, 3 total +"Seed: <> +Test Suites: 3 passed, 3 total Tests: 3 passed, 3 total Snapshots: 0 total Time: <> diff --git a/e2e/__tests__/__snapshots__/nativeEsm.test.ts.snap b/e2e/__tests__/__snapshots__/nativeEsm.test.ts.snap index 4324b26d16c4..a27baaf86790 100644 --- a/e2e/__tests__/__snapshots__/nativeEsm.test.ts.snap +++ b/e2e/__tests__/__snapshots__/nativeEsm.test.ts.snap @@ -1,7 +1,8 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP exports[`on node >=16.9.0 support re-exports from CJS of dual packages 1`] = ` -"Test Suites: 1 passed, 1 total +"Seed: <> +Test Suites: 1 passed, 1 total Tests: 1 passed, 1 total Snapshots: 0 total Time: <> @@ -9,7 +10,8 @@ Ran all test suites matching /native-esm-deep-cjs-reexport.test.js/i." `; exports[`runs test with native ESM 1`] = ` -"Test Suites: 1 passed, 1 total +"Seed: <> +Test Suites: 1 passed, 1 total Tests: 34 passed, 34 total Snapshots: 0 total Time: <> @@ -17,7 +19,8 @@ Ran all test suites matching /native-esm.test.js/i." `; exports[`supports top-level await 1`] = ` -"Test Suites: 1 passed, 1 total +"Seed: <> +Test Suites: 1 passed, 1 total Tests: 1 passed, 1 total Snapshots: 0 total Time: <> diff --git a/e2e/__tests__/__snapshots__/resolveAsync.test.ts.snap b/e2e/__tests__/__snapshots__/resolveAsync.test.ts.snap index edfad21176f6..4ff7a15cc8fe 100644 --- a/e2e/__tests__/__snapshots__/resolveAsync.test.ts.snap +++ b/e2e/__tests__/__snapshots__/resolveAsync.test.ts.snap @@ -1,7 +1,8 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP exports[`runs test with native ESM 1`] = ` -"Test Suites: 1 passed, 1 total +"Seed: <> +Test Suites: 1 passed, 1 total Tests: 1 passed, 1 total Snapshots: 0 total Time: <> diff --git a/e2e/__tests__/__snapshots__/runProgrammaticallyMultipleProjects.test.ts.snap b/e2e/__tests__/__snapshots__/runProgrammaticallyMultipleProjects.test.ts.snap index 9ffad72f23c0..3a9b9104e9f1 100644 --- a/e2e/__tests__/__snapshots__/runProgrammaticallyMultipleProjects.test.ts.snap +++ b/e2e/__tests__/__snapshots__/runProgrammaticallyMultipleProjects.test.ts.snap @@ -1,7 +1,8 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP exports[`run programmatically with multiple projects: summary 1`] = ` -"Test Suites: 2 passed, 2 total +"Seed: <> +Test Suites: 2 passed, 2 total Tests: 2 passed, 2 total Snapshots: 0 total Time: <> diff --git a/e2e/__tests__/__snapshots__/snapshot.test.ts.snap b/e2e/__tests__/__snapshots__/snapshot.test.ts.snap index 811a7727b08a..b39b6df99b45 100644 --- a/e2e/__tests__/__snapshots__/snapshot.test.ts.snap +++ b/e2e/__tests__/__snapshots__/snapshot.test.ts.snap @@ -1,7 +1,8 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP exports[`Snapshot Validation deletes a snapshot when a test does removes all the snapshots 1`] = ` -"Test Suites: 3 passed, 3 total +"Seed: <> +Test Suites: 3 passed, 3 total Tests: 9 passed, 9 total Snapshots: 9 written, 9 total Time: <> @@ -9,7 +10,8 @@ Ran all test suites." `; exports[`Snapshot Validation deletes a snapshot when a test does removes all the snapshots 2`] = ` -"Test Suites: 3 passed, 3 total +"Seed: <> +Test Suites: 3 passed, 3 total Tests: 6 passed, 6 total Snapshots: 1 file removed, 5 passed, 5 total Time: <> @@ -17,7 +19,8 @@ Ran all test suites." `; exports[`Snapshot Validation deletes the snapshot if the test suite has been removed 1`] = ` -"Test Suites: 3 passed, 3 total +"Seed: <> +Test Suites: 3 passed, 3 total Tests: 9 passed, 9 total Snapshots: 9 written, 9 total Time: <> @@ -25,7 +28,8 @@ Ran all test suites." `; exports[`Snapshot Validation deletes the snapshot if the test suite has been removed 2`] = ` -"Test Suites: 2 passed, 2 total +"Seed: <> +Test Suites: 2 passed, 2 total Tests: 5 passed, 5 total Snapshots: 1 file removed, 5 passed, 5 total Time: <> @@ -33,7 +37,8 @@ Ran all test suites." `; exports[`Snapshot Validation does not save snapshots in CI mode by default 1`] = ` -"Test Suites: 3 failed, 3 total +"Seed: <> +Test Suites: 3 failed, 3 total Tests: 7 failed, 2 passed, 9 total Snapshots: 9 failed, 9 total Time: <> @@ -41,7 +46,8 @@ Ran all test suites." `; exports[`Snapshot Validation updates the snapshot when a test removes some snapshots 1`] = ` -"Test Suites: 3 passed, 3 total +"Seed: <> +Test Suites: 3 passed, 3 total Tests: 9 passed, 9 total Snapshots: 9 written, 9 total Time: <> @@ -49,7 +55,8 @@ Ran all test suites." `; exports[`Snapshot Validation updates the snapshot when a test removes some snapshots 2`] = ` -"Test Suites: 3 passed, 3 total +"Seed: <> +Test Suites: 3 passed, 3 total Tests: 9 passed, 9 total Snapshots: 1 removed, 1 updated, 7 passed, 8 total Time: <> @@ -57,7 +64,8 @@ Ran all test suites." `; exports[`Snapshot Validation works on subsequent runs without \`-u\` 1`] = ` -"Test Suites: 3 passed, 3 total +"Seed: <> +Test Suites: 3 passed, 3 total Tests: 9 passed, 9 total Snapshots: 9 written, 9 total Time: <> @@ -65,7 +73,8 @@ Ran all test suites." `; exports[`Snapshot Validation works on subsequent runs without \`-u\` 2`] = ` -"Test Suites: 3 passed, 3 total +"Seed: <> +Test Suites: 3 passed, 3 total Tests: 9 passed, 9 total Snapshots: 9 passed, 9 total Time: <> @@ -73,7 +82,8 @@ Ran all test suites." `; exports[`Snapshot stores new snapshots on the first run 1`] = ` -"Test Suites: 2 passed, 2 total +"Seed: <> +Test Suites: 2 passed, 2 total Tests: 5 passed, 5 total Snapshots: 5 written, 5 total Time: <> @@ -81,7 +91,8 @@ Ran all test suites." `; exports[`Snapshot works with escaped characters 1`] = ` -"Test Suites: 1 passed, 1 total +"Seed: <> +Test Suites: 1 passed, 1 total Tests: 1 passed, 1 total Snapshots: 1 written, 1 total Time: <> @@ -89,7 +100,8 @@ Ran all test suites matching /snapshot.test.js/i." `; exports[`Snapshot works with escaped characters 2`] = ` -"Test Suites: 1 passed, 1 total +"Seed: <> +Test Suites: 1 passed, 1 total Tests: 2 passed, 2 total Snapshots: 1 written, 1 passed, 2 total Time: <> @@ -97,7 +109,8 @@ Ran all test suites matching /snapshot.test.js/i." `; exports[`Snapshot works with escaped characters 3`] = ` -"Test Suites: 1 passed, 1 total +"Seed: <> +Test Suites: 1 passed, 1 total Tests: 2 passed, 2 total Snapshots: 2 passed, 2 total Time: <> @@ -105,7 +118,8 @@ Ran all test suites matching /snapshot.test.js/i." `; exports[`Snapshot works with escaped regex 1`] = ` -"Test Suites: 1 passed, 1 total +"Seed: <> +Test Suites: 1 passed, 1 total Tests: 2 passed, 2 total Snapshots: 2 written, 2 total Time: <> @@ -113,7 +127,8 @@ Ran all test suites matching /snapshotEscapeRegex.js/i." `; exports[`Snapshot works with escaped regex 2`] = ` -"Test Suites: 1 passed, 1 total +"Seed: <> +Test Suites: 1 passed, 1 total Tests: 2 passed, 2 total Snapshots: 2 passed, 2 total Time: <> @@ -121,7 +136,8 @@ Ran all test suites matching /snapshotEscapeRegex.js/i." `; exports[`Snapshot works with template literal substitutions 1`] = ` -"Test Suites: 1 passed, 1 total +"Seed: <> +Test Suites: 1 passed, 1 total Tests: 1 passed, 1 total Snapshots: 1 written, 1 total Time: <> @@ -129,7 +145,8 @@ Ran all test suites matching /snapshotEscapeSubstitution.test.js/i." `; exports[`Snapshot works with template literal substitutions 2`] = ` -"Test Suites: 1 passed, 1 total +"Seed: <> +Test Suites: 1 passed, 1 total Tests: 1 passed, 1 total Snapshots: 1 passed, 1 total Time: <> diff --git a/e2e/__tests__/__snapshots__/snapshotMockFs.test.ts.snap b/e2e/__tests__/__snapshots__/snapshotMockFs.test.ts.snap index 0b187ca45889..277014715d3a 100644 --- a/e2e/__tests__/__snapshots__/snapshotMockFs.test.ts.snap +++ b/e2e/__tests__/__snapshots__/snapshotMockFs.test.ts.snap @@ -1,7 +1,8 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP exports[`store snapshot even if fs is mocked 1`] = ` -"Test Suites: 1 passed, 1 total +"Seed: <> +Test Suites: 1 passed, 1 total Tests: 1 passed, 1 total Snapshots: 1 written, 1 total Time: <> diff --git a/e2e/__tests__/__snapshots__/stackTrace.test.ts.snap b/e2e/__tests__/__snapshots__/stackTrace.test.ts.snap index e06101e24809..351c1252a41e 100644 --- a/e2e/__tests__/__snapshots__/stackTrace.test.ts.snap +++ b/e2e/__tests__/__snapshots__/stackTrace.test.ts.snap @@ -1,7 +1,8 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP exports[`Stack Trace does not print a stack trace for errors when --noStackTrace is given 1`] = ` -"Test Suites: 1 failed, 1 total +"Seed: <> +Test Suites: 1 failed, 1 total Tests: 3 failed, 3 total Snapshots: 0 total Time: <> @@ -9,7 +10,8 @@ Ran all test suites matching /testError.test.js/i." `; exports[`Stack Trace does not print a stack trace for matching errors when --noStackTrace is given 1`] = ` -"Test Suites: 1 failed, 1 total +"Seed: <> +Test Suites: 1 failed, 1 total Tests: 1 failed, 1 total Snapshots: 0 total Time: <> @@ -17,7 +19,8 @@ Ran all test suites matching /stackTrace.test.js/i." `; exports[`Stack Trace does not print a stack trace for runtime errors when --noStackTrace is given 1`] = ` -"Test Suites: 1 failed, 1 total +"Seed: <> +Test Suites: 1 failed, 1 total Tests: 0 total Snapshots: 0 total Time: <> @@ -25,7 +28,8 @@ Ran all test suites matching /runtimeError.test.js/i." `; exports[`Stack Trace prints a stack trace for errors 1`] = ` -"Test Suites: 1 failed, 1 total +"Seed: <> +Test Suites: 1 failed, 1 total Tests: 3 failed, 3 total Snapshots: 0 total Time: <> @@ -33,7 +37,8 @@ Ran all test suites matching /testError.test.js/i." `; exports[`Stack Trace prints a stack trace for errors without message in stack trace 1`] = ` -"Test Suites: 1 failed, 1 total +"Seed: <> +Test Suites: 1 failed, 1 total Tests: 1 failed, 1 total Snapshots: 0 total Time: <> @@ -41,7 +46,8 @@ Ran all test suites matching /stackTraceWithoutMessage.test.js/i." `; exports[`Stack Trace prints a stack trace for matching errors 1`] = ` -"Test Suites: 1 failed, 1 total +"Seed: <> +Test Suites: 1 failed, 1 total Tests: 1 failed, 1 total Snapshots: 0 total Time: <> @@ -49,7 +55,8 @@ Ran all test suites matching /stackTrace.test.js/i." `; exports[`Stack Trace prints a stack trace for runtime errors 1`] = ` -"Test Suites: 1 failed, 1 total +"Seed: <> +Test Suites: 1 failed, 1 total Tests: 0 total Snapshots: 0 total Time: <> diff --git a/e2e/__tests__/__snapshots__/testMatch.test.ts.snap b/e2e/__tests__/__snapshots__/testMatch.test.ts.snap index ed8312fe8a59..8062f817483e 100644 --- a/e2e/__tests__/__snapshots__/testMatch.test.ts.snap +++ b/e2e/__tests__/__snapshots__/testMatch.test.ts.snap @@ -1,7 +1,8 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP exports[`testMatch should able to match file with cjs and mjs extension 1`] = ` -"Test Suites: 2 passed, 2 total +"Seed: <> +Test Suites: 2 passed, 2 total Tests: 2 passed, 2 total Snapshots: 0 total Time: <> diff --git a/e2e/__tests__/__snapshots__/testNamePattern.test.ts.snap b/e2e/__tests__/__snapshots__/testNamePattern.test.ts.snap index 9c72df9c12dd..9ccff53ec846 100644 --- a/e2e/__tests__/__snapshots__/testNamePattern.test.ts.snap +++ b/e2e/__tests__/__snapshots__/testNamePattern.test.ts.snap @@ -1,7 +1,8 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP exports[`testNamePattern 1`] = ` -"Test Suites: 1 passed, 1 total +"Seed: <> +Test Suites: 1 passed, 1 total Tests: 3 skipped, 2 passed, 5 total Snapshots: 0 total Time: <> diff --git a/e2e/__tests__/__snapshots__/testNamePatternSkipped.test.ts.snap b/e2e/__tests__/__snapshots__/testNamePatternSkipped.test.ts.snap index fb6226de5485..76f6018a11b5 100644 --- a/e2e/__tests__/__snapshots__/testNamePatternSkipped.test.ts.snap +++ b/e2e/__tests__/__snapshots__/testNamePatternSkipped.test.ts.snap @@ -1,7 +1,8 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP exports[`testNamePattern skipped 1`] = ` -"Test Suites: 1 passed, 1 total +"Seed: <> +Test Suites: 1 passed, 1 total Tests: 1 skipped, 1 passed, 2 total Snapshots: 0 total Time: <> diff --git a/e2e/__tests__/__snapshots__/timeouts.test.ts.snap b/e2e/__tests__/__snapshots__/timeouts.test.ts.snap index 45abed912e71..3a3a682f2754 100644 --- a/e2e/__tests__/__snapshots__/timeouts.test.ts.snap +++ b/e2e/__tests__/__snapshots__/timeouts.test.ts.snap @@ -6,7 +6,8 @@ exports[`does not exceed the command line testTimeout 1`] = ` `; exports[`does not exceed the command line testTimeout 2`] = ` -"Test Suites: 1 passed, 1 total +"Seed: <> +Test Suites: 1 passed, 1 total Tests: 1 passed, 1 total Snapshots: 0 total Time: <> @@ -19,7 +20,8 @@ exports[`does not exceed the timeout 1`] = ` `; exports[`does not exceed the timeout 2`] = ` -"Test Suites: 1 passed, 1 total +"Seed: <> +Test Suites: 1 passed, 1 total Tests: 1 passed, 1 total Snapshots: 0 total Time: <> @@ -27,7 +29,8 @@ Ran all test suites." `; exports[`exceeds the command line testTimeout 1`] = ` -"Test Suites: 1 failed, 1 total +"Seed: <> +Test Suites: 1 failed, 1 total Tests: 1 failed, 1 total Snapshots: 0 total Time: <> @@ -35,7 +38,8 @@ Ran all test suites." `; exports[`exceeds the timeout 1`] = ` -"Test Suites: 1 failed, 1 total +"Seed: <> +Test Suites: 1 failed, 1 total Tests: 1 failed, 1 total Snapshots: 0 total Time: <> diff --git a/e2e/__tests__/__snapshots__/watchModeOnlyFailed.test.ts.snap b/e2e/__tests__/__snapshots__/watchModeOnlyFailed.test.ts.snap index 1eb721361319..c1b08fbd2ff8 100644 --- a/e2e/__tests__/__snapshots__/watchModeOnlyFailed.test.ts.snap +++ b/e2e/__tests__/__snapshots__/watchModeOnlyFailed.test.ts.snap @@ -35,7 +35,8 @@ exports[`can press "f" to run only failed tests: test results 2`] = ` `; exports[`can press "f" to run only failed tests: test summary 1`] = ` -"Test Suites: 1 failed, 1 passed, 2 total +"Seed: <> +Test Suites: 1 failed, 1 passed, 2 total Tests: 1 failed, 1 passed, 2 total Snapshots: 0 total Time: <> @@ -43,7 +44,8 @@ Ran all test suites." `; exports[`can press "f" to run only failed tests: test summary 2`] = ` -"Test Suites: 1 failed, 1 total +"Seed: <> +Test Suites: 1 failed, 1 total Tests: 1 failed, 1 total Snapshots: 0 total Time: <> diff --git a/e2e/__tests__/__snapshots__/watchModePatterns.test.ts.snap b/e2e/__tests__/__snapshots__/watchModePatterns.test.ts.snap index 1a0e4d7b91ae..c7f480f3f368 100644 --- a/e2e/__tests__/__snapshots__/watchModePatterns.test.ts.snap +++ b/e2e/__tests__/__snapshots__/watchModePatterns.test.ts.snap @@ -54,7 +54,8 @@ exports[`can press "p" to filter by file name: test results 2`] = ` `; exports[`can press "p" to filter by file name: test summary 1`] = ` -"Test Suites: 2 passed, 2 total +"Seed: <> +Test Suites: 2 passed, 2 total Tests: 4 passed, 4 total Snapshots: 0 total Time: <> @@ -62,7 +63,8 @@ Ran all test suites." `; exports[`can press "p" to filter by file name: test summary 2`] = ` -"Test Suites: 1 passed, 1 total +"Seed: <> +Test Suites: 1 passed, 1 total Tests: 2 passed, 2 total Snapshots: 0 total Time: <> @@ -108,7 +110,8 @@ PASS __tests__/foo.spec.js" `; exports[`can press "t" to filter by test name: test summary 1`] = ` -"Test Suites: 2 passed, 2 total +"Seed: <> +Test Suites: 2 passed, 2 total Tests: 4 passed, 4 total Snapshots: 0 total Time: <> @@ -116,7 +119,8 @@ Ran all test suites." `; exports[`can press "t" to filter by test name: test summary 2`] = ` -"Test Suites: 2 passed, 2 total +"Seed: <> +Test Suites: 2 passed, 2 total Tests: 2 skipped, 2 passed, 4 total Snapshots: 0 total Time: <> diff --git a/e2e/__tests__/__snapshots__/watchModeUpdateSnapshot.test.ts.snap b/e2e/__tests__/__snapshots__/watchModeUpdateSnapshot.test.ts.snap index f13279f7e2b1..19218bc4f4a8 100644 --- a/e2e/__tests__/__snapshots__/watchModeUpdateSnapshot.test.ts.snap +++ b/e2e/__tests__/__snapshots__/watchModeUpdateSnapshot.test.ts.snap @@ -33,7 +33,8 @@ Snapshot Summary `; exports[`can press "u" to update snapshots: test summary 1`] = ` -"Test Suites: 1 failed, 1 total +"Seed: <> +Test Suites: 1 failed, 1 total Tests: 1 failed, 1 total Snapshots: 1 failed, 1 total Time: <> @@ -41,7 +42,8 @@ Ran all test suites." `; exports[`can press "u" to update snapshots: test summary 2`] = ` -"Test Suites: 1 passed, 1 total +"Seed: <> +Test Suites: 1 passed, 1 total Tests: 1 passed, 1 total Snapshots: 1 updated, 1 total Time: <> diff --git a/e2e/__tests__/__snapshots__/workerRestarting.test.ts.snap b/e2e/__tests__/__snapshots__/workerRestarting.test.ts.snap index edf50a0f2d69..c2fee7456043 100644 --- a/e2e/__tests__/__snapshots__/workerRestarting.test.ts.snap +++ b/e2e/__tests__/__snapshots__/workerRestarting.test.ts.snap @@ -1,7 +1,8 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP exports[`all 3 test files should complete 1`] = ` -"Test Suites: 3 passed, 3 total +"Seed: <> +Test Suites: 3 passed, 3 total Tests: 3 passed, 3 total Snapshots: 0 total Time: <> diff --git a/e2e/__tests__/environmentAfterTeardown.test.ts b/e2e/__tests__/environmentAfterTeardown.test.ts index e0b8e10b871b..5f4041877a6f 100644 --- a/e2e/__tests__/environmentAfterTeardown.test.ts +++ b/e2e/__tests__/environmentAfterTeardown.test.ts @@ -9,7 +9,7 @@ import runJest from '../runJest'; test('prints useful error for environment methods after test is done', () => { const {stderr} = runJest('environment-after-teardown'); - const interestingLines = stderr.split('\n').slice(9, 18).join('\n'); + const interestingLines = stderr.split('\n').slice(10, 19).join('\n'); expect(interestingLines).toMatchSnapshot(); expect(stderr.split('\n')[10]).toBe( From 08e53ac7a708130a5e4d0ddd5fe43a65db65870a Mon Sep 17 00:00:00 2001 From: Joshua Hwang Date: Fri, 7 Oct 2022 22:30:19 +1100 Subject: [PATCH 14/53] added changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 30916146f9bb..475b4d06a297 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ ### Features +- `[@jest/cli, jest-config, @jest/environment, jest-environment-node, jest-environment-jsdom, @jest/reporters, jest-runtime, @jest/types]` Add `getSeed()` to the jest object available at runtime ([#13400](https://github.com/facebook/jest/pull/13400/)) - `[jest-config]` Add `readInitialConfig` utility function ([#13356](https://github.com/facebook/jest/pull/13356)) - `[jest-core]` Enable testResultsProcessor to be async ([#13343](https://github.com/facebook/jest/pull/13343)) - `[expect, @jest/expect-utils]` Allow `isA` utility to take a type argument ([#13355](https://github.com/facebook/jest/pull/13355)) From e848382d053eb6dfb5b28e08a71dbd2f6da576b7 Mon Sep 17 00:00:00 2001 From: Joshua Hwang Date: Fri, 7 Oct 2022 22:50:19 +1100 Subject: [PATCH 15/53] fixed e2e tests --- e2e/__tests__/__snapshots__/timeoutsLegacy.test.ts.snap | 9 ++++++--- e2e/jest-object/{__test__ => __tests__}/any-seed.test.js | 0 e2e/jest-object/{__test__ => __tests__}/get-seed.test.js | 0 .../__tests__/__snapshots__/SummaryReporter.test.js.snap | 4 ++++ 4 files changed, 10 insertions(+), 3 deletions(-) rename e2e/jest-object/{__test__ => __tests__}/any-seed.test.js (100%) rename e2e/jest-object/{__test__ => __tests__}/get-seed.test.js (100%) diff --git a/e2e/__tests__/__snapshots__/timeoutsLegacy.test.ts.snap b/e2e/__tests__/__snapshots__/timeoutsLegacy.test.ts.snap index 1f76f9f4b47f..f76ec82ba92c 100644 --- a/e2e/__tests__/__snapshots__/timeoutsLegacy.test.ts.snap +++ b/e2e/__tests__/__snapshots__/timeoutsLegacy.test.ts.snap @@ -1,7 +1,8 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP exports[`can read and write jasmine.DEFAULT_TIMEOUT_INTERVAL 1`] = ` -"Test Suites: 1 passed, 1 total +"Seed: <> +Test Suites: 1 passed, 1 total Tests: 1 passed, 1 total Snapshots: 0 total Time: <> @@ -14,7 +15,8 @@ exports[`does not exceed the timeout using jasmine.DEFAULT_TIMEOUT_INTERVAL 1`] `; exports[`does not exceed the timeout using jasmine.DEFAULT_TIMEOUT_INTERVAL 2`] = ` -"Test Suites: 1 passed, 1 total +"Seed: <> +Test Suites: 1 passed, 1 total Tests: 1 passed, 1 total Snapshots: 0 total Time: <> @@ -22,7 +24,8 @@ Ran all test suites." `; exports[`exceeds the timeout set using jasmine.DEFAULT_TIMEOUT_INTERVAL 1`] = ` -"Test Suites: 1 failed, 1 total +"Seed: <> +Test Suites: 1 failed, 1 total Tests: 1 failed, 1 total Snapshots: 0 total Time: <> diff --git a/e2e/jest-object/__test__/any-seed.test.js b/e2e/jest-object/__tests__/any-seed.test.js similarity index 100% rename from e2e/jest-object/__test__/any-seed.test.js rename to e2e/jest-object/__tests__/any-seed.test.js diff --git a/e2e/jest-object/__test__/get-seed.test.js b/e2e/jest-object/__tests__/get-seed.test.js similarity index 100% rename from e2e/jest-object/__test__/get-seed.test.js rename to e2e/jest-object/__tests__/get-seed.test.js diff --git a/packages/jest-reporters/src/__tests__/__snapshots__/SummaryReporter.test.js.snap b/packages/jest-reporters/src/__tests__/__snapshots__/SummaryReporter.test.js.snap index 42e5e5366851..38238c18f8a6 100644 --- a/packages/jest-reporters/src/__tests__/__snapshots__/SummaryReporter.test.js.snap +++ b/packages/jest-reporters/src/__tests__/__snapshots__/SummaryReporter.test.js.snap @@ -10,6 +10,7 @@ exports[`snapshots all have results (after update) 1`] = ` ↳ ../path/to/suite_one • unchecked snapshot 1 +Seed: XXXX Test Suites: 1 failed, 1 total Tests: 1 failed, 1 total Snapshots: 1 failed, 1 removed, 1 file removed, 1 updated, 1 written, 2 passed, 2 total @@ -28,6 +29,7 @@ exports[`snapshots all have results (no update) 1`] = ` ↳ ../path/to/suite_one • unchecked snapshot 1 +Seed: XXXX Test Suites: 1 failed, 1 total Tests: 1 failed, 1 total Snapshots: 1 failed, 1 obsolete, 1 file obsolete, 1 updated, 1 written, 2 passed, 2 total @@ -40,6 +42,7 @@ exports[`snapshots needs update with npm test 1`] = ` "Snapshot Summary › 2 snapshots failed from 1 test suite. Inspect your code changes or run \`npm test -- -u\` to update them. +Seed: XXXX Test Suites: 1 failed, 1 total Tests: 1 failed, 1 total Snapshots: 2 failed, 2 total @@ -52,6 +55,7 @@ exports[`snapshots needs update with yarn test 1`] = ` "Snapshot Summary › 2 snapshots failed from 1 test suite. Inspect your code changes or run \`yarn test -u\` to update them. +Seed: XXXX Test Suites: 1 failed, 1 total Tests: 1 failed, 1 total Snapshots: 2 failed, 2 total From 9424589b77cf6eb897b30c4c5f56cf330b7420b7 Mon Sep 17 00:00:00 2001 From: josh <41476440+Joshua-Hwang@users.noreply.github.com> Date: Sat, 8 Oct 2022 04:40:07 +1000 Subject: [PATCH 16/53] lint fix --- e2e/Utils.ts | 2 +- e2e/jest-object/__test__/get-seed.test.js | 2 +- packages/jest-reporters/src/Status.ts | 2 +- packages/jest-reporters/src/SummaryReporter.ts | 2 +- packages/jest-reporters/src/getSummary.ts | 1 - 5 files changed, 4 insertions(+), 5 deletions(-) diff --git a/e2e/Utils.ts b/e2e/Utils.ts index 56f42f0ce7eb..60d5ff877d4d 100644 --- a/e2e/Utils.ts +++ b/e2e/Utils.ts @@ -158,7 +158,7 @@ export const copyDir = (src: string, dest: string) => { }; export const replaceSeed = (str: string) => - str.replace(/Seed: (-?\d+)/g, 'Seed: <>'); + str.replace(/Seed: {8}(-?\d+)/g, 'Seed: <>'); export const replaceTime = (str: string) => str diff --git a/e2e/jest-object/__test__/get-seed.test.js b/e2e/jest-object/__test__/get-seed.test.js index 97b65af39c5f..2055f0223cf5 100644 --- a/e2e/jest-object/__test__/get-seed.test.js +++ b/e2e/jest-object/__test__/get-seed.test.js @@ -6,5 +6,5 @@ */ test('getSeed', () => { - expect(jest.getSeed()).toEqual(1234); + expect(jest.getSeed()).toBe(1234); }); diff --git a/packages/jest-reporters/src/Status.ts b/packages/jest-reporters/src/Status.ts index f724dadfd634..4c62346320e7 100644 --- a/packages/jest-reporters/src/Status.ts +++ b/packages/jest-reporters/src/Status.ts @@ -184,8 +184,8 @@ export default class Status { currentTestCases: this._currentTestCases, estimatedTime: this._estimatedTime, roundTime: true, - width, seed: this._globalConfig.seed, + width, })}`; } diff --git a/packages/jest-reporters/src/SummaryReporter.ts b/packages/jest-reporters/src/SummaryReporter.ts index 2168121fd579..ecc05be0414f 100644 --- a/packages/jest-reporters/src/SummaryReporter.ts +++ b/packages/jest-reporters/src/SummaryReporter.ts @@ -108,8 +108,8 @@ export default class SummaryReporter extends BaseReporter { if (numTotalTestSuites) { let message = getSummary(aggregatedResults, { - seed: this._globalConfig.seed, estimatedTime: this._estimatedTime, + seed: this._globalConfig.seed, }); if (!this._globalConfig.silent) { diff --git a/packages/jest-reporters/src/getSummary.ts b/packages/jest-reporters/src/getSummary.ts index c14b17b8f55d..186efd723caa 100644 --- a/packages/jest-reporters/src/getSummary.ts +++ b/packages/jest-reporters/src/getSummary.ts @@ -118,7 +118,6 @@ export default function getSummary( chalk.bold('Seed: ') + (options?.seed?.toString() ?? 'XXXX') }`; - const suites = `${ chalk.bold('Test Suites: ') + (suitesFailed ? `${chalk.bold.red(`${suitesFailed} failed`)}, ` : '') + From 83f5e9aa3421fbdb979b4d881457b5404b172aa4 Mon Sep 17 00:00:00 2001 From: josh <41476440+Joshua-Hwang@users.noreply.github.com> Date: Sat, 8 Oct 2022 09:12:17 +1000 Subject: [PATCH 17/53] updated further snapshots --- .../src/__tests__/__snapshots__/SummaryReporter.test.js.snap | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/packages/jest-reporters/src/__tests__/__snapshots__/SummaryReporter.test.js.snap b/packages/jest-reporters/src/__tests__/__snapshots__/SummaryReporter.test.js.snap index 42e5e5366851..38238c18f8a6 100644 --- a/packages/jest-reporters/src/__tests__/__snapshots__/SummaryReporter.test.js.snap +++ b/packages/jest-reporters/src/__tests__/__snapshots__/SummaryReporter.test.js.snap @@ -10,6 +10,7 @@ exports[`snapshots all have results (after update) 1`] = ` ↳ ../path/to/suite_one • unchecked snapshot 1 +Seed: XXXX Test Suites: 1 failed, 1 total Tests: 1 failed, 1 total Snapshots: 1 failed, 1 removed, 1 file removed, 1 updated, 1 written, 2 passed, 2 total @@ -28,6 +29,7 @@ exports[`snapshots all have results (no update) 1`] = ` ↳ ../path/to/suite_one • unchecked snapshot 1 +Seed: XXXX Test Suites: 1 failed, 1 total Tests: 1 failed, 1 total Snapshots: 1 failed, 1 obsolete, 1 file obsolete, 1 updated, 1 written, 2 passed, 2 total @@ -40,6 +42,7 @@ exports[`snapshots needs update with npm test 1`] = ` "Snapshot Summary › 2 snapshots failed from 1 test suite. Inspect your code changes or run \`npm test -- -u\` to update them. +Seed: XXXX Test Suites: 1 failed, 1 total Tests: 1 failed, 1 total Snapshots: 2 failed, 2 total @@ -52,6 +55,7 @@ exports[`snapshots needs update with yarn test 1`] = ` "Snapshot Summary › 2 snapshots failed from 1 test suite. Inspect your code changes or run \`yarn test -u\` to update them. +Seed: XXXX Test Suites: 1 failed, 1 total Tests: 1 failed, 1 total Snapshots: 2 failed, 2 total From bfcc0b4ea56e16f1fb4a4ade1be9d63629d7fe22 Mon Sep 17 00:00:00 2001 From: josh <41476440+Joshua-Hwang@users.noreply.github.com> Date: Sat, 8 Oct 2022 10:28:12 +1000 Subject: [PATCH 18/53] removed seed from initial options --- packages/jest-types/src/Config.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/jest-types/src/Config.ts b/packages/jest-types/src/Config.ts index b41124d0089e..7ec8a8f915da 100644 --- a/packages/jest-types/src/Config.ts +++ b/packages/jest-types/src/Config.ts @@ -289,7 +289,6 @@ export type InitialOptions = Partial<{ runTestsByPath: boolean; runtime: string; sandboxInjectedGlobals: Array; - seed: number; setupFiles: Array; setupFilesAfterEnv: Array; silent: boolean; From 3e786424a6c7ff2ae803cd7fe55c7317b070457b Mon Sep 17 00:00:00 2001 From: josh <41476440+Joshua-Hwang@users.noreply.github.com> Date: Sat, 8 Oct 2022 10:28:34 +1000 Subject: [PATCH 19/53] added typing tests --- packages/jest-types/__typetests__/jest.test.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/packages/jest-types/__typetests__/jest.test.ts b/packages/jest-types/__typetests__/jest.test.ts index 4b225aeb8b6e..6b98888d4b61 100644 --- a/packages/jest-types/__typetests__/jest.test.ts +++ b/packages/jest-types/__typetests__/jest.test.ts @@ -534,3 +534,6 @@ expectError(jest.retryTimes()); expectType(jest.setTimeout(6000)); expectError(jest.setTimeout()); + +expectType(jest.getSeed()); +expectError(jest.getSeed(123)); From ba7f2696b6f4cc5d36cd655a3c0e11ecd5c0dcd3 Mon Sep 17 00:00:00 2001 From: josh <41476440+Joshua-Hwang@users.noreply.github.com> Date: Sat, 8 Oct 2022 10:36:26 +1000 Subject: [PATCH 20/53] documentation and messages made more clear --- docs/CLI.md | 5 ++--- docs/JestObjectAPI.md | 3 ++- packages/jest-cli/src/cli/args.ts | 2 +- packages/jest-config/src/normalize.ts | 2 +- packages/jest-environment/src/index.ts | 4 ++-- 5 files changed, 8 insertions(+), 8 deletions(-) diff --git a/docs/CLI.md b/docs/CLI.md index 4828ad01666f..23619db3bd56 100644 --- a/docs/CLI.md +++ b/docs/CLI.md @@ -352,10 +352,9 @@ The default regex matching works fine on small runs, but becomes slow if provide ### `--seed=` -Provides a seed number that the tests have access to via `jest.getSeed()`. -If this option isn't specified Jest will randomly generate a seed. +Sets a seed value that can be retrieved in a test file via [`jest.getSeed()`](JestObjectAPI.md#jestgetseed). If this option is not specified Jest will randomly generate the value. -The seed value must be between `-0x80000000` to `0x7fffffff` inclusive. +The seed value must be between `-0x80000000` and `0x7fffffff` inclusive. ```bash jest --seed=1324 diff --git a/docs/JestObjectAPI.md b/docs/JestObjectAPI.md index 5c3b63ad623d..034d3a231d2c 100644 --- a/docs/JestObjectAPI.md +++ b/docs/JestObjectAPI.md @@ -909,11 +909,12 @@ This function is not available when using legacy fake timers implementation. ## Misc ### `jest.getSeed()` + Every time Jest runs a seed value is randomly generated which you could use in a pseudorandom number generator or anywhere else. :::tip -You can manually define this value with the CLI argument `--seed=`. +You can manually set this value via the [`--seed=`](CLI.md#--seednum) CLI argument. ::: diff --git a/packages/jest-cli/src/cli/args.ts b/packages/jest-cli/src/cli/args.ts index 7ca5ec28c66e..ea37f06aacc1 100644 --- a/packages/jest-cli/src/cli/args.ts +++ b/packages/jest-cli/src/cli/args.ts @@ -512,7 +512,7 @@ export const options: {[key: string]: Options} = { }, seed: { description: - 'Provides a seed number that the tests have access to via jest.getSeed(). If this option is not specified Jest will randomly generate a seed. The seed value must be between -0x80000000 to 0x7fffffff inclusive.', + 'Sets a seed value that can be retrieved in a tests file via `jest.getSeed()`. If this option is not specified Jest will randomly generate the value. The seed value must be between `-0x80000000` and `0x7fffffff` inclusive.', type: 'number', }, selectProjects: { diff --git a/packages/jest-config/src/normalize.ts b/packages/jest-config/src/normalize.ts index f13430a373b3..7eb9d9d33348 100644 --- a/packages/jest-config/src/normalize.ts +++ b/packages/jest-config/src/normalize.ts @@ -1027,7 +1027,7 @@ export default async function normalize( if (newOptions.seed < -0x80000000 || newOptions.seed > 0x7fffffff) { throw new ValidationError( 'Validation Error', - 'seed value is limited from -0x80000000 to 0x7fffffff', + 'seed value must be between `-0x80000000` and `0x7fffffff` inclusive', ); } diff --git a/packages/jest-environment/src/index.ts b/packages/jest-environment/src/index.ts index ca344f310146..058717e5310f 100644 --- a/packages/jest-environment/src/index.ts +++ b/packages/jest-environment/src/index.ts @@ -150,8 +150,8 @@ export interface Jest { */ getRealSystemTime(): number; /** - * Fetches the seed generated for this particular running of Jest. - * It can also be manually set with --seed CLI argument. + * Retrieves the seed value. It will be randomly generated for each test run + * or can be manually set via the `--seed` CLI argument. */ getSeed(): number; /** From 40047fe24317839f6f0fb818303192d394dbde5b Mon Sep 17 00:00:00 2001 From: josh <41476440+Joshua-Hwang@users.noreply.github.com> Date: Sat, 8 Oct 2022 11:11:11 +1000 Subject: [PATCH 21/53] added --showSeed arg --- packages/jest-cli/src/cli/args.ts | 5 +++++ packages/jest-config/src/index.ts | 1 + packages/jest-config/src/normalize.ts | 2 ++ packages/jest-reporters/src/Status.ts | 1 + packages/jest-reporters/src/SummaryReporter.ts | 1 + packages/jest-reporters/src/getSummary.ts | 8 +++++++- packages/jest-reporters/src/types.ts | 1 + packages/jest-types/__typetests__/jest.test.ts | 2 +- packages/jest-types/src/Config.ts | 2 ++ 9 files changed, 21 insertions(+), 2 deletions(-) diff --git a/packages/jest-cli/src/cli/args.ts b/packages/jest-cli/src/cli/args.ts index ea37f06aacc1..0dcc96269a13 100644 --- a/packages/jest-cli/src/cli/args.ts +++ b/packages/jest-cli/src/cli/args.ts @@ -442,6 +442,11 @@ export const options: {[key: string]: Options} = { description: 'The path to the "prettier" module used for inline snapshots.', type: 'string', }, + showSeed: { + description: + 'Prints the seed value in the test report summary. See `--seed` for how to set this value', + type: 'boolean', + }, projects: { description: 'A list of projects that use Jest to run all tests of all ' + diff --git a/packages/jest-config/src/index.ts b/packages/jest-config/src/index.ts index bbe76f06f5b8..8a8142c502be 100644 --- a/packages/jest-config/src/index.ts +++ b/packages/jest-config/src/index.ts @@ -117,6 +117,7 @@ const groupOptions = ( runTestsByPath: options.runTestsByPath, seed: options.seed, shard: options.shard, + showSeed: options.showSeed, silent: options.silent, skipFilter: options.skipFilter, snapshotFormat: options.snapshotFormat, diff --git a/packages/jest-config/src/normalize.ts b/packages/jest-config/src/normalize.ts index 7eb9d9d33348..f6d70e90a82e 100644 --- a/packages/jest-config/src/normalize.ts +++ b/packages/jest-config/src/normalize.ts @@ -1021,6 +1021,8 @@ export default async function normalize( newOptions.onlyChanged = newOptions.watch; } + newOptions.showSeed = argv.showSeed || !!argv.seed; + // xoroshiro128plus is used in v8 and is used here (at time of writing) newOptions.seed = argv.seed ?? Math.floor(0xffffffff * Math.random() - 0x80000000); diff --git a/packages/jest-reporters/src/Status.ts b/packages/jest-reporters/src/Status.ts index 4c62346320e7..f44c960e3ff1 100644 --- a/packages/jest-reporters/src/Status.ts +++ b/packages/jest-reporters/src/Status.ts @@ -185,6 +185,7 @@ export default class Status { estimatedTime: this._estimatedTime, roundTime: true, seed: this._globalConfig.seed, + showSeed: this._globalConfig.showSeed, width, })}`; } diff --git a/packages/jest-reporters/src/SummaryReporter.ts b/packages/jest-reporters/src/SummaryReporter.ts index ecc05be0414f..2666812e7837 100644 --- a/packages/jest-reporters/src/SummaryReporter.ts +++ b/packages/jest-reporters/src/SummaryReporter.ts @@ -110,6 +110,7 @@ export default class SummaryReporter extends BaseReporter { let message = getSummary(aggregatedResults, { estimatedTime: this._estimatedTime, seed: this._globalConfig.seed, + showSeed: this._globalConfig.showSeed, }); if (!this._globalConfig.silent) { diff --git a/packages/jest-reporters/src/getSummary.ts b/packages/jest-reporters/src/getSummary.ts index 186efd723caa..c8eb86cf31bf 100644 --- a/packages/jest-reporters/src/getSummary.ts +++ b/packages/jest-reporters/src/getSummary.ts @@ -187,5 +187,11 @@ export default function getSummary( }${snapshotsTotal} total`; const time = renderTime(runTime, estimatedTime, width); - return [seed, suites, tests, snapshots, time].join('\n'); + return [ + ...(options?.showSeed ? [seed] : []), + suites, + tests, + snapshots, + time, + ].join('\n'); } diff --git a/packages/jest-reporters/src/types.ts b/packages/jest-reporters/src/types.ts index ef9927d649a0..4d85ff3c9bc1 100644 --- a/packages/jest-reporters/src/types.ts +++ b/packages/jest-reporters/src/types.ts @@ -61,4 +61,5 @@ export type SummaryOptions = { roundTime?: boolean; width?: number; seed?: number; + showSeed?: boolean; }; diff --git a/packages/jest-types/__typetests__/jest.test.ts b/packages/jest-types/__typetests__/jest.test.ts index 6b98888d4b61..e6a9cc895e1f 100644 --- a/packages/jest-types/__typetests__/jest.test.ts +++ b/packages/jest-types/__typetests__/jest.test.ts @@ -535,5 +535,5 @@ expectError(jest.retryTimes()); expectType(jest.setTimeout(6000)); expectError(jest.setTimeout()); -expectType(jest.getSeed()); +expectType(jest.getSeed()); expectError(jest.getSeed(123)); diff --git a/packages/jest-types/src/Config.ts b/packages/jest-types/src/Config.ts index 7ec8a8f915da..1ac0ab890dd3 100644 --- a/packages/jest-types/src/Config.ts +++ b/packages/jest-types/src/Config.ts @@ -395,6 +395,7 @@ export type GlobalConfig = { runTestsByPath: boolean; rootDir: string; seed: number; + showSeed?: boolean; shard?: ShardConfig; silent?: boolean; skipFilter: boolean; @@ -539,6 +540,7 @@ export type Argv = Arguments< roots: Array; runInBand: boolean; seed: number; + showSeed: boolean; selectProjects: Array; setupFiles: Array; setupFilesAfterEnv: Array; From 67307257e81d77dc2eada59148dc7d0d40585cc7 Mon Sep 17 00:00:00 2001 From: josh <41476440+Joshua-Hwang@users.noreply.github.com> Date: Sat, 8 Oct 2022 11:54:40 +1000 Subject: [PATCH 22/53] moved seed from environment to ctor --- packages/jest-cli/src/cli/args.ts | 10 +++++----- packages/jest-environment-jsdom/src/index.ts | 4 +--- packages/jest-environment-node/src/index.ts | 4 +--- packages/jest-environment/src/index.ts | 1 - packages/jest-repl/src/cli/runtime-cli.ts | 1 + packages/jest-runner/src/runTest.ts | 1 + packages/jest-runtime/src/index.ts | 12 +++++++++++- 7 files changed, 20 insertions(+), 13 deletions(-) diff --git a/packages/jest-cli/src/cli/args.ts b/packages/jest-cli/src/cli/args.ts index 0dcc96269a13..1ed7606b37a1 100644 --- a/packages/jest-cli/src/cli/args.ts +++ b/packages/jest-cli/src/cli/args.ts @@ -442,11 +442,6 @@ export const options: {[key: string]: Options} = { description: 'The path to the "prettier" module used for inline snapshots.', type: 'string', }, - showSeed: { - description: - 'Prints the seed value in the test report summary. See `--seed` for how to set this value', - type: 'boolean', - }, projects: { description: 'A list of projects that use Jest to run all tests of all ' + @@ -551,6 +546,11 @@ export const options: {[key: string]: Options} = { description: 'Print your jest config and then exits.', type: 'boolean', }, + showSeed: { + description: + 'Prints the seed value in the test report summary. See `--seed` for how to set this value', + type: 'boolean', + }, silent: { description: 'Prevent tests from printing messages through the console.', type: 'boolean', diff --git a/packages/jest-environment-jsdom/src/index.ts b/packages/jest-environment-jsdom/src/index.ts index edbf300d6928..5973678a40f8 100644 --- a/packages/jest-environment-jsdom/src/index.ts +++ b/packages/jest-environment-jsdom/src/index.ts @@ -38,11 +38,9 @@ export default class JSDOMEnvironment implements JestEnvironment { private errorEventListener: ((event: Event & {error: Error}) => void) | null; moduleMocker: ModuleMocker | null; customExportConditions = ['browser']; - seed: number; constructor(config: JestEnvironmentConfig, context: EnvironmentContext) { - const {projectConfig, globalConfig} = config; - this.seed = globalConfig.seed; + const {projectConfig} = config; const virtualConsole = new VirtualConsole(); virtualConsole.sendTo(context.console, {omitJSDOMErrors: true}); diff --git a/packages/jest-environment-node/src/index.ts b/packages/jest-environment-node/src/index.ts index 095e62762096..5d326167e133 100644 --- a/packages/jest-environment-node/src/index.ts +++ b/packages/jest-environment-node/src/index.ts @@ -64,12 +64,10 @@ export default class NodeEnvironment implements JestEnvironment { global: Global.Global; moduleMocker: ModuleMocker | null; customExportConditions = ['node', 'node-addons']; - seed: number; // while `context` is unused, it should always be passed constructor(config: JestEnvironmentConfig, _context: EnvironmentContext) { - const {projectConfig, globalConfig} = config; - this.seed = globalConfig.seed; + const {projectConfig} = config; this.context = createContext(); const global = runInContext( 'this', diff --git a/packages/jest-environment/src/index.ts b/packages/jest-environment/src/index.ts index 058717e5310f..df50111e37f5 100644 --- a/packages/jest-environment/src/index.ts +++ b/packages/jest-environment/src/index.ts @@ -44,7 +44,6 @@ export declare class JestEnvironment { fakeTimersModern: ModernFakeTimers | null; moduleMocker: ModuleMocker | null; getVmContext(): Context | null; - seed: number; setup(): Promise; teardown(): Promise; handleTestEvent?: Circus.EventHandler; diff --git a/packages/jest-repl/src/cli/runtime-cli.ts b/packages/jest-repl/src/cli/runtime-cli.ts index 8e156a9364c4..6456413f88fc 100644 --- a/packages/jest-repl/src/cli/runtime-cli.ts +++ b/packages/jest-repl/src/cli/runtime-cli.ts @@ -106,6 +106,7 @@ export async function run( sourcesRelatedToTestsInChangedFiles: undefined, }, filePath, + globalConfig.seed, ); for (const path of projectConfig.setupFiles) { diff --git a/packages/jest-runner/src/runTest.ts b/packages/jest-runner/src/runTest.ts index 8a1d045f27e2..4ebd0b259384 100644 --- a/packages/jest-runner/src/runTest.ts +++ b/packages/jest-runner/src/runTest.ts @@ -196,6 +196,7 @@ async function runTestInternal( context.sourcesRelatedToTestsInChangedFiles, }, path, + globalConfig.seed, ); let isTornDown = false; diff --git a/packages/jest-runtime/src/index.ts b/packages/jest-runtime/src/index.ts index fafd340a26ac..3cc089367eb7 100644 --- a/packages/jest-runtime/src/index.ts +++ b/packages/jest-runtime/src/index.ts @@ -181,6 +181,7 @@ export default class Runtime { private readonly _esmModuleLinkingMap: WeakMap>; private readonly _testPath: string; private readonly _resolver: Resolver; + private _seed: number; private _shouldAutoMock: boolean; private readonly _shouldMockModuleCache: Map; private readonly _shouldUnmockTransitiveDependenciesCache: Map< @@ -213,6 +214,7 @@ export default class Runtime { cacheFS: Map, coverageOptions: ShouldInstrumentOptions, testPath: string, + seed: number, ) { this._cacheFS = cacheFS; this._config = config; @@ -242,6 +244,7 @@ export default class Runtime { this._testPath = testPath; this._resolver = resolver; this._scriptTransformer = transformer; + this._seed = seed; this._shouldAutoMock = config.automock; this._sourceMapRegistry = new Map(); this._fileTransforms = new Map(); @@ -2123,7 +2126,14 @@ export default class Runtime { ); } }, - getSeed: () => this._environment.seed, + getSeed: () => { + if (this._seed === undefined) { + throw new Error( + 'The seed value is not available. Likely you are using older versions of the jest dependencies.', + ); + } + return this._seed; + }, getTimerCount: () => _getFakeTimers().getTimerCount(), isMockFunction: this._moduleMocker.isMockFunction, isolateModules, From 589d4347f3cbd8bd2a0929047bdc7a2483e38e6f Mon Sep 17 00:00:00 2001 From: josh <41476440+Joshua-Hwang@users.noreply.github.com> Date: Sat, 8 Oct 2022 11:57:05 +1000 Subject: [PATCH 23/53] snapshots updated --- .../src/__tests__/__snapshots__/SummaryReporter.test.js.snap | 4 ---- 1 file changed, 4 deletions(-) diff --git a/packages/jest-reporters/src/__tests__/__snapshots__/SummaryReporter.test.js.snap b/packages/jest-reporters/src/__tests__/__snapshots__/SummaryReporter.test.js.snap index 38238c18f8a6..42e5e5366851 100644 --- a/packages/jest-reporters/src/__tests__/__snapshots__/SummaryReporter.test.js.snap +++ b/packages/jest-reporters/src/__tests__/__snapshots__/SummaryReporter.test.js.snap @@ -10,7 +10,6 @@ exports[`snapshots all have results (after update) 1`] = ` ↳ ../path/to/suite_one • unchecked snapshot 1 -Seed: XXXX Test Suites: 1 failed, 1 total Tests: 1 failed, 1 total Snapshots: 1 failed, 1 removed, 1 file removed, 1 updated, 1 written, 2 passed, 2 total @@ -29,7 +28,6 @@ exports[`snapshots all have results (no update) 1`] = ` ↳ ../path/to/suite_one • unchecked snapshot 1 -Seed: XXXX Test Suites: 1 failed, 1 total Tests: 1 failed, 1 total Snapshots: 1 failed, 1 obsolete, 1 file obsolete, 1 updated, 1 written, 2 passed, 2 total @@ -42,7 +40,6 @@ exports[`snapshots needs update with npm test 1`] = ` "Snapshot Summary › 2 snapshots failed from 1 test suite. Inspect your code changes or run \`npm test -- -u\` to update them. -Seed: XXXX Test Suites: 1 failed, 1 total Tests: 1 failed, 1 total Snapshots: 2 failed, 2 total @@ -55,7 +52,6 @@ exports[`snapshots needs update with yarn test 1`] = ` "Snapshot Summary › 2 snapshots failed from 1 test suite. Inspect your code changes or run \`yarn test -u\` to update them. -Seed: XXXX Test Suites: 1 failed, 1 total Tests: 1 failed, 1 total Snapshots: 2 failed, 2 total From 4eafd79a6752d57bde96c067a286133f621ca365 Mon Sep 17 00:00:00 2001 From: josh <41476440+Joshua-Hwang@users.noreply.github.com> Date: Sat, 8 Oct 2022 17:22:13 +1000 Subject: [PATCH 24/53] fixed up e2e tests --- e2e/Utils.ts | 6 +-- .../cliHandlesExactFilenames.test.ts.snap | 3 +- .../__snapshots__/console.test.ts.snap | 21 +++----- .../consoleDebugging.test.ts.snap | 3 +- ...consoleLogOutputWhenRunInBand.test.ts.snap | 3 +- .../__snapshots__/coverageReport.test.ts.snap | 3 +- .../coverageThreshold.test.ts.snap | 12 ++--- .../customReporters.test.ts.snap | 3 +- .../__snapshots__/domDiffing.test.ts.snap | 1 - .../emptyDescribeWithHooks.test.ts.snap | 12 ++--- .../findRelatedFiles.test.ts.snap | 9 ++-- .../__snapshots__/globals.test.ts.snap | 33 ++++-------- .../__snapshots__/injectGlobals.test.ts.snap | 6 +-- .../__snapshots__/jest.config.js.test.ts.snap | 6 +-- .../__snapshots__/jest.config.ts.test.ts.snap | 9 ++-- .../multiProjectRunner.test.ts.snap | 9 ++-- .../__snapshots__/nativeEsm.test.ts.snap | 9 ++-- .../__snapshots__/resolveAsync.test.ts.snap | 3 +- ...grammaticallyMultipleProjects.test.ts.snap | 3 +- .../__snapshots__/showConfig.test.ts.snap | 1 + .../__snapshots__/snapshot.test.ts.snap | 51 +++++++------------ .../__snapshots__/snapshotMockFs.test.ts.snap | 3 +- .../__snapshots__/stackTrace.test.ts.snap | 21 +++----- .../__snapshots__/testMatch.test.ts.snap | 3 +- .../testNamePattern.test.ts.snap | 3 +- .../testNamePatternSkipped.test.ts.snap | 3 +- .../__snapshots__/timeouts.test.ts.snap | 12 ++--- .../watchModeOnlyFailed.test.ts.snap | 6 +-- .../watchModePatterns.test.ts.snap | 12 ++--- .../watchModeUpdateSnapshot.test.ts.snap | 6 +-- .../workerRestarting.test.ts.snap | 3 +- e2e/__tests__/domDiffing.test.ts | 4 +- .../environmentAfterTeardown.test.ts | 4 +- e2e/__tests__/requireAfterTeardown.test.ts | 4 +- 34 files changed, 100 insertions(+), 190 deletions(-) diff --git a/e2e/Utils.ts b/e2e/Utils.ts index 60d5ff877d4d..c2d3f62cd61f 100644 --- a/e2e/Utils.ts +++ b/e2e/Utils.ts @@ -204,7 +204,7 @@ export const extractSummary = (stdout: string) => { const match = stdout .replace(/(?:\\[rn])+/g, '\n') .match( - /Seed:.*\nTest Suites:.*\nTests.*\nSnapshots.*\nTime.*(\nRan all test suites)*.*\n*$/gm, + /Test Suites:.*\nTests.*\nSnapshots.*\nTime.*(\nRan all test suites)*.*\n*$/gm, ); if (!match) { throw new Error(dedent` @@ -248,7 +248,7 @@ const sortTests = (stdout: string) => export const extractSortedSummary = (stdout: string) => { const {rest, summary} = extractSummary(stdout); return { - rest: sortTests(replaceSeed(replaceTime(rest))), + rest: sortTests(replaceTime(rest)), summary, }; }; @@ -257,7 +257,7 @@ export const extractSummaries = ( stdout: string, ): Array<{rest: string; summary: string}> => { const regex = - /Seed:.*\nTest Suites:.*\nTests.*\nSnapshots.*\nTime.*(\nRan all test suites)*.*\n*$/gm; + /Test Suites:.*\nTests.*\nSnapshots.*\nTime.*(\nRan all test suites)*.*\n*$/gm; let match = regex.exec(stdout); const matches: Array = []; diff --git a/e2e/__tests__/__snapshots__/cliHandlesExactFilenames.test.ts.snap b/e2e/__tests__/__snapshots__/cliHandlesExactFilenames.test.ts.snap index ba6d7d8e2bb4..4eb172dc686b 100644 --- a/e2e/__tests__/__snapshots__/cliHandlesExactFilenames.test.ts.snap +++ b/e2e/__tests__/__snapshots__/cliHandlesExactFilenames.test.ts.snap @@ -9,8 +9,7 @@ Force exiting Jest: Have you considered using \`--detectOpenHandles\` to detect `; exports[`CLI accepts exact file names if matchers matched 2`] = ` -"Seed: <> -Test Suites: 1 passed, 1 total +"Test Suites: 1 passed, 1 total Tests: 1 passed, 1 total Snapshots: 0 total Time: <> diff --git a/e2e/__tests__/__snapshots__/console.test.ts.snap b/e2e/__tests__/__snapshots__/console.test.ts.snap index dc629daa255a..849933bd86c4 100644 --- a/e2e/__tests__/__snapshots__/console.test.ts.snap +++ b/e2e/__tests__/__snapshots__/console.test.ts.snap @@ -41,8 +41,7 @@ exports[`console printing 1`] = ` `; exports[`console printing 2`] = ` -"Seed: <> -Test Suites: 1 passed, 1 total +"Test Suites: 1 passed, 1 total Tests: 1 passed, 1 total Snapshots: 0 total Time: <> @@ -93,8 +92,7 @@ exports[`console printing with --verbose 2`] = ` `; exports[`console printing with --verbose 3`] = ` -"Seed: <> -Test Suites: 1 passed, 1 total +"Test Suites: 1 passed, 1 total Tests: 1 passed, 1 total Snapshots: 0 total Time: <> @@ -129,8 +127,7 @@ exports[`does not error out when using winston 2`] = ` `; exports[`does not error out when using winston 3`] = ` -"Seed: <> -Test Suites: 1 passed, 1 total +"Test Suites: 1 passed, 1 total Tests: 1 passed, 1 total Snapshots: 0 total Time: <> @@ -142,8 +139,7 @@ exports[`does not print to console with --silent 1`] = `""`; exports[`does not print to console with --silent 2`] = `"PASS __tests__/console.test.js"`; exports[`does not print to console with --silent 3`] = ` -"Seed: <> -Test Suites: 1 passed, 1 total +"Test Suites: 1 passed, 1 total Tests: 1 passed, 1 total Snapshots: 0 total Time: <>" @@ -178,8 +174,7 @@ exports[`respects --noStackTrace 2`] = ` `; exports[`respects --noStackTrace 3`] = ` -"Seed: <> -Test Suites: 1 passed, 1 total +"Test Suites: 1 passed, 1 total Tests: 1 passed, 1 total Snapshots: 0 total Time: <> @@ -215,8 +210,7 @@ exports[`respects noStackTrace in config 2`] = ` `; exports[`respects noStackTrace in config 3`] = ` -"Seed: <> -Test Suites: 1 passed, 1 total +"Test Suites: 1 passed, 1 total Tests: 1 passed, 1 total Snapshots: 0 total Time: <> @@ -231,8 +225,7 @@ exports[`the jsdom console is the same as the test console 2`] = ` `; exports[`the jsdom console is the same as the test console 3`] = ` -"Seed: <> -Test Suites: 1 passed, 1 total +"Test Suites: 1 passed, 1 total Tests: 1 passed, 1 total Snapshots: 0 total Time: <> diff --git a/e2e/__tests__/__snapshots__/consoleDebugging.test.ts.snap b/e2e/__tests__/__snapshots__/consoleDebugging.test.ts.snap index 1a0bf9db5b60..4bc14067c0cf 100644 --- a/e2e/__tests__/__snapshots__/consoleDebugging.test.ts.snap +++ b/e2e/__tests__/__snapshots__/consoleDebugging.test.ts.snap @@ -14,8 +14,7 @@ exports[`console debugging with --verbose 2`] = ` `; exports[`console debugging with --verbose 3`] = ` -"Seed: <> -Test Suites: 1 passed, 1 total +"Test Suites: 1 passed, 1 total Tests: 1 passed, 1 total Snapshots: 1 passed, 1 total Time: <> diff --git a/e2e/__tests__/__snapshots__/consoleLogOutputWhenRunInBand.test.ts.snap b/e2e/__tests__/__snapshots__/consoleLogOutputWhenRunInBand.test.ts.snap index 2d0ab2f2a0cc..e092acb545d1 100644 --- a/e2e/__tests__/__snapshots__/consoleLogOutputWhenRunInBand.test.ts.snap +++ b/e2e/__tests__/__snapshots__/consoleLogOutputWhenRunInBand.test.ts.snap @@ -9,8 +9,7 @@ Force exiting Jest: Have you considered using \`--detectOpenHandles\` to detect `; exports[`prints console.logs when run with forceExit 2`] = ` -"Seed: <> -Test Suites: 1 passed, 1 total +"Test Suites: 1 passed, 1 total Tests: 1 passed, 1 total Snapshots: 0 total Time: <> diff --git a/e2e/__tests__/__snapshots__/coverageReport.test.ts.snap b/e2e/__tests__/__snapshots__/coverageReport.test.ts.snap index f13878bac359..bf48e0520423 100644 --- a/e2e/__tests__/__snapshots__/coverageReport.test.ts.snap +++ b/e2e/__tests__/__snapshots__/coverageReport.test.ts.snap @@ -61,8 +61,7 @@ All files | 60 | 0 | 50 | 60 | `; exports[`json reporter printing with --coverage 1`] = ` -"Seed: <> -Test Suites: 1 failed, 1 total +"Test Suites: 1 failed, 1 total Tests: 1 failed, 1 skipped, 2 passed, 4 total Snapshots: 0 total Time: <> diff --git a/e2e/__tests__/__snapshots__/coverageThreshold.test.ts.snap b/e2e/__tests__/__snapshots__/coverageThreshold.test.ts.snap index 8d0581625776..0fe03e7e827b 100644 --- a/e2e/__tests__/__snapshots__/coverageThreshold.test.ts.snap +++ b/e2e/__tests__/__snapshots__/coverageThreshold.test.ts.snap @@ -8,8 +8,7 @@ Jest: "global" coverage threshold for lines (100%) not met: 0%" `; exports[`excludes tests matched by path threshold groups from global group 2`] = ` -"Seed: <> -Test Suites: 1 passed, 1 total +"Test Suites: 1 passed, 1 total Tests: 1 passed, 1 total Snapshots: 0 total Time: <> @@ -43,8 +42,7 @@ Jest: "global" coverage threshold for lines (90%) not met: 50%" `; exports[`exits with 1 if coverage threshold is not met 2`] = ` -"Seed: <> -Test Suites: 1 passed, 1 total +"Test Suites: 1 passed, 1 total Tests: 1 passed, 1 total Snapshots: 0 total Time: <> @@ -68,8 +66,7 @@ Jest: Coverage data for apple.js was not found." `; exports[`exits with 1 if path threshold group is not found in coverage data 2`] = ` -"Seed: <> -Test Suites: 1 passed, 1 total +"Test Suites: 1 passed, 1 total Tests: 1 passed, 1 total Snapshots: 0 total Time: <> @@ -95,8 +92,7 @@ Jest: "./banana.js" coverage threshold for lines (100%) not met: 50%" `; exports[`file is matched by all path and glob threshold groups 2`] = ` -"Seed: <> -Test Suites: 1 passed, 1 total +"Test Suites: 1 passed, 1 total Tests: 1 passed, 1 total Snapshots: 0 total Time: <> diff --git a/e2e/__tests__/__snapshots__/customReporters.test.ts.snap b/e2e/__tests__/__snapshots__/customReporters.test.ts.snap index 0493a07f8801..7506630b07d2 100644 --- a/e2e/__tests__/__snapshots__/customReporters.test.ts.snap +++ b/e2e/__tests__/__snapshots__/customReporters.test.ts.snap @@ -78,8 +78,7 @@ exports[`Custom Reporters Integration default reporters enabled 1`] = ` `; exports[`Custom Reporters Integration default reporters enabled 2`] = ` -"Seed: <> -Test Suites: 1 passed, 1 total +"Test Suites: 1 passed, 1 total Tests: 1 passed, 1 total Snapshots: 0 total Time: <> diff --git a/e2e/__tests__/__snapshots__/domDiffing.test.ts.snap b/e2e/__tests__/__snapshots__/domDiffing.test.ts.snap index 3f81fa9af30c..d137c76c46ae 100644 --- a/e2e/__tests__/__snapshots__/domDiffing.test.ts.snap +++ b/e2e/__tests__/__snapshots__/domDiffing.test.ts.snap @@ -43,7 +43,6 @@ exports[`should work without error 1`] = ` at Object.toBe (__tests__/dom.test.js:18:41) -Seed: <> Test Suites: 1 failed, 1 total Tests: 2 failed, 2 total Snapshots: 0 total diff --git a/e2e/__tests__/__snapshots__/emptyDescribeWithHooks.test.ts.snap b/e2e/__tests__/__snapshots__/emptyDescribeWithHooks.test.ts.snap index bc8fb3efedca..ad2f6318c6ed 100644 --- a/e2e/__tests__/__snapshots__/emptyDescribeWithHooks.test.ts.snap +++ b/e2e/__tests__/__snapshots__/emptyDescribeWithHooks.test.ts.snap @@ -3,8 +3,7 @@ exports[`hook in describe with skipped test 1`] = ` Object { "rest": "", - "summary": "Seed: <> -Test Suites: 1 skipped, 0 of 1 total + "summary": "Test Suites: 1 skipped, 0 of 1 total Tests: 1 skipped, 1 total Snapshots: 0 total Time: <> @@ -31,8 +30,7 @@ Object { at beforeEach (__tests__/hookInEmptyDescribe.test.js:9:3) at Object.describe (__tests__/hookInEmptyDescribe.test.js:8:1)", - "summary": "Seed: <> -Test Suites: 1 failed, 1 total + "summary": "Test Suites: 1 failed, 1 total Tests: 1 passed, 1 total Snapshots: 0 total Time: <> @@ -59,8 +57,7 @@ Object { at beforeEach (__tests__/hookInEmptyNestedDescribe.test.js:9:3) at Object.describe (__tests__/hookInEmptyNestedDescribe.test.js:8:1)", - "summary": "Seed: <> -Test Suites: 1 failed, 1 total + "summary": "Test Suites: 1 failed, 1 total Tests: 1 passed, 1 total Snapshots: 0 total Time: <> @@ -132,8 +129,7 @@ Object { at beforeAll (__tests__/multipleHooksInEmptyDescribe.test.js:12:3) at Object.describe (__tests__/multipleHooksInEmptyDescribe.test.js:8:1)", - "summary": "Seed: <> -Test Suites: 1 failed, 1 total + "summary": "Test Suites: 1 failed, 1 total Tests: 1 passed, 1 total Snapshots: 0 total Time: <> diff --git a/e2e/__tests__/__snapshots__/findRelatedFiles.test.ts.snap b/e2e/__tests__/__snapshots__/findRelatedFiles.test.ts.snap index 9ce6ddab28a7..d21e158b8bf1 100644 --- a/e2e/__tests__/__snapshots__/findRelatedFiles.test.ts.snap +++ b/e2e/__tests__/__snapshots__/findRelatedFiles.test.ts.snap @@ -1,8 +1,7 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP exports[`--findRelatedTests flag coverage configuration is applied correctly 1`] = ` -"Seed: <> -Test Suites: 1 passed, 1 total +"Test Suites: 1 passed, 1 total Tests: 1 passed, 1 total Snapshots: 0 total Time: <> @@ -24,8 +23,7 @@ All files | 100 | 100 | 100 | 100 | `; exports[`--findRelatedTests flag generates coverage report for filename 1`] = ` -"Seed: <> -Test Suites: 2 passed, 2 total +"Test Suites: 2 passed, 2 total Tests: 2 passed, 2 total Snapshots: 0 total Time: <> @@ -48,8 +46,7 @@ All files | 100 | 100 | 100 | 100 | `; exports[`--findRelatedTests flag generates coverage report for filename 4`] = ` -"Seed: <> -Test Suites: 1 passed, 1 total +"Test Suites: 1 passed, 1 total Tests: 1 passed, 1 total Snapshots: 0 total Time: <> diff --git a/e2e/__tests__/__snapshots__/globals.test.ts.snap b/e2e/__tests__/__snapshots__/globals.test.ts.snap index de691f9a2c6e..47e0dd3db70d 100644 --- a/e2e/__tests__/__snapshots__/globals.test.ts.snap +++ b/e2e/__tests__/__snapshots__/globals.test.ts.snap @@ -10,8 +10,7 @@ exports[`basic test constructs 1`] = ` `; exports[`basic test constructs 2`] = ` -"Seed: <> -Test Suites: 1 passed, 1 total +"Test Suites: 1 passed, 1 total Tests: 4 passed, 4 total Snapshots: 0 total Time: <> @@ -31,8 +30,7 @@ exports[`cannot have describe with no implementation 1`] = ` `; exports[`cannot have describe with no implementation 2`] = ` -"Seed: <> -Test Suites: 1 failed, 1 total +"Test Suites: 1 failed, 1 total Tests: 0 total Snapshots: 0 total Time: <> @@ -54,8 +52,7 @@ exports[`cannot test with no implementation 1`] = ` `; exports[`cannot test with no implementation 2`] = ` -"Seed: <> -Test Suites: 1 failed, 1 total +"Test Suites: 1 failed, 1 total Tests: 0 total Snapshots: 0 total Time: <> @@ -77,8 +74,7 @@ exports[`cannot test with no implementation with expand arg 1`] = ` `; exports[`cannot test with no implementation with expand arg 2`] = ` -"Seed: <> -Test Suites: 1 failed, 1 total +"Test Suites: 1 failed, 1 total Tests: 0 total Snapshots: 0 total Time: <> @@ -92,8 +88,7 @@ exports[`function as describe() descriptor 1`] = ` `; exports[`function as describe() descriptor 2`] = ` -"Seed: <> -Test Suites: 1 passed, 1 total +"Test Suites: 1 passed, 1 total Tests: 1 passed, 1 total Snapshots: 0 total Time: <> @@ -106,8 +101,7 @@ exports[`function as it() descriptor 1`] = ` `; exports[`function as it() descriptor 2`] = ` -"Seed: <> -Test Suites: 1 passed, 1 total +"Test Suites: 1 passed, 1 total Tests: 1 passed, 1 total Snapshots: 0 total Time: <> @@ -123,8 +117,7 @@ exports[`interleaved describe and test children order 1`] = ` `; exports[`interleaved describe and test children order 2`] = ` -"Seed: <> -Test Suites: 1 passed, 1 total +"Test Suites: 1 passed, 1 total Tests: 3 passed, 3 total Snapshots: 0 total Time: <> @@ -147,8 +140,7 @@ exports[`only 1`] = ` `; exports[`only 2`] = ` -"Seed: <> -Test Suites: 1 passed, 1 total +"Test Suites: 1 passed, 1 total Tests: 1 skipped, 7 passed, 8 total Snapshots: 0 total Time: <> @@ -171,8 +163,7 @@ exports[`only with expand arg 1`] = ` `; exports[`only with expand arg 2`] = ` -"Seed: <> -Test Suites: 1 passed, 1 total +"Test Suites: 1 passed, 1 total Tests: 1 skipped, 7 passed, 8 total Snapshots: 0 total Time: <> @@ -196,8 +187,7 @@ exports[`skips 1`] = ` `; exports[`skips 2`] = ` -"Seed: <> -Test Suites: 1 passed, 1 total +"Test Suites: 1 passed, 1 total Tests: 8 skipped, 1 passed, 9 total Snapshots: 0 total Time: <> @@ -221,8 +211,7 @@ exports[`skips with expand arg 1`] = ` `; exports[`skips with expand arg 2`] = ` -"Seed: <> -Test Suites: 1 passed, 1 total +"Test Suites: 1 passed, 1 total Tests: 8 skipped, 1 passed, 9 total Snapshots: 0 total Time: <> diff --git a/e2e/__tests__/__snapshots__/injectGlobals.test.ts.snap b/e2e/__tests__/__snapshots__/injectGlobals.test.ts.snap index de97464b6e34..74c718ed91b9 100644 --- a/e2e/__tests__/__snapshots__/injectGlobals.test.ts.snap +++ b/e2e/__tests__/__snapshots__/injectGlobals.test.ts.snap @@ -6,8 +6,7 @@ exports[`globals are undefined if passed \`false\` from CLI 1`] = ` `; exports[`globals are undefined if passed \`false\` from CLI 2`] = ` -"Seed: <> -Test Suites: 1 passed, 1 total +"Test Suites: 1 passed, 1 total Tests: 1 passed, 1 total Snapshots: 0 total Time: <> @@ -20,8 +19,7 @@ exports[`globals are undefined if passed \`false\` from config 1`] = ` `; exports[`globals are undefined if passed \`false\` from config 2`] = ` -"Seed: <> -Test Suites: 1 passed, 1 total +"Test Suites: 1 passed, 1 total Tests: 1 passed, 1 total Snapshots: 0 total Time: <> diff --git a/e2e/__tests__/__snapshots__/jest.config.js.test.ts.snap b/e2e/__tests__/__snapshots__/jest.config.js.test.ts.snap index 9b74d9e719f4..45f2b0bcb85b 100644 --- a/e2e/__tests__/__snapshots__/jest.config.js.test.ts.snap +++ b/e2e/__tests__/__snapshots__/jest.config.js.test.ts.snap @@ -15,8 +15,7 @@ exports[`traverses directory tree up until it finds jest.config 2`] = ` `; exports[`traverses directory tree up until it finds jest.config 3`] = ` -"Seed: <> -Test Suites: 1 passed, 1 total +"Test Suites: 1 passed, 1 total Tests: 2 passed, 2 total Snapshots: 0 total Time: <> @@ -29,8 +28,7 @@ exports[`works with jest.config.js 1`] = ` `; exports[`works with jest.config.js 2`] = ` -"Seed: <> -Test Suites: 1 passed, 1 total +"Test Suites: 1 passed, 1 total Tests: 1 passed, 1 total Snapshots: 0 total Time: <> diff --git a/e2e/__tests__/__snapshots__/jest.config.ts.test.ts.snap b/e2e/__tests__/__snapshots__/jest.config.ts.test.ts.snap index 8215365a75ba..7ecbcfe06551 100644 --- a/e2e/__tests__/__snapshots__/jest.config.ts.test.ts.snap +++ b/e2e/__tests__/__snapshots__/jest.config.ts.test.ts.snap @@ -15,8 +15,7 @@ exports[`traverses directory tree up until it finds jest.config 2`] = ` `; exports[`traverses directory tree up until it finds jest.config 3`] = ` -"Seed: <> -Test Suites: 1 passed, 1 total +"Test Suites: 1 passed, 1 total Tests: 2 passed, 2 total Snapshots: 0 total Time: <> @@ -29,8 +28,7 @@ exports[`works with jest.config.ts 1`] = ` `; exports[`works with jest.config.ts 2`] = ` -"Seed: <> -Test Suites: 1 passed, 1 total +"Test Suites: 1 passed, 1 total Tests: 1 passed, 1 total Snapshots: 0 total Time: <> @@ -43,8 +41,7 @@ exports[`works with tsconfig.json 1`] = ` `; exports[`works with tsconfig.json 2`] = ` -"Seed: <> -Test Suites: 1 passed, 1 total +"Test Suites: 1 passed, 1 total Tests: 1 passed, 1 total Snapshots: 0 total Time: <> diff --git a/e2e/__tests__/__snapshots__/multiProjectRunner.test.ts.snap b/e2e/__tests__/__snapshots__/multiProjectRunner.test.ts.snap index 1869d98a1d60..bf72a9f9bf37 100644 --- a/e2e/__tests__/__snapshots__/multiProjectRunner.test.ts.snap +++ b/e2e/__tests__/__snapshots__/multiProjectRunner.test.ts.snap @@ -1,8 +1,7 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP exports[`can pass projects or global config 1`] = ` -"Seed: <> -Test Suites: 3 failed, 3 total +"Test Suites: 3 failed, 3 total Tests: 0 total Snapshots: 0 total Time: <> @@ -10,8 +9,7 @@ Ran all test suites." `; exports[`can pass projects or global config 2`] = ` -"Seed: <> -Test Suites: 3 passed, 3 total +"Test Suites: 3 passed, 3 total Tests: 3 passed, 3 total Snapshots: 0 total Time: <> @@ -25,8 +23,7 @@ PASS project2/__tests__/file1.test.js" `; exports[`can pass projects or global config 4`] = ` -"Seed: <> -Test Suites: 3 passed, 3 total +"Test Suites: 3 passed, 3 total Tests: 3 passed, 3 total Snapshots: 0 total Time: <> diff --git a/e2e/__tests__/__snapshots__/nativeEsm.test.ts.snap b/e2e/__tests__/__snapshots__/nativeEsm.test.ts.snap index a27baaf86790..4324b26d16c4 100644 --- a/e2e/__tests__/__snapshots__/nativeEsm.test.ts.snap +++ b/e2e/__tests__/__snapshots__/nativeEsm.test.ts.snap @@ -1,8 +1,7 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP exports[`on node >=16.9.0 support re-exports from CJS of dual packages 1`] = ` -"Seed: <> -Test Suites: 1 passed, 1 total +"Test Suites: 1 passed, 1 total Tests: 1 passed, 1 total Snapshots: 0 total Time: <> @@ -10,8 +9,7 @@ Ran all test suites matching /native-esm-deep-cjs-reexport.test.js/i." `; exports[`runs test with native ESM 1`] = ` -"Seed: <> -Test Suites: 1 passed, 1 total +"Test Suites: 1 passed, 1 total Tests: 34 passed, 34 total Snapshots: 0 total Time: <> @@ -19,8 +17,7 @@ Ran all test suites matching /native-esm.test.js/i." `; exports[`supports top-level await 1`] = ` -"Seed: <> -Test Suites: 1 passed, 1 total +"Test Suites: 1 passed, 1 total Tests: 1 passed, 1 total Snapshots: 0 total Time: <> diff --git a/e2e/__tests__/__snapshots__/resolveAsync.test.ts.snap b/e2e/__tests__/__snapshots__/resolveAsync.test.ts.snap index 4ff7a15cc8fe..edfad21176f6 100644 --- a/e2e/__tests__/__snapshots__/resolveAsync.test.ts.snap +++ b/e2e/__tests__/__snapshots__/resolveAsync.test.ts.snap @@ -1,8 +1,7 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP exports[`runs test with native ESM 1`] = ` -"Seed: <> -Test Suites: 1 passed, 1 total +"Test Suites: 1 passed, 1 total Tests: 1 passed, 1 total Snapshots: 0 total Time: <> diff --git a/e2e/__tests__/__snapshots__/runProgrammaticallyMultipleProjects.test.ts.snap b/e2e/__tests__/__snapshots__/runProgrammaticallyMultipleProjects.test.ts.snap index 3a9b9104e9f1..9ffad72f23c0 100644 --- a/e2e/__tests__/__snapshots__/runProgrammaticallyMultipleProjects.test.ts.snap +++ b/e2e/__tests__/__snapshots__/runProgrammaticallyMultipleProjects.test.ts.snap @@ -1,8 +1,7 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP exports[`run programmatically with multiple projects: summary 1`] = ` -"Seed: <> -Test Suites: 2 passed, 2 total +"Test Suites: 2 passed, 2 total Tests: 2 passed, 2 total Snapshots: 0 total Time: <> diff --git a/e2e/__tests__/__snapshots__/showConfig.test.ts.snap b/e2e/__tests__/__snapshots__/showConfig.test.ts.snap index 79a0e38b919b..98d2fcb2e79b 100644 --- a/e2e/__tests__/__snapshots__/showConfig.test.ts.snap +++ b/e2e/__tests__/__snapshots__/showConfig.test.ts.snap @@ -126,6 +126,7 @@ exports[`--showConfig outputs config info and exits 1`] = ` "rootDir": "<>", "runTestsByPath": false, "seed": <>, + "showSeed": false, "skipFilter": false, "snapshotFormat": { "escapeString": false, diff --git a/e2e/__tests__/__snapshots__/snapshot.test.ts.snap b/e2e/__tests__/__snapshots__/snapshot.test.ts.snap index b39b6df99b45..811a7727b08a 100644 --- a/e2e/__tests__/__snapshots__/snapshot.test.ts.snap +++ b/e2e/__tests__/__snapshots__/snapshot.test.ts.snap @@ -1,8 +1,7 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP exports[`Snapshot Validation deletes a snapshot when a test does removes all the snapshots 1`] = ` -"Seed: <> -Test Suites: 3 passed, 3 total +"Test Suites: 3 passed, 3 total Tests: 9 passed, 9 total Snapshots: 9 written, 9 total Time: <> @@ -10,8 +9,7 @@ Ran all test suites." `; exports[`Snapshot Validation deletes a snapshot when a test does removes all the snapshots 2`] = ` -"Seed: <> -Test Suites: 3 passed, 3 total +"Test Suites: 3 passed, 3 total Tests: 6 passed, 6 total Snapshots: 1 file removed, 5 passed, 5 total Time: <> @@ -19,8 +17,7 @@ Ran all test suites." `; exports[`Snapshot Validation deletes the snapshot if the test suite has been removed 1`] = ` -"Seed: <> -Test Suites: 3 passed, 3 total +"Test Suites: 3 passed, 3 total Tests: 9 passed, 9 total Snapshots: 9 written, 9 total Time: <> @@ -28,8 +25,7 @@ Ran all test suites." `; exports[`Snapshot Validation deletes the snapshot if the test suite has been removed 2`] = ` -"Seed: <> -Test Suites: 2 passed, 2 total +"Test Suites: 2 passed, 2 total Tests: 5 passed, 5 total Snapshots: 1 file removed, 5 passed, 5 total Time: <> @@ -37,8 +33,7 @@ Ran all test suites." `; exports[`Snapshot Validation does not save snapshots in CI mode by default 1`] = ` -"Seed: <> -Test Suites: 3 failed, 3 total +"Test Suites: 3 failed, 3 total Tests: 7 failed, 2 passed, 9 total Snapshots: 9 failed, 9 total Time: <> @@ -46,8 +41,7 @@ Ran all test suites." `; exports[`Snapshot Validation updates the snapshot when a test removes some snapshots 1`] = ` -"Seed: <> -Test Suites: 3 passed, 3 total +"Test Suites: 3 passed, 3 total Tests: 9 passed, 9 total Snapshots: 9 written, 9 total Time: <> @@ -55,8 +49,7 @@ Ran all test suites." `; exports[`Snapshot Validation updates the snapshot when a test removes some snapshots 2`] = ` -"Seed: <> -Test Suites: 3 passed, 3 total +"Test Suites: 3 passed, 3 total Tests: 9 passed, 9 total Snapshots: 1 removed, 1 updated, 7 passed, 8 total Time: <> @@ -64,8 +57,7 @@ Ran all test suites." `; exports[`Snapshot Validation works on subsequent runs without \`-u\` 1`] = ` -"Seed: <> -Test Suites: 3 passed, 3 total +"Test Suites: 3 passed, 3 total Tests: 9 passed, 9 total Snapshots: 9 written, 9 total Time: <> @@ -73,8 +65,7 @@ Ran all test suites." `; exports[`Snapshot Validation works on subsequent runs without \`-u\` 2`] = ` -"Seed: <> -Test Suites: 3 passed, 3 total +"Test Suites: 3 passed, 3 total Tests: 9 passed, 9 total Snapshots: 9 passed, 9 total Time: <> @@ -82,8 +73,7 @@ Ran all test suites." `; exports[`Snapshot stores new snapshots on the first run 1`] = ` -"Seed: <> -Test Suites: 2 passed, 2 total +"Test Suites: 2 passed, 2 total Tests: 5 passed, 5 total Snapshots: 5 written, 5 total Time: <> @@ -91,8 +81,7 @@ Ran all test suites." `; exports[`Snapshot works with escaped characters 1`] = ` -"Seed: <> -Test Suites: 1 passed, 1 total +"Test Suites: 1 passed, 1 total Tests: 1 passed, 1 total Snapshots: 1 written, 1 total Time: <> @@ -100,8 +89,7 @@ Ran all test suites matching /snapshot.test.js/i." `; exports[`Snapshot works with escaped characters 2`] = ` -"Seed: <> -Test Suites: 1 passed, 1 total +"Test Suites: 1 passed, 1 total Tests: 2 passed, 2 total Snapshots: 1 written, 1 passed, 2 total Time: <> @@ -109,8 +97,7 @@ Ran all test suites matching /snapshot.test.js/i." `; exports[`Snapshot works with escaped characters 3`] = ` -"Seed: <> -Test Suites: 1 passed, 1 total +"Test Suites: 1 passed, 1 total Tests: 2 passed, 2 total Snapshots: 2 passed, 2 total Time: <> @@ -118,8 +105,7 @@ Ran all test suites matching /snapshot.test.js/i." `; exports[`Snapshot works with escaped regex 1`] = ` -"Seed: <> -Test Suites: 1 passed, 1 total +"Test Suites: 1 passed, 1 total Tests: 2 passed, 2 total Snapshots: 2 written, 2 total Time: <> @@ -127,8 +113,7 @@ Ran all test suites matching /snapshotEscapeRegex.js/i." `; exports[`Snapshot works with escaped regex 2`] = ` -"Seed: <> -Test Suites: 1 passed, 1 total +"Test Suites: 1 passed, 1 total Tests: 2 passed, 2 total Snapshots: 2 passed, 2 total Time: <> @@ -136,8 +121,7 @@ Ran all test suites matching /snapshotEscapeRegex.js/i." `; exports[`Snapshot works with template literal substitutions 1`] = ` -"Seed: <> -Test Suites: 1 passed, 1 total +"Test Suites: 1 passed, 1 total Tests: 1 passed, 1 total Snapshots: 1 written, 1 total Time: <> @@ -145,8 +129,7 @@ Ran all test suites matching /snapshotEscapeSubstitution.test.js/i." `; exports[`Snapshot works with template literal substitutions 2`] = ` -"Seed: <> -Test Suites: 1 passed, 1 total +"Test Suites: 1 passed, 1 total Tests: 1 passed, 1 total Snapshots: 1 passed, 1 total Time: <> diff --git a/e2e/__tests__/__snapshots__/snapshotMockFs.test.ts.snap b/e2e/__tests__/__snapshots__/snapshotMockFs.test.ts.snap index 277014715d3a..0b187ca45889 100644 --- a/e2e/__tests__/__snapshots__/snapshotMockFs.test.ts.snap +++ b/e2e/__tests__/__snapshots__/snapshotMockFs.test.ts.snap @@ -1,8 +1,7 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP exports[`store snapshot even if fs is mocked 1`] = ` -"Seed: <> -Test Suites: 1 passed, 1 total +"Test Suites: 1 passed, 1 total Tests: 1 passed, 1 total Snapshots: 1 written, 1 total Time: <> diff --git a/e2e/__tests__/__snapshots__/stackTrace.test.ts.snap b/e2e/__tests__/__snapshots__/stackTrace.test.ts.snap index 351c1252a41e..e06101e24809 100644 --- a/e2e/__tests__/__snapshots__/stackTrace.test.ts.snap +++ b/e2e/__tests__/__snapshots__/stackTrace.test.ts.snap @@ -1,8 +1,7 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP exports[`Stack Trace does not print a stack trace for errors when --noStackTrace is given 1`] = ` -"Seed: <> -Test Suites: 1 failed, 1 total +"Test Suites: 1 failed, 1 total Tests: 3 failed, 3 total Snapshots: 0 total Time: <> @@ -10,8 +9,7 @@ Ran all test suites matching /testError.test.js/i." `; exports[`Stack Trace does not print a stack trace for matching errors when --noStackTrace is given 1`] = ` -"Seed: <> -Test Suites: 1 failed, 1 total +"Test Suites: 1 failed, 1 total Tests: 1 failed, 1 total Snapshots: 0 total Time: <> @@ -19,8 +17,7 @@ Ran all test suites matching /stackTrace.test.js/i." `; exports[`Stack Trace does not print a stack trace for runtime errors when --noStackTrace is given 1`] = ` -"Seed: <> -Test Suites: 1 failed, 1 total +"Test Suites: 1 failed, 1 total Tests: 0 total Snapshots: 0 total Time: <> @@ -28,8 +25,7 @@ Ran all test suites matching /runtimeError.test.js/i." `; exports[`Stack Trace prints a stack trace for errors 1`] = ` -"Seed: <> -Test Suites: 1 failed, 1 total +"Test Suites: 1 failed, 1 total Tests: 3 failed, 3 total Snapshots: 0 total Time: <> @@ -37,8 +33,7 @@ Ran all test suites matching /testError.test.js/i." `; exports[`Stack Trace prints a stack trace for errors without message in stack trace 1`] = ` -"Seed: <> -Test Suites: 1 failed, 1 total +"Test Suites: 1 failed, 1 total Tests: 1 failed, 1 total Snapshots: 0 total Time: <> @@ -46,8 +41,7 @@ Ran all test suites matching /stackTraceWithoutMessage.test.js/i." `; exports[`Stack Trace prints a stack trace for matching errors 1`] = ` -"Seed: <> -Test Suites: 1 failed, 1 total +"Test Suites: 1 failed, 1 total Tests: 1 failed, 1 total Snapshots: 0 total Time: <> @@ -55,8 +49,7 @@ Ran all test suites matching /stackTrace.test.js/i." `; exports[`Stack Trace prints a stack trace for runtime errors 1`] = ` -"Seed: <> -Test Suites: 1 failed, 1 total +"Test Suites: 1 failed, 1 total Tests: 0 total Snapshots: 0 total Time: <> diff --git a/e2e/__tests__/__snapshots__/testMatch.test.ts.snap b/e2e/__tests__/__snapshots__/testMatch.test.ts.snap index 8062f817483e..ed8312fe8a59 100644 --- a/e2e/__tests__/__snapshots__/testMatch.test.ts.snap +++ b/e2e/__tests__/__snapshots__/testMatch.test.ts.snap @@ -1,8 +1,7 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP exports[`testMatch should able to match file with cjs and mjs extension 1`] = ` -"Seed: <> -Test Suites: 2 passed, 2 total +"Test Suites: 2 passed, 2 total Tests: 2 passed, 2 total Snapshots: 0 total Time: <> diff --git a/e2e/__tests__/__snapshots__/testNamePattern.test.ts.snap b/e2e/__tests__/__snapshots__/testNamePattern.test.ts.snap index 9ccff53ec846..9c72df9c12dd 100644 --- a/e2e/__tests__/__snapshots__/testNamePattern.test.ts.snap +++ b/e2e/__tests__/__snapshots__/testNamePattern.test.ts.snap @@ -1,8 +1,7 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP exports[`testNamePattern 1`] = ` -"Seed: <> -Test Suites: 1 passed, 1 total +"Test Suites: 1 passed, 1 total Tests: 3 skipped, 2 passed, 5 total Snapshots: 0 total Time: <> diff --git a/e2e/__tests__/__snapshots__/testNamePatternSkipped.test.ts.snap b/e2e/__tests__/__snapshots__/testNamePatternSkipped.test.ts.snap index 76f6018a11b5..fb6226de5485 100644 --- a/e2e/__tests__/__snapshots__/testNamePatternSkipped.test.ts.snap +++ b/e2e/__tests__/__snapshots__/testNamePatternSkipped.test.ts.snap @@ -1,8 +1,7 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP exports[`testNamePattern skipped 1`] = ` -"Seed: <> -Test Suites: 1 passed, 1 total +"Test Suites: 1 passed, 1 total Tests: 1 skipped, 1 passed, 2 total Snapshots: 0 total Time: <> diff --git a/e2e/__tests__/__snapshots__/timeouts.test.ts.snap b/e2e/__tests__/__snapshots__/timeouts.test.ts.snap index 3a3a682f2754..45abed912e71 100644 --- a/e2e/__tests__/__snapshots__/timeouts.test.ts.snap +++ b/e2e/__tests__/__snapshots__/timeouts.test.ts.snap @@ -6,8 +6,7 @@ exports[`does not exceed the command line testTimeout 1`] = ` `; exports[`does not exceed the command line testTimeout 2`] = ` -"Seed: <> -Test Suites: 1 passed, 1 total +"Test Suites: 1 passed, 1 total Tests: 1 passed, 1 total Snapshots: 0 total Time: <> @@ -20,8 +19,7 @@ exports[`does not exceed the timeout 1`] = ` `; exports[`does not exceed the timeout 2`] = ` -"Seed: <> -Test Suites: 1 passed, 1 total +"Test Suites: 1 passed, 1 total Tests: 1 passed, 1 total Snapshots: 0 total Time: <> @@ -29,8 +27,7 @@ Ran all test suites." `; exports[`exceeds the command line testTimeout 1`] = ` -"Seed: <> -Test Suites: 1 failed, 1 total +"Test Suites: 1 failed, 1 total Tests: 1 failed, 1 total Snapshots: 0 total Time: <> @@ -38,8 +35,7 @@ Ran all test suites." `; exports[`exceeds the timeout 1`] = ` -"Seed: <> -Test Suites: 1 failed, 1 total +"Test Suites: 1 failed, 1 total Tests: 1 failed, 1 total Snapshots: 0 total Time: <> diff --git a/e2e/__tests__/__snapshots__/watchModeOnlyFailed.test.ts.snap b/e2e/__tests__/__snapshots__/watchModeOnlyFailed.test.ts.snap index c1b08fbd2ff8..1eb721361319 100644 --- a/e2e/__tests__/__snapshots__/watchModeOnlyFailed.test.ts.snap +++ b/e2e/__tests__/__snapshots__/watchModeOnlyFailed.test.ts.snap @@ -35,8 +35,7 @@ exports[`can press "f" to run only failed tests: test results 2`] = ` `; exports[`can press "f" to run only failed tests: test summary 1`] = ` -"Seed: <> -Test Suites: 1 failed, 1 passed, 2 total +"Test Suites: 1 failed, 1 passed, 2 total Tests: 1 failed, 1 passed, 2 total Snapshots: 0 total Time: <> @@ -44,8 +43,7 @@ Ran all test suites." `; exports[`can press "f" to run only failed tests: test summary 2`] = ` -"Seed: <> -Test Suites: 1 failed, 1 total +"Test Suites: 1 failed, 1 total Tests: 1 failed, 1 total Snapshots: 0 total Time: <> diff --git a/e2e/__tests__/__snapshots__/watchModePatterns.test.ts.snap b/e2e/__tests__/__snapshots__/watchModePatterns.test.ts.snap index c7f480f3f368..1a0e4d7b91ae 100644 --- a/e2e/__tests__/__snapshots__/watchModePatterns.test.ts.snap +++ b/e2e/__tests__/__snapshots__/watchModePatterns.test.ts.snap @@ -54,8 +54,7 @@ exports[`can press "p" to filter by file name: test results 2`] = ` `; exports[`can press "p" to filter by file name: test summary 1`] = ` -"Seed: <> -Test Suites: 2 passed, 2 total +"Test Suites: 2 passed, 2 total Tests: 4 passed, 4 total Snapshots: 0 total Time: <> @@ -63,8 +62,7 @@ Ran all test suites." `; exports[`can press "p" to filter by file name: test summary 2`] = ` -"Seed: <> -Test Suites: 1 passed, 1 total +"Test Suites: 1 passed, 1 total Tests: 2 passed, 2 total Snapshots: 0 total Time: <> @@ -110,8 +108,7 @@ PASS __tests__/foo.spec.js" `; exports[`can press "t" to filter by test name: test summary 1`] = ` -"Seed: <> -Test Suites: 2 passed, 2 total +"Test Suites: 2 passed, 2 total Tests: 4 passed, 4 total Snapshots: 0 total Time: <> @@ -119,8 +116,7 @@ Ran all test suites." `; exports[`can press "t" to filter by test name: test summary 2`] = ` -"Seed: <> -Test Suites: 2 passed, 2 total +"Test Suites: 2 passed, 2 total Tests: 2 skipped, 2 passed, 4 total Snapshots: 0 total Time: <> diff --git a/e2e/__tests__/__snapshots__/watchModeUpdateSnapshot.test.ts.snap b/e2e/__tests__/__snapshots__/watchModeUpdateSnapshot.test.ts.snap index 19218bc4f4a8..f13279f7e2b1 100644 --- a/e2e/__tests__/__snapshots__/watchModeUpdateSnapshot.test.ts.snap +++ b/e2e/__tests__/__snapshots__/watchModeUpdateSnapshot.test.ts.snap @@ -33,8 +33,7 @@ Snapshot Summary `; exports[`can press "u" to update snapshots: test summary 1`] = ` -"Seed: <> -Test Suites: 1 failed, 1 total +"Test Suites: 1 failed, 1 total Tests: 1 failed, 1 total Snapshots: 1 failed, 1 total Time: <> @@ -42,8 +41,7 @@ Ran all test suites." `; exports[`can press "u" to update snapshots: test summary 2`] = ` -"Seed: <> -Test Suites: 1 passed, 1 total +"Test Suites: 1 passed, 1 total Tests: 1 passed, 1 total Snapshots: 1 updated, 1 total Time: <> diff --git a/e2e/__tests__/__snapshots__/workerRestarting.test.ts.snap b/e2e/__tests__/__snapshots__/workerRestarting.test.ts.snap index c2fee7456043..edf50a0f2d69 100644 --- a/e2e/__tests__/__snapshots__/workerRestarting.test.ts.snap +++ b/e2e/__tests__/__snapshots__/workerRestarting.test.ts.snap @@ -1,8 +1,7 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP exports[`all 3 test files should complete 1`] = ` -"Seed: <> -Test Suites: 3 passed, 3 total +"Test Suites: 3 passed, 3 total Tests: 3 passed, 3 total Snapshots: 0 total Time: <> diff --git a/e2e/__tests__/domDiffing.test.ts b/e2e/__tests__/domDiffing.test.ts index feb0625b724d..b61baff2d6eb 100644 --- a/e2e/__tests__/domDiffing.test.ts +++ b/e2e/__tests__/domDiffing.test.ts @@ -6,11 +6,11 @@ * */ -import {replaceSeed, replaceTime} from '../Utils'; +import {replaceTime} from '../Utils'; import runJest from '../runJest'; test('should work without error', () => { const output = runJest('dom-diffing'); expect(output.failed).toBe(true); - expect(replaceSeed(replaceTime(output.stderr))).toMatchSnapshot(); + expect(replaceTime(output.stderr)).toMatchSnapshot(); }); diff --git a/e2e/__tests__/environmentAfterTeardown.test.ts b/e2e/__tests__/environmentAfterTeardown.test.ts index 5f4041877a6f..103e33d1d43c 100644 --- a/e2e/__tests__/environmentAfterTeardown.test.ts +++ b/e2e/__tests__/environmentAfterTeardown.test.ts @@ -9,10 +9,10 @@ import runJest from '../runJest'; test('prints useful error for environment methods after test is done', () => { const {stderr} = runJest('environment-after-teardown'); - const interestingLines = stderr.split('\n').slice(10, 19).join('\n'); + const interestingLines = stderr.split('\n').slice(9, 18).join('\n'); expect(interestingLines).toMatchSnapshot(); - expect(stderr.split('\n')[10]).toBe( + expect(stderr.split('\n')[9]).toBe( 'ReferenceError: You are trying to access a property or method of the Jest environment after it has been torn down. From __tests__/afterTeardown.test.js.', ); }); diff --git a/e2e/__tests__/requireAfterTeardown.test.ts b/e2e/__tests__/requireAfterTeardown.test.ts index c28b2a20dd44..c7e2b1d3f898 100644 --- a/e2e/__tests__/requireAfterTeardown.test.ts +++ b/e2e/__tests__/requireAfterTeardown.test.ts @@ -10,10 +10,10 @@ import runJest from '../runJest'; test('prints useful error for requires after test is done', () => { const {stderr} = runJest('require-after-teardown'); - const interestingLines = stderr.split('\n').slice(10, 19).join('\n'); + const interestingLines = stderr.split('\n').slice(9, 18).join('\n'); expect(interestingLines).toMatchSnapshot(); - expect(stderr.split('\n')[20]).toMatch( + expect(stderr.split('\n')[19]).toMatch( new RegExp('(__tests__/lateRequire.test.js:11:20)'), ); }); From ebdf7cb1468a6133e8275147dda515b5ff96ce3f Mon Sep 17 00:00:00 2001 From: josh <41476440+Joshua-Hwang@users.noreply.github.com> Date: Sat, 8 Oct 2022 17:53:03 +1000 Subject: [PATCH 25/53] added new e2e test for --showSeed --- e2e/Utils.ts | 6 +-- .../__snapshots__/showSeed.test.ts.snap | 28 ++++++++++ e2e/__tests__/showSeed.test.ts | 54 +++++++++++++++++++ 3 files changed, 85 insertions(+), 3 deletions(-) create mode 100644 e2e/__tests__/__snapshots__/showSeed.test.ts.snap create mode 100644 e2e/__tests__/showSeed.test.ts diff --git a/e2e/Utils.ts b/e2e/Utils.ts index c2d3f62cd61f..f46860eb286e 100644 --- a/e2e/Utils.ts +++ b/e2e/Utils.ts @@ -204,7 +204,7 @@ export const extractSummary = (stdout: string) => { const match = stdout .replace(/(?:\\[rn])+/g, '\n') .match( - /Test Suites:.*\nTests.*\nSnapshots.*\nTime.*(\nRan all test suites)*.*\n*$/gm, + /(Seed:.*\n)?Test Suites:.*\nTests.*\nSnapshots.*\nTime.*(\nRan all test suites)*.*\n*$/gm, ); if (!match) { throw new Error(dedent` @@ -214,7 +214,7 @@ export const extractSummary = (stdout: string) => { `); } - const summary = replaceSeed(replaceTime(match[0])); + const summary = replaceTime(match[0]); const rest = stdout .replace(match[0], '') @@ -257,7 +257,7 @@ export const extractSummaries = ( stdout: string, ): Array<{rest: string; summary: string}> => { const regex = - /Test Suites:.*\nTests.*\nSnapshots.*\nTime.*(\nRan all test suites)*.*\n*$/gm; + /(Seed:.*\n)?Test Suites:.*\nTests.*\nSnapshots.*\nTime.*(\nRan all test suites)*.*\n*$/gm; let match = regex.exec(stdout); const matches: Array = []; diff --git a/e2e/__tests__/__snapshots__/showSeed.test.ts.snap b/e2e/__tests__/__snapshots__/showSeed.test.ts.snap new file mode 100644 index 000000000000..cbefff8a9ffa --- /dev/null +++ b/e2e/__tests__/__snapshots__/showSeed.test.ts.snap @@ -0,0 +1,28 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`--seed --showSeed will show the seed in the report 1`] = ` +"Seed: <> +Test Suites: 2 passed, 2 total +Tests: 2 passed, 2 total +Snapshots: 0 total +Time: <> +Ran all test suites." +`; + +exports[`--seed will force the report to show the seed in the report 1`] = ` +"Seed: <> +Test Suites: 2 passed, 2 total +Tests: 2 passed, 2 total +Snapshots: 0 total +Time: <> +Ran all test suites." +`; + +exports[`--showSeed changes report to output seed 1`] = ` +"Seed: <> +Test Suites: 2 failed, 5 passed, 7 total +Tests: 15 failed, 11 skipped, 53 passed, 79 total +Snapshots: 0 total +Time: <> +Ran all test suites." +`; diff --git a/e2e/__tests__/showSeed.test.ts b/e2e/__tests__/showSeed.test.ts new file mode 100644 index 000000000000..8607f4f37675 --- /dev/null +++ b/e2e/__tests__/showSeed.test.ts @@ -0,0 +1,54 @@ +/** + * 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'; +import { extractSummary, replaceSeed } from '../Utils'; + +test('--showSeed changes report to output seed', () => { + const dir = path.resolve(__dirname, '../each'); + + let {stderr} = runJest(dir, [ + '--showSeed', + '--no-cache', + // Make the snapshot flag stable on CI. + '--ci', + ]); + + const summary = replaceSeed(extractSummary(stderr).summary); + + expect(summary).toMatchSnapshot(); +}); + +test('--seed will force the report to show the seed in the report', () => { + const dir = path.resolve(__dirname, '../jest-object'); + + let {stderr} = runJest(dir, [ + '--seed', + '1234', + '--ci', + ]); + + const summary = replaceSeed(extractSummary(stderr).summary); + + expect(summary).toMatchSnapshot(); +}); + +test('--seed --showSeed will show the seed in the report', () => { + const dir = path.resolve(__dirname, '../jest-object'); + + let {stderr} = runJest(dir, [ + '--showSeed', + '--seed', + '1234', + '--ci', + ]); + + const summary = replaceSeed(extractSummary(stderr).summary); + + expect(summary).toMatchSnapshot(); +}); From 116bdca68993311269bff0eec7ac0fda53d42746 Mon Sep 17 00:00:00 2001 From: josh <41476440+Joshua-Hwang@users.noreply.github.com> Date: Sat, 8 Oct 2022 17:53:29 +1000 Subject: [PATCH 26/53] linting fix --- e2e/__tests__/showSeed.test.ts | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-) diff --git a/e2e/__tests__/showSeed.test.ts b/e2e/__tests__/showSeed.test.ts index 8607f4f37675..7604ecac868f 100644 --- a/e2e/__tests__/showSeed.test.ts +++ b/e2e/__tests__/showSeed.test.ts @@ -6,13 +6,13 @@ */ import * as path from 'path'; +import {extractSummary, replaceSeed} from '../Utils'; import runJest from '../runJest'; -import { extractSummary, replaceSeed } from '../Utils'; test('--showSeed changes report to output seed', () => { const dir = path.resolve(__dirname, '../each'); - let {stderr} = runJest(dir, [ + const {stderr} = runJest(dir, [ '--showSeed', '--no-cache', // Make the snapshot flag stable on CI. @@ -27,11 +27,7 @@ test('--showSeed changes report to output seed', () => { test('--seed will force the report to show the seed in the report', () => { const dir = path.resolve(__dirname, '../jest-object'); - let {stderr} = runJest(dir, [ - '--seed', - '1234', - '--ci', - ]); + const {stderr} = runJest(dir, ['--seed', '1234', '--ci']); const summary = replaceSeed(extractSummary(stderr).summary); @@ -41,12 +37,7 @@ test('--seed will force the report to show the seed in the report', () => { test('--seed --showSeed will show the seed in the report', () => { const dir = path.resolve(__dirname, '../jest-object'); - let {stderr} = runJest(dir, [ - '--showSeed', - '--seed', - '1234', - '--ci', - ]); + const {stderr} = runJest(dir, ['--showSeed', '--seed', '1234', '--ci']); const summary = replaceSeed(extractSummary(stderr).summary); From c7d196a9c0bfa6e7289ffa631e5548d1c2e84c2c Mon Sep 17 00:00:00 2001 From: josh <41476440+Joshua-Hwang@users.noreply.github.com> Date: Sat, 8 Oct 2022 22:36:13 +1000 Subject: [PATCH 27/53] added showseed docs --- docs/CLI.md | 24 +++++++++++++++++++++--- docs/JestObjectAPI.md | 2 +- 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/docs/CLI.md b/docs/CLI.md index 23619db3bd56..318fd920c224 100644 --- a/docs/CLI.md +++ b/docs/CLI.md @@ -352,14 +352,18 @@ The default regex matching works fine on small runs, but becomes slow if provide ### `--seed=` -Sets a seed value that can be retrieved in a test file via [`jest.getSeed()`](JestObjectAPI.md#jestgetseed). If this option is not specified Jest will randomly generate the value. - -The seed value must be between `-0x80000000` and `0x7fffffff` inclusive. +Sets a seed value that can be retrieved in a test file via [`jest.getSeed()`](JestObjectAPI.md#jestgetseed). If this option is not specified Jest will randomly generate the value. The seed value must be between `-0x80000000` and `0x7fffffff` inclusive. ```bash jest --seed=1324 ``` +:::tip + +If this option is not specified Jest will randomly generate the value. You can use the [`--showSeed`](#--showseed) flag to print the seed in the test report summary. + +::: + ### `--selectProjects ... ` Run the tests of the specified projects. Jest uses the attribute `displayName` in the configuration to identify each project. If you use this option, you should provide a `displayName` to all your projects. @@ -390,6 +394,20 @@ jest --shard=3/3 Print your Jest config and then exits. +### `--showSeed` + +Prints the seed value in the test report summary. See [`--seed=`](#--seednum) for the details. + +An example output, the first line shows the seed used. +``` +Seed: 1831310091 +Test Suites: 2 failed, 5 passed, 7 total +Tests: 15 failed, 11 skipped, 53 passed, 79 total +Snapshots: 0 total +Time: 1.138 s +Ran all test suites. +``` + ### `--silent` Prevent tests from printing messages through the console. diff --git a/docs/JestObjectAPI.md b/docs/JestObjectAPI.md index 034d3a231d2c..6314b7f0797c 100644 --- a/docs/JestObjectAPI.md +++ b/docs/JestObjectAPI.md @@ -914,7 +914,7 @@ Every time Jest runs a seed value is randomly generated which you could use in a :::tip -You can manually set this value via the [`--seed=`](CLI.md#--seednum) CLI argument. +Use the [`--showSeed`](CLI.md#--showseed) flag to print the seed in the test report summary. To manually set the value of the seed use [`--seed=`](CLI.md#--seednum) CLI argument. ::: From d2af3a63f9d9929b86c938b3a25a11805a8ae51e Mon Sep 17 00:00:00 2001 From: josh <41476440+Joshua-Hwang@users.noreply.github.com> Date: Sat, 8 Oct 2022 22:37:43 +1000 Subject: [PATCH 28/53] showSeed is the only way to print the seed --- packages/jest-config/src/normalize.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/jest-config/src/normalize.ts b/packages/jest-config/src/normalize.ts index f6d70e90a82e..183ac8bf7728 100644 --- a/packages/jest-config/src/normalize.ts +++ b/packages/jest-config/src/normalize.ts @@ -1021,7 +1021,7 @@ export default async function normalize( newOptions.onlyChanged = newOptions.watch; } - newOptions.showSeed = argv.showSeed || !!argv.seed; + newOptions.showSeed = argv.showSeed; // xoroshiro128plus is used in v8 and is used here (at time of writing) newOptions.seed = From 2ea7dc69e9d4a43be35299ba22b04009c9bf6c6e Mon Sep 17 00:00:00 2001 From: josh <41476440+Joshua-Hwang@users.noreply.github.com> Date: Sat, 8 Oct 2022 22:38:28 +1000 Subject: [PATCH 29/53] e2e tests related are updated --- e2e/__tests__/jestObject.test.ts | 2 +- e2e/__tests__/showSeed.test.ts | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/e2e/__tests__/jestObject.test.ts b/e2e/__tests__/jestObject.test.ts index 53b5ce2ce05e..0818da27bc9f 100644 --- a/e2e/__tests__/jestObject.test.ts +++ b/e2e/__tests__/jestObject.test.ts @@ -15,7 +15,7 @@ test('passes with seed', () => { expect(result.exitCode).toBe(0); }); -test('failes with wrong seed', () => { +test('fails with wrong seed', () => { const result = runJest(dir, ['get-seed.test.js', '--seed', '1111']); expect(result.exitCode).toBe(1); }); diff --git a/e2e/__tests__/showSeed.test.ts b/e2e/__tests__/showSeed.test.ts index 7604ecac868f..a168673f77d0 100644 --- a/e2e/__tests__/showSeed.test.ts +++ b/e2e/__tests__/showSeed.test.ts @@ -24,12 +24,12 @@ test('--showSeed changes report to output seed', () => { expect(summary).toMatchSnapshot(); }); -test('--seed will force the report to show the seed in the report', () => { +test('if --showSeed is not present the report will not show the seed', () => { const dir = path.resolve(__dirname, '../jest-object'); const {stderr} = runJest(dir, ['--seed', '1234', '--ci']); - const summary = replaceSeed(extractSummary(stderr).summary); + const summary = extractSummary(stderr).summary; expect(summary).toMatchSnapshot(); }); From b9b8abfc9fd829637dde1197c006415fe8f57620 Mon Sep 17 00:00:00 2001 From: josh <41476440+Joshua-Hwang@users.noreply.github.com> Date: Sat, 8 Oct 2022 22:40:01 +1000 Subject: [PATCH 30/53] snapshots updated --- e2e/__tests__/__snapshots__/showConfig.test.ts.snap | 1 - e2e/__tests__/__snapshots__/showSeed.test.ts.snap | 13 ++++++------- .../__snapshots__/timeoutsLegacy.test.ts.snap | 9 +++------ .../__snapshots__/SummaryReporter.test.js.snap | 4 ---- 4 files changed, 9 insertions(+), 18 deletions(-) diff --git a/e2e/__tests__/__snapshots__/showConfig.test.ts.snap b/e2e/__tests__/__snapshots__/showConfig.test.ts.snap index 98d2fcb2e79b..79a0e38b919b 100644 --- a/e2e/__tests__/__snapshots__/showConfig.test.ts.snap +++ b/e2e/__tests__/__snapshots__/showConfig.test.ts.snap @@ -126,7 +126,6 @@ exports[`--showConfig outputs config info and exits 1`] = ` "rootDir": "<>", "runTestsByPath": false, "seed": <>, - "showSeed": false, "skipFilter": false, "snapshotFormat": { "escapeString": false, diff --git a/e2e/__tests__/__snapshots__/showSeed.test.ts.snap b/e2e/__tests__/__snapshots__/showSeed.test.ts.snap index cbefff8a9ffa..f9124a83fd32 100644 --- a/e2e/__tests__/__snapshots__/showSeed.test.ts.snap +++ b/e2e/__tests__/__snapshots__/showSeed.test.ts.snap @@ -9,19 +9,18 @@ Time: <> Ran all test suites." `; -exports[`--seed will force the report to show the seed in the report 1`] = ` +exports[`--showSeed changes report to output seed 1`] = ` "Seed: <> -Test Suites: 2 passed, 2 total -Tests: 2 passed, 2 total +Test Suites: 2 failed, 5 passed, 7 total +Tests: 15 failed, 11 skipped, 53 passed, 79 total Snapshots: 0 total Time: <> Ran all test suites." `; -exports[`--showSeed changes report to output seed 1`] = ` -"Seed: <> -Test Suites: 2 failed, 5 passed, 7 total -Tests: 15 failed, 11 skipped, 53 passed, 79 total +exports[`if --showSeed is not present the report will not show the seed 1`] = ` +"Test Suites: 2 passed, 2 total +Tests: 2 passed, 2 total Snapshots: 0 total Time: <> Ran all test suites." diff --git a/e2e/__tests__/__snapshots__/timeoutsLegacy.test.ts.snap b/e2e/__tests__/__snapshots__/timeoutsLegacy.test.ts.snap index f76ec82ba92c..1f76f9f4b47f 100644 --- a/e2e/__tests__/__snapshots__/timeoutsLegacy.test.ts.snap +++ b/e2e/__tests__/__snapshots__/timeoutsLegacy.test.ts.snap @@ -1,8 +1,7 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP exports[`can read and write jasmine.DEFAULT_TIMEOUT_INTERVAL 1`] = ` -"Seed: <> -Test Suites: 1 passed, 1 total +"Test Suites: 1 passed, 1 total Tests: 1 passed, 1 total Snapshots: 0 total Time: <> @@ -15,8 +14,7 @@ exports[`does not exceed the timeout using jasmine.DEFAULT_TIMEOUT_INTERVAL 1`] `; exports[`does not exceed the timeout using jasmine.DEFAULT_TIMEOUT_INTERVAL 2`] = ` -"Seed: <> -Test Suites: 1 passed, 1 total +"Test Suites: 1 passed, 1 total Tests: 1 passed, 1 total Snapshots: 0 total Time: <> @@ -24,8 +22,7 @@ Ran all test suites." `; exports[`exceeds the timeout set using jasmine.DEFAULT_TIMEOUT_INTERVAL 1`] = ` -"Seed: <> -Test Suites: 1 failed, 1 total +"Test Suites: 1 failed, 1 total Tests: 1 failed, 1 total Snapshots: 0 total Time: <> diff --git a/packages/jest-reporters/src/__tests__/__snapshots__/SummaryReporter.test.js.snap b/packages/jest-reporters/src/__tests__/__snapshots__/SummaryReporter.test.js.snap index 38238c18f8a6..42e5e5366851 100644 --- a/packages/jest-reporters/src/__tests__/__snapshots__/SummaryReporter.test.js.snap +++ b/packages/jest-reporters/src/__tests__/__snapshots__/SummaryReporter.test.js.snap @@ -10,7 +10,6 @@ exports[`snapshots all have results (after update) 1`] = ` ↳ ../path/to/suite_one • unchecked snapshot 1 -Seed: XXXX Test Suites: 1 failed, 1 total Tests: 1 failed, 1 total Snapshots: 1 failed, 1 removed, 1 file removed, 1 updated, 1 written, 2 passed, 2 total @@ -29,7 +28,6 @@ exports[`snapshots all have results (no update) 1`] = ` ↳ ../path/to/suite_one • unchecked snapshot 1 -Seed: XXXX Test Suites: 1 failed, 1 total Tests: 1 failed, 1 total Snapshots: 1 failed, 1 obsolete, 1 file obsolete, 1 updated, 1 written, 2 passed, 2 total @@ -42,7 +40,6 @@ exports[`snapshots needs update with npm test 1`] = ` "Snapshot Summary › 2 snapshots failed from 1 test suite. Inspect your code changes or run \`npm test -- -u\` to update them. -Seed: XXXX Test Suites: 1 failed, 1 total Tests: 1 failed, 1 total Snapshots: 2 failed, 2 total @@ -55,7 +52,6 @@ exports[`snapshots needs update with yarn test 1`] = ` "Snapshot Summary › 2 snapshots failed from 1 test suite. Inspect your code changes or run \`yarn test -u\` to update them. -Seed: XXXX Test Suites: 1 failed, 1 total Tests: 1 failed, 1 total Snapshots: 2 failed, 2 total From 679521b75b859ffd1aab29218a3d185153e4491f Mon Sep 17 00:00:00 2001 From: josh <41476440+Joshua-Hwang@users.noreply.github.com> Date: Sat, 8 Oct 2022 23:08:15 +1000 Subject: [PATCH 31/53] added showSeed to config --- packages/jest-config/src/ValidConfig.ts | 1 + packages/jest-config/src/normalize.ts | 3 ++- packages/jest-types/src/Config.ts | 1 + 3 files changed, 4 insertions(+), 1 deletion(-) diff --git a/packages/jest-config/src/ValidConfig.ts b/packages/jest-config/src/ValidConfig.ts index 1526b0cbbeb6..5239ffd8709d 100644 --- a/packages/jest-config/src/ValidConfig.ts +++ b/packages/jest-config/src/ValidConfig.ts @@ -137,6 +137,7 @@ const initialOptions: Config.InitialOptions = { sandboxInjectedGlobals: [], setupFiles: ['/setup.js'], setupFilesAfterEnv: ['/testSetupFile.js'], + showSeed: false, silent: true, skipFilter: false, skipNodeResolution: false, diff --git a/packages/jest-config/src/normalize.ts b/packages/jest-config/src/normalize.ts index 183ac8bf7728..7badae2427ab 100644 --- a/packages/jest-config/src/normalize.ts +++ b/packages/jest-config/src/normalize.ts @@ -918,6 +918,7 @@ export default async function normalize( case 'runTestsByPath': case 'sandboxInjectedGlobals': case 'silent': + case 'showSeed': case 'skipFilter': case 'skipNodeResolution': case 'slowTestThreshold': @@ -1021,7 +1022,7 @@ export default async function normalize( newOptions.onlyChanged = newOptions.watch; } - newOptions.showSeed = argv.showSeed; + newOptions.showSeed = newOptions.showSeed || argv.showSeed; // xoroshiro128plus is used in v8 and is used here (at time of writing) newOptions.seed = diff --git a/packages/jest-types/src/Config.ts b/packages/jest-types/src/Config.ts index 1ac0ab890dd3..c8cfebd40625 100644 --- a/packages/jest-types/src/Config.ts +++ b/packages/jest-types/src/Config.ts @@ -291,6 +291,7 @@ export type InitialOptions = Partial<{ sandboxInjectedGlobals: Array; setupFiles: Array; setupFilesAfterEnv: Array; + showSeed: boolean; silent: boolean; skipFilter: boolean; skipNodeResolution: boolean; From adda4f71dbed5ecf731fa850ec008b6fbdcb917e Mon Sep 17 00:00:00 2001 From: josh <41476440+Joshua-Hwang@users.noreply.github.com> Date: Sat, 8 Oct 2022 23:17:39 +1000 Subject: [PATCH 32/53] added e2e test for showSeed config --- e2e/__tests__/__snapshots__/showSeed.test.ts.snap | 9 +++++++++ e2e/__tests__/showSeed.test.ts | 10 ++++++++++ e2e/jest-object/different-config.json | 4 ++++ 3 files changed, 23 insertions(+) create mode 100644 e2e/jest-object/different-config.json diff --git a/e2e/__tests__/__snapshots__/showSeed.test.ts.snap b/e2e/__tests__/__snapshots__/showSeed.test.ts.snap index f9124a83fd32..ce4c83bfea7b 100644 --- a/e2e/__tests__/__snapshots__/showSeed.test.ts.snap +++ b/e2e/__tests__/__snapshots__/showSeed.test.ts.snap @@ -25,3 +25,12 @@ Snapshots: 0 total Time: <> Ran all test suites." `; + +exports[`if showSeed is present in the config the report will show the seed 1`] = ` +"Seed: 1234 +Test Suites: 2 passed, 2 total +Tests: 2 passed, 2 total +Snapshots: 0 total +Time: <> +Ran all test suites." +`; diff --git a/e2e/__tests__/showSeed.test.ts b/e2e/__tests__/showSeed.test.ts index a168673f77d0..6af2247e55b2 100644 --- a/e2e/__tests__/showSeed.test.ts +++ b/e2e/__tests__/showSeed.test.ts @@ -34,6 +34,16 @@ test('if --showSeed is not present the report will not show the seed', () => { expect(summary).toMatchSnapshot(); }); +test('if showSeed is present in the config the report will show the seed', () => { + const dir = path.resolve(__dirname, '../jest-object'); + + const {stderr} = runJest(dir, ['--seed', '1234', '--ci', '--config', 'different-config.json']); + + const summary = extractSummary(stderr).summary; + + expect(summary).toMatchSnapshot(); +}); + test('--seed --showSeed will show the seed in the report', () => { const dir = path.resolve(__dirname, '../jest-object'); diff --git a/e2e/jest-object/different-config.json b/e2e/jest-object/different-config.json new file mode 100644 index 000000000000..ae9b2166eaff --- /dev/null +++ b/e2e/jest-object/different-config.json @@ -0,0 +1,4 @@ +{ + "displayName": "Config from different-config.json file", + "showSeed": true +} From 01ac6f38ac0f06cf1df68bbb77534d87691f0aeb Mon Sep 17 00:00:00 2001 From: josh <41476440+Joshua-Hwang@users.noreply.github.com> Date: Sat, 8 Oct 2022 23:28:40 +1000 Subject: [PATCH 33/53] documented showSeed config --- docs/Configuration.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/docs/Configuration.md b/docs/Configuration.md index 5ecbeef85358..2b9f4f0a28c1 100644 --- a/docs/Configuration.md +++ b/docs/Configuration.md @@ -1614,6 +1614,12 @@ const config: Config = { export default config; ``` +### `showSeed` \[boolean] + +Default: `false` + +The equivalent of the [`--showSeed`](CLI.md#--showseed) flag to print the seed in the test report summary. + ### `slowTestThreshold` \[number] Default: `5` From 71c04c402eba4ca94fa4490cd2fdd11d2b416210 Mon Sep 17 00:00:00 2001 From: josh <41476440+Joshua-Hwang@users.noreply.github.com> Date: Sun, 9 Oct 2022 08:30:08 +1000 Subject: [PATCH 34/53] updated docs --- docs/CLI.md | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) diff --git a/docs/CLI.md b/docs/CLI.md index 318fd920c224..7c83d00f3917 100644 --- a/docs/CLI.md +++ b/docs/CLI.md @@ -352,7 +352,7 @@ The default regex matching works fine on small runs, but becomes slow if provide ### `--seed=` -Sets a seed value that can be retrieved in a test file via [`jest.getSeed()`](JestObjectAPI.md#jestgetseed). If this option is not specified Jest will randomly generate the value. The seed value must be between `-0x80000000` and `0x7fffffff` inclusive. +Sets a seed value that can be retrieved in a test file via [`jest.getSeed()`](JestObjectAPI.md#jestgetseed). The seed value must be between `-0x80000000` and `0x7fffffff` inclusive. ```bash jest --seed=1324 @@ -398,16 +398,6 @@ Print your Jest config and then exits. Prints the seed value in the test report summary. See [`--seed=`](#--seednum) for the details. -An example output, the first line shows the seed used. -``` -Seed: 1831310091 -Test Suites: 2 failed, 5 passed, 7 total -Tests: 15 failed, 11 skipped, 53 passed, 79 total -Snapshots: 0 total -Time: 1.138 s -Ran all test suites. -``` - ### `--silent` Prevent tests from printing messages through the console. From 1fee0a77ded18f9dd0d3c5e775c3254b57b573d5 Mon Sep 17 00:00:00 2001 From: josh <41476440+Joshua-Hwang@users.noreply.github.com> Date: Sun, 9 Oct 2022 08:30:57 +1000 Subject: [PATCH 35/53] globalConfig passed instead and error thrown when seed is not present --- packages/jest-repl/src/cli/runtime-cli.ts | 2 +- .../jest-reporters/src/SummaryReporter.ts | 2 +- .../__snapshots__/getSummary.test.ts.snap | 16 +++++++ .../src/__tests__/getSummary.test.ts | 42 +++++++++++++++++++ packages/jest-reporters/src/getSummary.ts | 17 ++++++-- packages/jest-reporters/src/types.ts | 2 +- packages/jest-runner/src/runTest.ts | 2 +- .../src/__mocks__/createRuntime.js | 5 ++- packages/jest-runtime/src/index.ts | 12 +++--- 9 files changed, 86 insertions(+), 14 deletions(-) create mode 100644 packages/jest-reporters/src/__tests__/__snapshots__/getSummary.test.ts.snap create mode 100644 packages/jest-reporters/src/__tests__/getSummary.test.ts diff --git a/packages/jest-repl/src/cli/runtime-cli.ts b/packages/jest-repl/src/cli/runtime-cli.ts index 6456413f88fc..7cfbb123f197 100644 --- a/packages/jest-repl/src/cli/runtime-cli.ts +++ b/packages/jest-repl/src/cli/runtime-cli.ts @@ -106,7 +106,7 @@ export async function run( sourcesRelatedToTestsInChangedFiles: undefined, }, filePath, - globalConfig.seed, + globalConfig, ); for (const path of projectConfig.setupFiles) { diff --git a/packages/jest-reporters/src/SummaryReporter.ts b/packages/jest-reporters/src/SummaryReporter.ts index 2666812e7837..5704911a0fac 100644 --- a/packages/jest-reporters/src/SummaryReporter.ts +++ b/packages/jest-reporters/src/SummaryReporter.ts @@ -109,8 +109,8 @@ export default class SummaryReporter extends BaseReporter { if (numTotalTestSuites) { let message = getSummary(aggregatedResults, { estimatedTime: this._estimatedTime, - seed: this._globalConfig.seed, showSeed: this._globalConfig.showSeed, + seed: this._globalConfig.seed, }); if (!this._globalConfig.silent) { diff --git a/packages/jest-reporters/src/__tests__/__snapshots__/getSummary.test.ts.snap b/packages/jest-reporters/src/__tests__/__snapshots__/getSummary.test.ts.snap new file mode 100644 index 000000000000..1645fc2db6a9 --- /dev/null +++ b/packages/jest-reporters/src/__tests__/__snapshots__/getSummary.test.ts.snap @@ -0,0 +1,16 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`getSummary does not print seed value when showSeed is false 1`] = ` +"Test Suites: 0 total +Tests: 0 total +Snapshots: 0 total +Time: 1665268154.244 s" +`; + +exports[`getSummary does print seed value when showSeed is true 1`] = ` +"Seed: 55555 +Test Suites: 0 total +Tests: 0 total +Snapshots: 0 total +Time: 1665268154.248 s" +`; diff --git a/packages/jest-reporters/src/__tests__/getSummary.test.ts b/packages/jest-reporters/src/__tests__/getSummary.test.ts new file mode 100644 index 000000000000..7df778661f25 --- /dev/null +++ b/packages/jest-reporters/src/__tests__/getSummary.test.ts @@ -0,0 +1,42 @@ +/** + * 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 { makeEmptyAggregatedTestResult } from '@jest/test-result'; +import getSummary from '../getSummary'; + +describe('getSummary', () => { + test('does not print seed value when showSeed is false', () => { + const summary = getSummary(makeEmptyAggregatedTestResult(), { + estimatedTime: 0, + showSeed: false, + }); + + expect(summary).toMatchSnapshot(); + }); + + test('does print seed value when showSeed is true', () => { + const summary = getSummary(makeEmptyAggregatedTestResult(), { + estimatedTime: 0, + showSeed: true, + seed: 55555, + }); + + expect(summary).toMatchSnapshot(); + }); + + test('throws error is showSeed is true but seed is not present', () => { + expect.assertions(1); + + try { + getSummary(makeEmptyAggregatedTestResult(), { + estimatedTime: 0, + showSeed: true, + }); + } catch (error) { + expect(error).toBeInstanceOf(Error); + } + }); +}) diff --git a/packages/jest-reporters/src/getSummary.ts b/packages/jest-reporters/src/getSummary.ts index c8eb86cf31bf..80dc77b3256b 100644 --- a/packages/jest-reporters/src/getSummary.ts +++ b/packages/jest-reporters/src/getSummary.ts @@ -114,9 +114,17 @@ export default function getSummary( const testsTotal = aggregatedResults.numTotalTests; const width = (options && options.width) || 0; - const seed = `${ - chalk.bold('Seed: ') + (options?.seed?.toString() ?? 'XXXX') - }`; + const optionalLines = [] as string[]; + + if (options?.showSeed) { + if (options?.seed === undefined) { + throw new Error + } + const seed = `${ + chalk.bold('Seed: ') + options.seed.toString() + }`; + optionalLines.push(seed); + } const suites = `${ chalk.bold('Test Suites: ') + @@ -187,8 +195,9 @@ export default function getSummary( }${snapshotsTotal} total`; const time = renderTime(runTime, estimatedTime, width); + return [ - ...(options?.showSeed ? [seed] : []), + ...optionalLines, suites, tests, snapshots, diff --git a/packages/jest-reporters/src/types.ts b/packages/jest-reporters/src/types.ts index 4d85ff3c9bc1..98d131b0061e 100644 --- a/packages/jest-reporters/src/types.ts +++ b/packages/jest-reporters/src/types.ts @@ -60,6 +60,6 @@ export type SummaryOptions = { estimatedTime?: number; roundTime?: boolean; width?: number; - seed?: number; showSeed?: boolean; + seed?: number; }; diff --git a/packages/jest-runner/src/runTest.ts b/packages/jest-runner/src/runTest.ts index 4ebd0b259384..0f3614bce98c 100644 --- a/packages/jest-runner/src/runTest.ts +++ b/packages/jest-runner/src/runTest.ts @@ -196,7 +196,7 @@ async function runTestInternal( context.sourcesRelatedToTestsInChangedFiles, }, path, - globalConfig.seed, + globalConfig, ); let isTornDown = false; diff --git a/packages/jest-runtime/src/__mocks__/createRuntime.js b/packages/jest-runtime/src/__mocks__/createRuntime.js index bea84f2b8d38..30d1e9479006 100644 --- a/packages/jest-runtime/src/__mocks__/createRuntime.js +++ b/packages/jest-runtime/src/__mocks__/createRuntime.js @@ -55,6 +55,8 @@ module.exports = async function createRuntime(filename, projectConfig) { const moduleNameMapper = setupModuleNameMapper(projectConfig, rootDir); const transform = setupTransform(projectConfig, rootDir, cwd); + const globalConfig = makeGlobalConfig(); + projectConfig = makeProjectConfig({ cacheDirectory: getCacheDirectory(), cwd, @@ -77,7 +79,7 @@ module.exports = async function createRuntime(filename, projectConfig) { } const environment = new NodeEnvironment({ - globalConfig: makeGlobalConfig(), + globalConfig, projectConfig, }); environment.global.console = console; @@ -109,6 +111,7 @@ module.exports = async function createRuntime(filename, projectConfig) { sourcesRelatedToTestsInChangedFiles: undefined, }, filename, + globalConfig, ); for (const path of projectConfig.setupFiles) { diff --git a/packages/jest-runtime/src/index.ts b/packages/jest-runtime/src/index.ts index 3cc089367eb7..2847f8b23be8 100644 --- a/packages/jest-runtime/src/index.ts +++ b/packages/jest-runtime/src/index.ts @@ -155,6 +155,7 @@ const supportsNodeColonModulePrefixInRequire = (() => { export default class Runtime { private readonly _cacheFS: Map; private readonly _config: Config.ProjectConfig; + private readonly _globalConfig?: Config.GlobalConfig; private readonly _coverageOptions: ShouldInstrumentOptions; private _currentlyExecutingModulePath: string; private readonly _environment: JestEnvironment; @@ -181,7 +182,6 @@ export default class Runtime { private readonly _esmModuleLinkingMap: WeakMap>; private readonly _testPath: string; private readonly _resolver: Resolver; - private _seed: number; private _shouldAutoMock: boolean; private readonly _shouldMockModuleCache: Map; private readonly _shouldUnmockTransitiveDependenciesCache: Map< @@ -214,13 +214,15 @@ export default class Runtime { cacheFS: Map, coverageOptions: ShouldInstrumentOptions, testPath: string, - seed: number, + // TODO: make mandatory in Jest 30 + globalConfig?: Config.GlobalConfig, ) { this._cacheFS = cacheFS; this._config = config; this._coverageOptions = coverageOptions; this._currentlyExecutingModulePath = ''; this._environment = environment; + this._globalConfig = globalConfig; this._explicitShouldMock = new Map(); this._explicitShouldMockModule = new Map(); this._internalModuleRegistry = new Map(); @@ -244,7 +246,6 @@ export default class Runtime { this._testPath = testPath; this._resolver = resolver; this._scriptTransformer = transformer; - this._seed = seed; this._shouldAutoMock = config.automock; this._sourceMapRegistry = new Map(); this._fileTransforms = new Map(); @@ -2127,12 +2128,13 @@ export default class Runtime { } }, getSeed: () => { - if (this._seed === undefined) { + // TODO: remove this check in Jest 30 + if (this._globalConfig?.seed === undefined) { throw new Error( 'The seed value is not available. Likely you are using older versions of the jest dependencies.', ); } - return this._seed; + return this._globalConfig?.seed; }, getTimerCount: () => _getFakeTimers().getTimerCount(), isMockFunction: this._moduleMocker.isMockFunction, From 7b97aabeb783cfee38c03e54a4fb733271356f5b Mon Sep 17 00:00:00 2001 From: josh <41476440+Joshua-Hwang@users.noreply.github.com> Date: Sun, 9 Oct 2022 08:32:19 +1000 Subject: [PATCH 36/53] lint fix --- e2e/__tests__/showSeed.test.ts | 8 +++++++- packages/jest-reporters/src/SummaryReporter.ts | 2 +- .../src/__tests__/getSummary.test.ts | 6 +++--- packages/jest-reporters/src/getSummary.ts | 16 ++++------------ 4 files changed, 15 insertions(+), 17 deletions(-) diff --git a/e2e/__tests__/showSeed.test.ts b/e2e/__tests__/showSeed.test.ts index 6af2247e55b2..ad5cbe7eb18b 100644 --- a/e2e/__tests__/showSeed.test.ts +++ b/e2e/__tests__/showSeed.test.ts @@ -37,7 +37,13 @@ test('if --showSeed is not present the report will not show the seed', () => { test('if showSeed is present in the config the report will show the seed', () => { const dir = path.resolve(__dirname, '../jest-object'); - const {stderr} = runJest(dir, ['--seed', '1234', '--ci', '--config', 'different-config.json']); + const {stderr} = runJest(dir, [ + '--seed', + '1234', + '--ci', + '--config', + 'different-config.json', + ]); const summary = extractSummary(stderr).summary; diff --git a/packages/jest-reporters/src/SummaryReporter.ts b/packages/jest-reporters/src/SummaryReporter.ts index 5704911a0fac..2666812e7837 100644 --- a/packages/jest-reporters/src/SummaryReporter.ts +++ b/packages/jest-reporters/src/SummaryReporter.ts @@ -109,8 +109,8 @@ export default class SummaryReporter extends BaseReporter { if (numTotalTestSuites) { let message = getSummary(aggregatedResults, { estimatedTime: this._estimatedTime, - showSeed: this._globalConfig.showSeed, seed: this._globalConfig.seed, + showSeed: this._globalConfig.showSeed, }); if (!this._globalConfig.silent) { diff --git a/packages/jest-reporters/src/__tests__/getSummary.test.ts b/packages/jest-reporters/src/__tests__/getSummary.test.ts index 7df778661f25..3359385839b9 100644 --- a/packages/jest-reporters/src/__tests__/getSummary.test.ts +++ b/packages/jest-reporters/src/__tests__/getSummary.test.ts @@ -4,7 +4,7 @@ * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. */ -import { makeEmptyAggregatedTestResult } from '@jest/test-result'; +import {makeEmptyAggregatedTestResult} from '@jest/test-result'; import getSummary from '../getSummary'; describe('getSummary', () => { @@ -20,8 +20,8 @@ describe('getSummary', () => { test('does print seed value when showSeed is true', () => { const summary = getSummary(makeEmptyAggregatedTestResult(), { estimatedTime: 0, - showSeed: true, seed: 55555, + showSeed: true, }); expect(summary).toMatchSnapshot(); @@ -39,4 +39,4 @@ describe('getSummary', () => { expect(error).toBeInstanceOf(Error); } }); -}) +}); diff --git a/packages/jest-reporters/src/getSummary.ts b/packages/jest-reporters/src/getSummary.ts index 80dc77b3256b..a5030f974ae0 100644 --- a/packages/jest-reporters/src/getSummary.ts +++ b/packages/jest-reporters/src/getSummary.ts @@ -114,15 +114,13 @@ export default function getSummary( const testsTotal = aggregatedResults.numTotalTests; const width = (options && options.width) || 0; - const optionalLines = [] as string[]; + const optionalLines = [] as Array; if (options?.showSeed) { if (options?.seed === undefined) { - throw new Error + throw new Error(); } - const seed = `${ - chalk.bold('Seed: ') + options.seed.toString() - }`; + const seed = `${chalk.bold('Seed: ') + options.seed.toString()}`; optionalLines.push(seed); } @@ -196,11 +194,5 @@ export default function getSummary( const time = renderTime(runTime, estimatedTime, width); - return [ - ...optionalLines, - suites, - tests, - snapshots, - time, - ].join('\n'); + return [...optionalLines, suites, tests, snapshots, time].join('\n'); } From 076eb02de73683b9cc99c3d743fde666a64be983 Mon Sep 17 00:00:00 2001 From: josh <41476440+Joshua-Hwang@users.noreply.github.com> Date: Sun, 9 Oct 2022 08:48:13 +1000 Subject: [PATCH 37/53] replace Date.now --- .../__tests__/__snapshots__/getSummary.test.ts.snap | 4 ++-- .../jest-reporters/src/__tests__/getSummary.test.ts | 10 ++++++++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/packages/jest-reporters/src/__tests__/__snapshots__/getSummary.test.ts.snap b/packages/jest-reporters/src/__tests__/__snapshots__/getSummary.test.ts.snap index 1645fc2db6a9..00e39eced7a2 100644 --- a/packages/jest-reporters/src/__tests__/__snapshots__/getSummary.test.ts.snap +++ b/packages/jest-reporters/src/__tests__/__snapshots__/getSummary.test.ts.snap @@ -4,7 +4,7 @@ exports[`getSummary does not print seed value when showSeed is false 1`] = ` "Test Suites: 0 total Tests: 0 total Snapshots: 0 total -Time: 1665268154.244 s" +Time: 0.01 s" `; exports[`getSummary does print seed value when showSeed is true 1`] = ` @@ -12,5 +12,5 @@ exports[`getSummary does print seed value when showSeed is true 1`] = ` Test Suites: 0 total Tests: 0 total Snapshots: 0 total -Time: 1665268154.248 s" +Time: 0.01 s" `; diff --git a/packages/jest-reporters/src/__tests__/getSummary.test.ts b/packages/jest-reporters/src/__tests__/getSummary.test.ts index 3359385839b9..568367853c78 100644 --- a/packages/jest-reporters/src/__tests__/getSummary.test.ts +++ b/packages/jest-reporters/src/__tests__/getSummary.test.ts @@ -7,6 +7,16 @@ import {makeEmptyAggregatedTestResult} from '@jest/test-result'; import getSummary from '../getSummary'; +const now = Date.now; + +beforeEach(() => { + Date.now = () => 10; +}); + +afterEach(() => { + Date.now = now; +}); + describe('getSummary', () => { test('does not print seed value when showSeed is false', () => { const summary = getSummary(makeEmptyAggregatedTestResult(), { From d0eed4afac351c22cd645a6ab3e0eff7436ad808 Mon Sep 17 00:00:00 2001 From: josh <41476440+Joshua-Hwang@users.noreply.github.com> Date: Sun, 9 Oct 2022 19:39:28 +1000 Subject: [PATCH 38/53] added showSeed test --- .../src/__tests__/normalize.test.ts | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/packages/jest-config/src/__tests__/normalize.test.ts b/packages/jest-config/src/__tests__/normalize.test.ts index 629cf498a7c2..4e044128ae58 100644 --- a/packages/jest-config/src/__tests__/normalize.test.ts +++ b/packages/jest-config/src/__tests__/normalize.test.ts @@ -2092,3 +2092,25 @@ describe('seed', () => { expect(options.seed).toBe(4321); }); }); + +describe('showSeed', () => { + test('showSeed is set when argv flag is set', async () => { + const {options} = await normalize({rootDir: '/root/'}, { + showSeed: true, + } as Config.Argv); + expect(options.showSeed).toBe(true); + }); + + test('showSeed is set when the config is set', async () => { + const {options} = await normalize( + {rootDir: '/root/', showSeed: true}, + {} as Config.Argv, + ); + expect(options.showSeed).toBe(true); + }); + + test('showSeed is false when neither is set', async () => { + const {options} = await normalize({rootDir: '/root/'}, {} as Config.Argv); + expect(options.showSeed).toBeFalsy(); + }); +}); From 523b995f9b84202821786859d475c11aca8fe307 Mon Sep 17 00:00:00 2001 From: josh <41476440+Joshua-Hwang@users.noreply.github.com> Date: Sun, 9 Oct 2022 19:39:44 +1000 Subject: [PATCH 39/53] use jest.useFakeTimer instead --- packages/jest-reporters/src/__tests__/getSummary.test.ts | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/packages/jest-reporters/src/__tests__/getSummary.test.ts b/packages/jest-reporters/src/__tests__/getSummary.test.ts index 568367853c78..c581d6722113 100644 --- a/packages/jest-reporters/src/__tests__/getSummary.test.ts +++ b/packages/jest-reporters/src/__tests__/getSummary.test.ts @@ -7,14 +7,13 @@ import {makeEmptyAggregatedTestResult} from '@jest/test-result'; import getSummary from '../getSummary'; -const now = Date.now; - beforeEach(() => { - Date.now = () => 10; + jest.useFakeTimers(); + jest.setSystemTime(10); }); afterEach(() => { - Date.now = now; + jest.useRealTimers(); }); describe('getSummary', () => { From 1328b7bbef0ef7776573f12c51b3e8cd47ef141e Mon Sep 17 00:00:00 2001 From: josh <41476440+Joshua-Hwang@users.noreply.github.com> Date: Sun, 9 Oct 2022 19:44:48 +1000 Subject: [PATCH 40/53] removed optional chaining --- packages/jest-runtime/src/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/jest-runtime/src/index.ts b/packages/jest-runtime/src/index.ts index 2847f8b23be8..7be6cf2db53d 100644 --- a/packages/jest-runtime/src/index.ts +++ b/packages/jest-runtime/src/index.ts @@ -2134,7 +2134,7 @@ export default class Runtime { 'The seed value is not available. Likely you are using older versions of the jest dependencies.', ); } - return this._globalConfig?.seed; + return this._globalConfig.seed; }, getTimerCount: () => _getFakeTimers().getTimerCount(), isMockFunction: this._moduleMocker.isMockFunction, From 1aae6532ad34f251930219282660086c70c2d339 Mon Sep 17 00:00:00 2001 From: josh <41476440+Joshua-Hwang@users.noreply.github.com> Date: Sun, 9 Oct 2022 19:46:17 +1000 Subject: [PATCH 41/53] lint fix and error now has message --- packages/jest-reporters/src/getSummary.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/jest-reporters/src/getSummary.ts b/packages/jest-reporters/src/getSummary.ts index a5030f974ae0..094addb106b8 100644 --- a/packages/jest-reporters/src/getSummary.ts +++ b/packages/jest-reporters/src/getSummary.ts @@ -114,11 +114,11 @@ export default function getSummary( const testsTotal = aggregatedResults.numTotalTests; const width = (options && options.width) || 0; - const optionalLines = [] as Array; + const optionalLines: Array = []; if (options?.showSeed) { if (options?.seed === undefined) { - throw new Error(); + throw new Error('Attempted to display seed but seed value is undefined'); } const seed = `${chalk.bold('Seed: ') + options.seed.toString()}`; optionalLines.push(seed); From d568629e8226e614dcf0f5745503a7b87350efa2 Mon Sep 17 00:00:00 2001 From: josh <41476440+Joshua-Hwang@users.noreply.github.com> Date: Sun, 9 Oct 2022 19:47:24 +1000 Subject: [PATCH 42/53] clarified docs --- docs/CLI.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/docs/CLI.md b/docs/CLI.md index 7c83d00f3917..759181790d7a 100644 --- a/docs/CLI.md +++ b/docs/CLI.md @@ -352,7 +352,7 @@ The default regex matching works fine on small runs, but becomes slow if provide ### `--seed=` -Sets a seed value that can be retrieved in a test file via [`jest.getSeed()`](JestObjectAPI.md#jestgetseed). The seed value must be between `-0x80000000` and `0x7fffffff` inclusive. +Sets a seed value that can be retrieved in a test file via [`jest.getSeed()`](JestObjectAPI.md#jestgetseed). The seed value must be between `-0x80000000` and `0x7fffffff` inclusive (`-2147483648` and `2147483647` in decimal). ```bash jest --seed=1324 @@ -398,6 +398,8 @@ Print your Jest config and then exits. Prints the seed value in the test report summary. See [`--seed=`](#--seednum) for the details. +Can also be set in configuration. See [`showSeed`](Configuration#showseed-boolean). + ### `--silent` Prevent tests from printing messages through the console. From e246b8aa5f207ceb32952dc0dcff34a5c261a385 Mon Sep 17 00:00:00 2001 From: josh <41476440+Joshua-Hwang@users.noreply.github.com> Date: Sun, 9 Oct 2022 19:49:48 +1000 Subject: [PATCH 43/53] Changelog updated --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 475b4d06a297..acdd776269e0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ ### Features - `[@jest/cli, jest-config, @jest/environment, jest-environment-node, jest-environment-jsdom, @jest/reporters, jest-runtime, @jest/types]` Add `getSeed()` to the jest object available at runtime ([#13400](https://github.com/facebook/jest/pull/13400/)) +- `[@jest/cli, jest-config]` `showSeed` will display the seed value in the report can be set via a CLI flag or through the config file ([#13400](https://github.com/facebook/jest/pull/13400/)) - `[jest-config]` Add `readInitialConfig` utility function ([#13356](https://github.com/facebook/jest/pull/13356)) - `[jest-core]` Enable testResultsProcessor to be async ([#13343](https://github.com/facebook/jest/pull/13343)) - `[expect, @jest/expect-utils]` Allow `isA` utility to take a type argument ([#13355](https://github.com/facebook/jest/pull/13355)) From 3efe6fcd4764a3bdf191d58cb9ad0143b7a0e6e9 Mon Sep 17 00:00:00 2001 From: Simen Bekkhus Date: Sun, 9 Oct 2022 08:34:01 -0700 Subject: [PATCH 44/53] tweak changelog --- CHANGELOG.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index acdd776269e0..977ff242a348 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,10 +2,11 @@ ### Features -- `[@jest/cli, jest-config, @jest/environment, jest-environment-node, jest-environment-jsdom, @jest/reporters, jest-runtime, @jest/types]` Add `getSeed()` to the jest object available at runtime ([#13400](https://github.com/facebook/jest/pull/13400/)) -- `[@jest/cli, jest-config]` `showSeed` will display the seed value in the report can be set via a CLI flag or through the config file ([#13400](https://github.com/facebook/jest/pull/13400/)) +- `[@jest/cli, jest-config]` A seed for the test run will be randomly generated, or set by a CLI option ([#13400](https://github.com/facebook/jest/pull/13400)) +- `[@jest/cli, jest-config]` `--show-seed` will display the seed value in the report, and can be set via a CLI flag or through the config file ([#13400](https://github.com/facebook/jest/pull/13400)) - `[jest-config]` Add `readInitialConfig` utility function ([#13356](https://github.com/facebook/jest/pull/13356)) - `[jest-core]` Enable testResultsProcessor to be async ([#13343](https://github.com/facebook/jest/pull/13343)) +- `[@jest/environment, jest-environment-node, jest-environment-jsdom, jest-runtime]` Add `getSeed()` to the `jest` object ([#13400](https://github.com/facebook/jest/pull/13400)) - `[expect, @jest/expect-utils]` Allow `isA` utility to take a type argument ([#13355](https://github.com/facebook/jest/pull/13355)) ### Fixes From 0fb3e79071cd9552b988cd8826b8522529c9fad9 Mon Sep 17 00:00:00 2001 From: Simen Bekkhus Date: Sun, 9 Oct 2022 08:34:41 -0700 Subject: [PATCH 45/53] tweak link --- docs/CLI.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/CLI.md b/docs/CLI.md index 759181790d7a..053c05ddd897 100644 --- a/docs/CLI.md +++ b/docs/CLI.md @@ -398,7 +398,7 @@ Print your Jest config and then exits. Prints the seed value in the test report summary. See [`--seed=`](#--seednum) for the details. -Can also be set in configuration. See [`showSeed`](Configuration#showseed-boolean). +Can also be set in configuration. See [`showSeed`](Configuration.md#showseed-boolean). ### `--silent` From d023a21b20f14049d26f2c1974b5c2cd8333b00e Mon Sep 17 00:00:00 2001 From: Simen Bekkhus Date: Sun, 9 Oct 2022 08:36:55 -0700 Subject: [PATCH 46/53] run same integration test --- e2e/__tests__/__snapshots__/showSeed.test.ts.snap | 4 ++-- e2e/__tests__/showSeed.test.ts | 14 ++++---------- 2 files changed, 6 insertions(+), 12 deletions(-) diff --git a/e2e/__tests__/__snapshots__/showSeed.test.ts.snap b/e2e/__tests__/__snapshots__/showSeed.test.ts.snap index ce4c83bfea7b..61a3ae92deed 100644 --- a/e2e/__tests__/__snapshots__/showSeed.test.ts.snap +++ b/e2e/__tests__/__snapshots__/showSeed.test.ts.snap @@ -11,8 +11,8 @@ Ran all test suites." exports[`--showSeed changes report to output seed 1`] = ` "Seed: <> -Test Suites: 2 failed, 5 passed, 7 total -Tests: 15 failed, 11 skipped, 53 passed, 79 total +Test Suites: 1 failed, 1 passed, 2 total +Tests: 1 failed, 1 passed, 2 total Snapshots: 0 total Time: <> Ran all test suites." diff --git a/e2e/__tests__/showSeed.test.ts b/e2e/__tests__/showSeed.test.ts index ad5cbe7eb18b..3bfa76013e53 100644 --- a/e2e/__tests__/showSeed.test.ts +++ b/e2e/__tests__/showSeed.test.ts @@ -9,9 +9,9 @@ import * as path from 'path'; import {extractSummary, replaceSeed} from '../Utils'; import runJest from '../runJest'; -test('--showSeed changes report to output seed', () => { - const dir = path.resolve(__dirname, '../each'); +const dir = path.resolve(__dirname, '../jest-object'); +test('--showSeed changes report to output seed', () => { const {stderr} = runJest(dir, [ '--showSeed', '--no-cache', @@ -25,18 +25,14 @@ test('--showSeed changes report to output seed', () => { }); test('if --showSeed is not present the report will not show the seed', () => { - const dir = path.resolve(__dirname, '../jest-object'); - const {stderr} = runJest(dir, ['--seed', '1234', '--ci']); - const summary = extractSummary(stderr).summary; + const {summary} = extractSummary(stderr); expect(summary).toMatchSnapshot(); }); test('if showSeed is present in the config the report will show the seed', () => { - const dir = path.resolve(__dirname, '../jest-object'); - const {stderr} = runJest(dir, [ '--seed', '1234', @@ -45,14 +41,12 @@ test('if showSeed is present in the config the report will show the seed', () => 'different-config.json', ]); - const summary = extractSummary(stderr).summary; + const {summary} = extractSummary(stderr); expect(summary).toMatchSnapshot(); }); test('--seed --showSeed will show the seed in the report', () => { - const dir = path.resolve(__dirname, '../jest-object'); - const {stderr} = runJest(dir, ['--showSeed', '--seed', '1234', '--ci']); const summary = replaceSeed(extractSummary(stderr).summary); From 535730b668ea04cb80bcbe9214fd86c41dac2499 Mon Sep 17 00:00:00 2001 From: Simen Bekkhus Date: Sun, 9 Oct 2022 08:45:39 -0700 Subject: [PATCH 47/53] do not use snapshots in tests --- .../__snapshots__/showSeed.test.ts.snap | 36 ------------------- e2e/__tests__/showSeed.test.ts | 27 +++++++------- 2 files changed, 12 insertions(+), 51 deletions(-) delete mode 100644 e2e/__tests__/__snapshots__/showSeed.test.ts.snap diff --git a/e2e/__tests__/__snapshots__/showSeed.test.ts.snap b/e2e/__tests__/__snapshots__/showSeed.test.ts.snap deleted file mode 100644 index 61a3ae92deed..000000000000 --- a/e2e/__tests__/__snapshots__/showSeed.test.ts.snap +++ /dev/null @@ -1,36 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`--seed --showSeed will show the seed in the report 1`] = ` -"Seed: <> -Test Suites: 2 passed, 2 total -Tests: 2 passed, 2 total -Snapshots: 0 total -Time: <> -Ran all test suites." -`; - -exports[`--showSeed changes report to output seed 1`] = ` -"Seed: <> -Test Suites: 1 failed, 1 passed, 2 total -Tests: 1 failed, 1 passed, 2 total -Snapshots: 0 total -Time: <> -Ran all test suites." -`; - -exports[`if --showSeed is not present the report will not show the seed 1`] = ` -"Test Suites: 2 passed, 2 total -Tests: 2 passed, 2 total -Snapshots: 0 total -Time: <> -Ran all test suites." -`; - -exports[`if showSeed is present in the config the report will show the seed 1`] = ` -"Seed: 1234 -Test Suites: 2 passed, 2 total -Tests: 2 passed, 2 total -Snapshots: 0 total -Time: <> -Ran all test suites." -`; diff --git a/e2e/__tests__/showSeed.test.ts b/e2e/__tests__/showSeed.test.ts index 3bfa76013e53..d7574e166945 100644 --- a/e2e/__tests__/showSeed.test.ts +++ b/e2e/__tests__/showSeed.test.ts @@ -11,45 +11,42 @@ import runJest from '../runJest'; const dir = path.resolve(__dirname, '../jest-object'); +const randomSeedValueRegExp = /Seed:\s+<>/; +const seedValueRegExp = /Seed:\s+1234/; + test('--showSeed changes report to output seed', () => { - const {stderr} = runJest(dir, [ - '--showSeed', - '--no-cache', - // Make the snapshot flag stable on CI. - '--ci', - ]); + const {stderr} = runJest(dir, ['--showSeed', '--no-cache']); - const summary = replaceSeed(extractSummary(stderr).summary); + const {summary} = extractSummary(stderr); - expect(summary).toMatchSnapshot(); + expect(replaceSeed(summary)).toMatch(randomSeedValueRegExp); }); test('if --showSeed is not present the report will not show the seed', () => { - const {stderr} = runJest(dir, ['--seed', '1234', '--ci']); + const {stderr} = runJest(dir, ['--seed', '1234']); const {summary} = extractSummary(stderr); - expect(summary).toMatchSnapshot(); + 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', - '--ci', '--config', 'different-config.json', ]); const {summary} = extractSummary(stderr); - expect(summary).toMatchSnapshot(); + expect(summary).toMatch(seedValueRegExp); }); test('--seed --showSeed will show the seed in the report', () => { - const {stderr} = runJest(dir, ['--showSeed', '--seed', '1234', '--ci']); + const {stderr} = runJest(dir, ['--showSeed', '--seed', '1234']); - const summary = replaceSeed(extractSummary(stderr).summary); + const {summary} = extractSummary(stderr); - expect(summary).toMatchSnapshot(); + expect(summary).toMatch(seedValueRegExp); }); From 3cb272bd39dafbf4fff70a572e79306dc588fa29 Mon Sep 17 00:00:00 2001 From: Simen Bekkhus Date: Sun, 9 Oct 2022 08:51:21 -0700 Subject: [PATCH 48/53] tweak doc --- docs/CLI.md | 2 +- packages/jest-leak-detector/src/index.ts | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/docs/CLI.md b/docs/CLI.md index 053c05ddd897..57c37d248985 100644 --- a/docs/CLI.md +++ b/docs/CLI.md @@ -352,7 +352,7 @@ The default regex matching works fine on small runs, but becomes slow if provide ### `--seed=` -Sets a seed value that can be retrieved in a test file via [`jest.getSeed()`](JestObjectAPI.md#jestgetseed). The seed value must be between `-0x80000000` and `0x7fffffff` inclusive (`-2147483648` and `2147483647` in decimal). +Sets a seed value that can be retrieved in a test file via [`jest.getSeed()`](JestObjectAPI.md#jestgetseed). The seed value must be between `-0x80000000` and `0x7fffffff` inclusive (`-2147483648` (`-(2 ** 31)`) and `2147483647` (`2 ** 31 - 1`) in decimal). ```bash jest --seed=1324 diff --git a/packages/jest-leak-detector/src/index.ts b/packages/jest-leak-detector/src/index.ts index f7f6f583198c..eff94dca1074 100644 --- a/packages/jest-leak-detector/src/index.ts +++ b/packages/jest-leak-detector/src/index.ts @@ -14,6 +14,9 @@ import {format as prettyFormat} from 'pretty-format'; const tick = promisify(setImmediate); +const val = -(2 ** 31); +const oval = 2 ** 31 - 1; + export default class LeakDetector { private _isReferenceBeingHeld: boolean; private readonly _finalizationRegistry?: FinalizationRegistry; From b8a70ebe14c2b6903c7c900bf171b7eaa9a27258 Mon Sep 17 00:00:00 2001 From: Simen Bekkhus Date: Sun, 9 Oct 2022 09:01:14 -0700 Subject: [PATCH 49/53] test bounds of seed --- .../jest-config/src/__tests__/normalize.test.ts | 17 +++++++++++++++++ packages/jest-config/src/normalize.ts | 12 +++++++++--- 2 files changed, 26 insertions(+), 3 deletions(-) diff --git a/packages/jest-config/src/__tests__/normalize.test.ts b/packages/jest-config/src/__tests__/normalize.test.ts index 4e044128ae58..8478cb65b0b7 100644 --- a/packages/jest-config/src/__tests__/normalize.test.ts +++ b/packages/jest-config/src/__tests__/normalize.test.ts @@ -2091,6 +2091,23 @@ describe('seed', () => { } as Config.Argv); expect(options.seed).toBe(4321); }); + + it('throws if seed is too large or too small', async () => { + await expect( + normalize({rootDir: '/root/'}, { + seed: 2 ** 33, + } as Config.Argv), + ).rejects.toThrow( + 'seed value must be between `-0x80000000` and `0x7fffffff` inclusive - is 8589934592', + ); + await expect( + normalize({rootDir: '/root/'}, { + seed: -(2 ** 33), + } as Config.Argv), + ).rejects.toThrow( + 'seed value must be between `-0x80000000` and `0x7fffffff` inclusive - is -8589934592', + ); + }); }); describe('showSeed', () => { diff --git a/packages/jest-config/src/normalize.ts b/packages/jest-config/src/normalize.ts index 7badae2427ab..d20a36437d1b 100644 --- a/packages/jest-config/src/normalize.ts +++ b/packages/jest-config/src/normalize.ts @@ -1024,13 +1024,19 @@ export default async function normalize( newOptions.showSeed = newOptions.showSeed || argv.showSeed; + const upperBoundSeedValue = 2 ** 31; + // xoroshiro128plus is used in v8 and is used here (at time of writing) newOptions.seed = - argv.seed ?? Math.floor(0xffffffff * Math.random() - 0x80000000); - if (newOptions.seed < -0x80000000 || newOptions.seed > 0x7fffffff) { + argv.seed ?? + Math.floor((2 ** 32 - 1) * Math.random() - upperBoundSeedValue); + if ( + newOptions.seed < -upperBoundSeedValue || + newOptions.seed > upperBoundSeedValue - 1 + ) { throw new ValidationError( 'Validation Error', - 'seed value must be between `-0x80000000` and `0x7fffffff` inclusive', + `seed value must be between \`-0x80000000\` and \`0x7fffffff\` inclusive - is ${newOptions.seed}`, ); } From b2021e559008acec75018ff6718107e78f0ee7bb Mon Sep 17 00:00:00 2001 From: Simen Bekkhus Date: Sun, 9 Oct 2022 09:02:25 -0700 Subject: [PATCH 50/53] no hooks --- packages/jest-reporters/src/__tests__/getSummary.test.ts | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/packages/jest-reporters/src/__tests__/getSummary.test.ts b/packages/jest-reporters/src/__tests__/getSummary.test.ts index c581d6722113..62745ef551bb 100644 --- a/packages/jest-reporters/src/__tests__/getSummary.test.ts +++ b/packages/jest-reporters/src/__tests__/getSummary.test.ts @@ -7,14 +7,7 @@ import {makeEmptyAggregatedTestResult} from '@jest/test-result'; import getSummary from '../getSummary'; -beforeEach(() => { - jest.useFakeTimers(); - jest.setSystemTime(10); -}); - -afterEach(() => { - jest.useRealTimers(); -}); +jest.useFakeTimers().setSystemTime(10); describe('getSummary', () => { test('does not print seed value when showSeed is false', () => { From 91212a246d3c51cd1d36a564a53ccdcbe20468b0 Mon Sep 17 00:00:00 2001 From: Simen Bekkhus Date: Sun, 9 Oct 2022 09:03:43 -0700 Subject: [PATCH 51/53] remove unused optional --- packages/jest-reporters/src/getSummary.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/jest-reporters/src/getSummary.ts b/packages/jest-reporters/src/getSummary.ts index 094addb106b8..2781932f5ad6 100644 --- a/packages/jest-reporters/src/getSummary.ts +++ b/packages/jest-reporters/src/getSummary.ts @@ -116,12 +116,12 @@ export default function getSummary( const optionalLines: Array = []; - if (options?.showSeed) { - if (options?.seed === undefined) { + if (options?.showSeed === true) { + const {seed} = options; + if (seed === undefined) { throw new Error('Attempted to display seed but seed value is undefined'); } - const seed = `${chalk.bold('Seed: ') + options.seed.toString()}`; - optionalLines.push(seed); + optionalLines.push(`${chalk.bold('Seed: ') + seed}`); } const suites = `${ From ed5f9c151c3a77c3a281e356ecd8d7414aa4e359 Mon Sep 17 00:00:00 2001 From: Simen Bekkhus Date: Sun, 9 Oct 2022 09:06:09 -0700 Subject: [PATCH 52/53] oops --- packages/jest-leak-detector/src/index.ts | 3 --- 1 file changed, 3 deletions(-) diff --git a/packages/jest-leak-detector/src/index.ts b/packages/jest-leak-detector/src/index.ts index eff94dca1074..f7f6f583198c 100644 --- a/packages/jest-leak-detector/src/index.ts +++ b/packages/jest-leak-detector/src/index.ts @@ -14,9 +14,6 @@ import {format as prettyFormat} from 'pretty-format'; const tick = promisify(setImmediate); -const val = -(2 ** 31); -const oval = 2 ** 31 - 1; - export default class LeakDetector { private _isReferenceBeingHeld: boolean; private readonly _finalizationRegistry?: FinalizationRegistry; From cf0230c58c98c97897912da835b1f1e350e94516 Mon Sep 17 00:00:00 2001 From: Simen Bekkhus Date: Sun, 9 Oct 2022 09:14:44 -0700 Subject: [PATCH 53/53] prettier --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b4ab46790ce1..e575da0d2e14 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,7 @@ ### Features -- `[@jest/cli, jest-config]` A seed for the test run will be randomly generated, or set by a CLI option ([#13400](https://github.com/facebook/jest/pull/13400)) +- `[@jest/cli, jest-config]` A seed for the test run will be randomly generated, or set by a CLI option ([#13400](https://github.com/facebook/jest/pull/13400)) - `[@jest/cli, jest-config]` `--show-seed` will display the seed value in the report, and can be set via a CLI flag or through the config file ([#13400](https://github.com/facebook/jest/pull/13400)) - `[jest-config]` Add `readInitialConfig` utility function ([#13356](https://github.com/facebook/jest/pull/13356)) - `[jest-core]` Enable testResultsProcessor to be async ([#13343](https://github.com/facebook/jest/pull/13343))