open-nomad/ui/mirage/faker.js
2023-04-10 15:36:59 +00:00

32 lines
772 B
JavaScript

/**
* Copyright (c) HashiCorp, Inc.
* SPDX-License-Identifier: MPL-2.0
*/
import faker from 'faker';
import config from 'nomad-ui/config/environment';
const searchIncludesSeed = window.location.search.includes('faker-seed');
if (
config.environment !== 'test' ||
config.percy.enabled ||
searchIncludesSeed
) {
if (searchIncludesSeed) {
const params = new URLSearchParams(window.location.search);
const seed = parseInt(params.get('faker-seed'));
faker.seed(seed);
} else {
faker.seed(1);
}
} else if (config.environment === 'test') {
const randomSeed = faker.random.number();
console.log(
`No seed specified with faker-seed query parameter, seeding Faker with ${randomSeed}`
);
faker.seed(randomSeed);
}
export default faker;