Skip to content

.tip

· one of the small things

Seed the random generator and print the seed on failure

If a test using random data fails, you can't reproduce it unless you know the seed.

const seed = Number(process.env.TEST_SEED ?? Date.now());
console.log(`seed: ${seed}`);
const rng = seedrandom(String(seed));

The failing run's log has the seed in it. Set TEST_SEED and you get the same inputs back on your laptop, every time, until it's fixed.

testing