Skip to content

Commit fa94f93

Browse files
author
John Doe
committed
refactor: fix Nx update unit tests
1 parent ff6c610 commit fa94f93

File tree

1 file changed

+20
-18
lines changed

1 file changed

+20
-18
lines changed

packages/models/src/lib/implementation/schemas.ts

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -68,25 +68,27 @@ export const descriptionSchema = z
6868
export const urlSchema = z.string().url().meta({ title: 'URL' });
6969

7070
/** Schema for a docsUrl */
71-
export const docsUrlSchema = urlSchema
71+
export const docsUrlSchema = z
72+
.union([
73+
z.literal(''),
74+
// eslint-disable-next-line unicorn/prefer-top-level-await
75+
z
76+
.string()
77+
.url()
78+
.catch(error => {
79+
// if only URL validation fails, supress error since this metadata is optional anyway
80+
if (
81+
error.issues.length === 1 &&
82+
error.issues[0]?.code === 'invalid_format' &&
83+
(error.issues[0] as ZodIssue & { format?: string }).format === 'url'
84+
) {
85+
console.warn(`Ignoring invalid docsUrl: ${error.value}`);
86+
return '';
87+
}
88+
throw new ZodError(error.error.issues);
89+
}),
90+
])
7291
.optional()
73-
.or(z.literal('')) // allow empty string (no URL validation)
74-
// eslint-disable-next-line unicorn/prefer-top-level-await, unicorn/catch-error-name
75-
.catch(ctx => {
76-
// if only URL validation fails, supress error since this metadata is optional anyway
77-
if (
78-
ctx.issues.length === 1 &&
79-
(ctx.issues[0]?.errors as ZodIssue[][])
80-
.flat()
81-
.some(
82-
error => error.code === 'invalid_format' && error.format === 'url',
83-
)
84-
) {
85-
console.warn(`Ignoring invalid docsUrl: ${ctx.value}`);
86-
return '';
87-
}
88-
throw new ZodError(ctx.error.issues);
89-
})
9092
.meta({ title: 'DocsUrl', description: 'Documentation site' });
9193

9294
/** Schema for a title of a plugin, category and audit */

0 commit comments

Comments
 (0)