{"record":{"id":"d71a01efe3608bbe","repo":"jestjs/jest","slug":"attempted-to-display-seed-but-seed-value-is-undefi","errorCode":null,"errorMessage":"Attempted to display seed but seed value is undefined","messagePattern":"Attempted to display seed but seed value is undefined","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/jest-reporters/src/getSummary.ts","lineNumber":122,"sourceCode":"  const snapshotsUpdated = snapshotResults.updated;\n  const suitesFailed = aggregatedResults.numFailedTestSuites;\n  const suitesPassed = aggregatedResults.numPassedTestSuites;\n  const suitesPending = aggregatedResults.numPendingTestSuites;\n  const suitesRun = suitesFailed + suitesPassed;\n  const suitesTotal = aggregatedResults.numTotalTestSuites;\n  const testsFailed = aggregatedResults.numFailedTests;\n  const testsPassed = aggregatedResults.numPassedTests;\n  const testsPending = aggregatedResults.numPendingTests;\n  const testsTodo = aggregatedResults.numTodoTests;\n  const testsTotal = aggregatedResults.numTotalTests;\n  const width = (options && options.width) || 0;\n\n  const optionalLines: Array<string> = [];\n\n  if (options?.showSeed === true) {\n    const {seed} = options;\n    if (seed === undefined) {\n      throw new Error('Attempted to display seed but seed value is undefined');\n    }\n    optionalLines.push(`${chalk.bold('Seed:        ') + seed}`);\n  }\n\n  const suites = `${\n    chalk.bold('Test Suites: ') +\n    (suitesFailed ? `${chalk.bold.red(`${suitesFailed} failed`)}, ` : '') +\n    (suitesPending\n      ? `${chalk.bold.yellow(`${suitesPending} skipped`)}, `\n      : '') +\n    (suitesPassed ? `${chalk.bold.green(`${suitesPassed} passed`)}, ` : '') +\n    (suitesRun === suitesTotal ? suitesTotal : `${suitesRun} of ${suitesTotal}`)\n  } total`;\n\n  const updatedTestsFailed =\n    testsFailed + valuesForCurrentTestCases.numFailingTests;\n  const updatedTestsPending =\n    testsPending + valuesForCurrentTestCases.numPendingTests;","sourceCodeStart":104,"sourceCodeEnd":140,"githubUrl":"https://github.com/jestjs/jest/blob/8e6d128e4a278059ecddecaa97400b04c8ae5fd9/packages/jest-reporters/src/getSummary.ts#L104-L140","documentation":"Thrown by jest-reporters' getSummary() at packages/jest-reporters/src/getSummary.ts:122 when the caller requests seed display (options.showSeed === true) but supplies no seed value (options.seed === undefined). Jest prints a 'Seed: <n>' line in the test summary so that randomized runs can be reproduced; if you ask for that line without giving it a number to print, the function aborts rather than emit a misleading empty seed. It is a hard guard against rendering an undefined value into the summary output.","triggerScenarios":"Calling getSummary(aggregatedResults, {showSeed: true}) without a numeric seed property. In the CLI/runtime path, SummaryReporter._printTestRunEnd (SummaryReporter.ts:125-129) forwards globalConfig.showSeed and globalConfig.seed, so the error fires when globalConfig.showSeed is true while globalConfig.seed is undefined. Concretely: running jest with --showSeed but no --seed=<n> and no --randomize (which would auto-generate a seed), or setting `showSeed: true` in jest.config without `randomize: true` or `seed: <n>`. Also when invoking getSummary directly from a custom reporter.","commonSituations":"A developer adds `showSeed: true` to a Jest config or custom reporter to surface the seed for reproducible test ordering, but forgets that a seed is only present when `randomize: true` or an explicit `seed` is configured. Another common case: upgrading Jest and adopting the newer --showSeed flag while the project does not use randomized ordering, leaving globalConfig.seed undefined. Custom reporters that wrap getSummary and hardcode showSeed: true without threading the seed through are the third typical source.","solutions":["Enable randomized ordering so Jest generates and stores a seed: pass --randomize on the CLI or set `randomize: true` in jest.config.js (this auto-populates globalConfig.seed and pairs naturally with --showSeed).","Supply an explicit seed: pass --seed=<n> on the CLI or set `seed: <number>` in jest.config.js so globalConfig.seed is defined.","Remove `showSeed: true` from your Jest config / reporter options if you do not actually need the Seed line in the summary.","If calling getSummary directly in a custom reporter, always pass both together: `{showSeed: globalConfig.showSeed, seed: globalConfig.seed}` and guard `showSeed: Boolean(globalConfig.showSeed) && globalConfig.seed !== undefined` before enabling it."],"exampleFix":"// before (jest.config.js)\nmodule.exports = {\n  showSeed: true,\n  // no randomize, no seed -> error at getSummary.ts:122\n};\n\n// after: enable randomize so a seed is generated\nmodule.exports = {\n  randomize: true,\n  showSeed: true,\n};\n\n// or: pin an explicit seed\nmodule.exports = {\n  seed: 12345,\n  showSeed: true,\n};","handlingStrategy":"validation","validationCode":"// Before calling getSummary, normalise the options so showSeed is only\n// true when a numeric seed actually exists.\nimport type {SummaryOptions} from 'jest-reporters';\n\nfunction safeSummaryOptions(opts: SummaryOptions): SummaryOptions {\n  const showSeed = opts.showSeed === true && typeof opts.seed === 'number';\n  return {...opts, showSeed};\n}\n\n// usage\nconst summary = getSummary(aggregatedResults, safeSummaryOptions({\n  showSeed: globalConfig.showSeed,\n  seed: globalConfig.seed,\n  estimatedTime,\n}));","typeGuard":"// Type + runtime guard narrowing: showSeed truthy implies seed is a number.\ntype SafeSummaryOptions =\n  | ({showSeed?: false} & SummaryOptions)\n  | ({showSeed: true; seed: number} & SummaryOptions);\n\nfunction hasSeed(opts: SummaryOptions): opts is {showSeed: true; seed: number} {\n  return opts.showSeed === true && typeof opts.seed === 'number' && Number.isFinite(opts.seed);\n}\n\nif (hasSeed(options)) {\n  // safe to call getSummary with options.showSeed === true\n}","tryCatchPattern":"// For custom reporters that wrap getSummary: catch, surface via _setError,\n// and re-run without showSeed so the summary still renders.\ntry {\n  message = getSummary(aggregatedResults, {showSeed: true, seed: globalConfig.seed});\n} catch (e) {\n  this._setError(e as Error);\n  message = getSummary(aggregatedResults, {showSeed: false});\n}","preventionTips":["Treat --showSeed and --randomize (or an explicit --seed) as a single feature: never enable showSeed without a seed source.","In jest.config.js, set `randomize: true` alongside `showSeed: true` so Jest always generates a seed to print.","In custom reporters, thread both globalConfig.showSeed and globalConfig.seed together and coerce showSeed to false when seed is missing.","Add a unit test mirroring __tests__/getSummary.test.ts:32 that asserts the throwing case AND the safe-passthrough case for your reporter options.","When upgrading Jest across versions that introduced seed support, audit globalConfig usage in any reporter you maintain for unset seed fields."],"tags":["jest","jest-reporters","configuration","seed","randomize","reporter"],"backgroundTag":null,"analyzedSha":"8e6d128e4a278059ecddecaa97400b04c8ae5fd9","analyzedAt":"2026-08-10T18:11:27.960Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}