jestjs/jest · error · ValidationError

seed value must be between `-0x80000000` and `0x7fffffff` in

Error message

seed value must be between `-0x80000000` and `0x7fffffff` inclusive - instead it is ${newOptions.seed}

What it means

normalize() derives the seed (normalize.ts:1127-1141) for test randomization and validates it against the 32-bit signed integer range imposed by the xoroshiro128plus PRNG ([-2147483648, 2147483647]). argv.seed, when provided, must already lie in that range; anything outside throws a ValidationError because the PRNG output would be undefined/unreliable outside its domain.

Source

Thrown at packages/jest-config/src/normalize.ts:1137

    newOptions.onlyChanged = newOptions.watch;
  }

  newOptions.randomize = newOptions.randomize || argv.randomize;

  newOptions.showSeed =
    newOptions.randomize || newOptions.showSeed || argv.showSeed;

  const upperBoundSeedValue = 2 ** 31;

  // bounds are determined by xoroshiro128plus which is used in v8 and is used here (at time of writing)
  newOptions.seed =
    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 - instead it is ${newOptions.seed}`,
    );
  }

  if (!newOptions.onlyChanged) {
    newOptions.onlyChanged = false;
  }

  if (!newOptions.lastCommit) {
    newOptions.lastCommit = false;
  }

  if (!newOptions.onlyFailures) {
    newOptions.onlyFailures = false;
  }

  if (!newOptions.watchAll) {

View on GitHub (pinned to 8e6d128e4a)

Solutions

  1. Constrain the seed to the signed 32-bit range: -2147483648 <= seed <= 2147483647.
  2. If reproducing a prior run, copy the exact integer printed by --showSeed.
  3. When deriving a seed programmatically, mask with & 0xffffffff and re-center, or use Math.floor(Math.random() * 2**32) - 2**31.

Example fix

// before
jest --seed 9999999999
// after
jest --seed 2147483647
Defensive patterns

Strategy: validation

Validate before calling

const MIN = -0x80000000;
const MAX = 0x7fffffff;
function clampSeed(seed: number): number {
  if (!Number.isInteger(seed) || seed < MIN || seed > MAX) {
    throw new Error(`seed must be an integer in [${MIN}, ${MAX}]`);
  }
  return seed;
}
function safeSeed(input: number): number {
  // bring arbitrary input into range deterministically
  return (input | 0); // truncate to int32, wraps within signed 32-bit range
}

Type guard

function isInt32(n: unknown): n is number {
  return typeof n === 'number' && Number.isInteger(n) && n >= -0x80000000 && n <= 0x7fffffff;
}

Prevention

When it happens

Trigger: Passing jest --seed 9999999999 (exceeds 2^31-1); jest --seed -9999999999 (below -2^31); passing a float or a numeric string that yargs coerced out of range; computing a seed from a hash that overflowed.

Common situations: Reusing a seed reported by --showSeed from a tool that formatted it differently; CI passing a seed via env that exceeds the range; a script that derives the seed from a Git SHA truncated/expanded incorrectly.

Related errors


AI-assisted analysis of jestjs/jest@8e6d128e4a (2026-08-10). Data as JSON: /api/errors/575cc1502f4fd013. Report an issue: GitHub.