ngneat/falso

UUID and random dates doesn´t respect the seed

MarioJuniorPro opened this issue · 4 comments

Is this a regression?

Yes

Description

Generating uuids doesn´t respect the seed and it is always random. Also, when I generate dates and reload the environment, the date generated respect the seed except by the seconds.
If for some reason it is not considered a bug, would be nice to have global option to use a strict mode.

import { seed } from '@ngneat/falso';
import { randUuid, random, randSoonDate } from '@ngneat/falso';

const uuids = [];
seed('1');
uuids.push([randUuid(), random(), randSoonDate()]);
seed('2');
uuids.push([randUuid(), random(), randSoonDate()]);
seed('1');
uuids.push([randUuid(), random(), randSoonDate()]);
console.table(uuids);

Please provide a link to a minimal reproduction of the bug

https://stackblitz.com/edit/typescript-sblpt9?file=index.ts

Please provide the exception or error you saw

// First run:
// 0	"da91cec3-7971-4a92-bb27-d54185e0be65"	0.2694488477791326	"2023-02-01T10:16:28.796Z"
// 1	"0a7b3a3e-4529-4626-b49f-7d395887312d"	0.7153687886990808	"2023-02-01T08:51:34.962Z"
// 2	"6f523c82-c565-4f84-92b9-9201899a292a"	0.2694488477791326	"2023-02-01T10:16:28.796Z"

// Seconds run:
// 0	"e5bd2a4c-d6e7-42d5-8c47-1777d8d7cefc"	0.2694488477791326	"2023-02-01T10:17:02.298Z"
// 1	"384e485c-a539-45da-b893-420e387ce038"	0.7153687886990808	"2023-02-01T08:52:08.465Z"
// 2	"ae7b7285-56d6-4efe-bb08-80ebded093f4"	0.2694488477791326	"2023-02-01T10:17:02.299Z"

Please provide the environment you discovered this bug in

It can be reproduced using this link [https://stackblitz.com/edit/typescript-sblpt9?file=index.ts]()

Anything else?

No response

Do you want to create a pull request?

No

After test using node, the uuid works fine, maybe the issue is when it runs in the browser or in StackBlitz.
The date issue is because the functions uses new Date(), I don´t now know if the best approach would implement some parameter or a global static timestamp.

I am having this exactly same behavior. Having a hard time getting the same uuid while using Jest. @MarioJuniorPro Do you manage to solved it? Thanks for any information!

@MarioJuniorPro @MarcoB-Ec I noticed that you are using @ngneat/falso@2.27 for some reason there.
The UUID seems to be working as expected after upgrading to the latest version.
Regarding randSoonDate, as you guys said it's based on new Date() so that would change between runs since it's not static by the seed.