Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(type-safe-api): silence warnings for mock data generation for fields with pattern constraints #892

Merged
merged 1 commit into from
Dec 9, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -178,14 +178,18 @@ export const generateMockDataForSchema = (

const generateStringFromRegex = (pattern: string): string | undefined => {
const random = Math.random;
const warn = console.warn;
try {
// Fix random to ensure mocked data is deterministic
Math.random = () => 0.5;
// ReRegExp prints warnings to the console which add unnecessary noise
console.warn = () => {};
return new ReRegExp(pattern).build();
} catch {
// Couldn't convert regex to string, don't fail, just be less strict
} finally {
Math.random = random;
console.warn = warn;
}
return undefined;
}
Expand Down
Loading