2023-04-10 15:36:59 +00:00
|
|
|
/**
|
|
|
|
* Copyright (c) HashiCorp, Inc.
|
|
|
|
* SPDX-License-Identifier: MPL-2.0
|
|
|
|
*/
|
|
|
|
|
2019-10-03 14:13:08 +00:00
|
|
|
import faker from 'faker';
|
|
|
|
import config from 'nomad-ui/config/environment';
|
|
|
|
|
|
|
|
const searchIncludesSeed = window.location.search.includes('faker-seed');
|
|
|
|
|
2022-05-12 20:09:19 +00:00
|
|
|
if (
|
|
|
|
config.environment !== 'test' ||
|
|
|
|
config.percy.enabled ||
|
|
|
|
searchIncludesSeed
|
|
|
|
) {
|
2019-10-03 14:13:08 +00:00
|
|
|
if (searchIncludesSeed) {
|
|
|
|
const params = new URLSearchParams(window.location.search);
|
|
|
|
const seed = parseInt(params.get('faker-seed'));
|
|
|
|
faker.seed(seed);
|
|
|
|
} else {
|
|
|
|
faker.seed(1);
|
|
|
|
}
|
2020-10-22 18:45:51 +00:00
|
|
|
} else if (config.environment === 'test') {
|
|
|
|
const randomSeed = faker.random.number();
|
2020-10-29 12:46:42 +00:00
|
|
|
console.log(
|
|
|
|
`No seed specified with faker-seed query parameter, seeding Faker with ${randomSeed}`
|
|
|
|
);
|
2020-10-22 18:45:51 +00:00
|
|
|
faker.seed(randomSeed);
|
2019-10-03 14:13:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export default faker;
|