Created
December 21, 2021 15:30
-
-
Save HonzaMac/bd11e85ba0038a0b29778f63ce11d23b to your computer and use it in GitHub Desktop.
faker-replaying-seed-from-ENV
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import faker from 'faker'; | |
const setupFaker = () => { | |
const replayedSeed = parseInt(process.env.FAKER_SEED, 10) || 0; | |
const seedValue = replayedSeed || Math.floor(Math.random() * Number.MAX_SAFE_INTEGER); | |
faker.seed(seedValue); | |
if (replayedSeed) { | |
console.warn(`Replaying test with FAKER_SEED=${replayedSeed}`); | |
} else { | |
console.info(`FAKER_SEED=${seedValue}`); | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment