Skip to content

Commit a0814d3

Browse files
committed
feat(plugin-coverage): update to zod v4
1 parent 3444e8d commit a0814d3

File tree

3 files changed

+33
-39
lines changed

3 files changed

+33
-39
lines changed

packages/plugin-coverage/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
"ansis": "^3.3.0",
4040
"parse-lcov": "^1.0.4",
4141
"yargs": "^17.7.2",
42-
"zod": "^3.22.4"
42+
"zod": "^4.0.5"
4343
},
4444
"peerDependencies": {
4545
"@nx/devkit": ">=17.0.0",

packages/plugin-coverage/src/lib/config.ts

Lines changed: 31 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -6,63 +6,57 @@ export type CoverageType = z.infer<typeof coverageTypeSchema>;
66
export const coverageResultSchema = z.union([
77
z.object({
88
resultsPath: z
9-
.string({
10-
description: 'Path to coverage results for Nx setup.',
11-
})
12-
.includes('lcov'),
9+
.string()
10+
.includes('lcov')
11+
.describe('Path to coverage results for Nx setup.'),
1312
pathToProject: z
14-
.string({
15-
description:
16-
'Path from workspace root to project root. Necessary for LCOV reports which provide a relative path.',
17-
})
13+
.string()
14+
.describe(
15+
'Path from workspace root to project root. Necessary for LCOV reports which provide a relative path.',
16+
)
1817
.optional(),
1918
}),
2019
z
21-
.string({
22-
description: 'Path to coverage results for a single project setup.',
23-
})
24-
.includes('lcov'),
20+
.string()
21+
.includes('lcov')
22+
.describe('Path to coverage results for a single project setup.'),
2523
]);
2624
export type CoverageResult = z.infer<typeof coverageResultSchema>;
2725

2826
export const coveragePluginConfigSchema = z.object({
2927
coverageToolCommand: z
3028
.object({
31-
command: z
32-
.string({ description: 'Command to run coverage tool.' })
33-
.min(1),
29+
command: z.string().min(1).describe('Command to run coverage tool.'),
3430
args: z
35-
.array(z.string(), {
36-
description: 'Arguments to be passed to the coverage tool.',
37-
})
38-
.optional(),
31+
.array(z.string())
32+
.optional()
33+
.describe('Arguments to be passed to the coverage tool.'),
3934
})
4035
.optional(),
4136
continueOnCommandFail: z
42-
.boolean({
43-
description:
44-
'Continue on coverage tool command failure or error. Defaults to true.',
45-
})
46-
.default(true),
37+
.boolean()
38+
.default(true)
39+
.describe(
40+
'Continue on coverage tool command failure or error. Defaults to true.',
41+
),
4742
coverageTypes: z
48-
.array(coverageTypeSchema, {
49-
description: 'Coverage types measured. Defaults to all available types.',
50-
})
43+
.array(coverageTypeSchema)
5144
.min(1)
52-
.default(['function', 'branch', 'line']),
45+
.default(['function', 'branch', 'line'])
46+
.describe('Coverage types measured. Defaults to all available types.'),
5347
reports: z
54-
.array(coverageResultSchema, {
55-
description:
56-
'Path to all code coverage report files. Only LCOV format is supported for now.',
57-
})
58-
.min(1),
48+
.array(coverageResultSchema)
49+
.min(1)
50+
.describe(
51+
'Path to all code coverage report files. Only LCOV format is supported for now.',
52+
),
5953
perfectScoreThreshold: z
60-
.number({
61-
description:
62-
'Score will be 1 (perfect) for this coverage and above. Score range is 0 - 1.',
63-
})
54+
.number()
6455
.gt(0)
6556
.max(1)
57+
.describe(
58+
'Score will be 1 (perfect) for this coverage and above. Score range is 0 - 1.',
59+
)
6660
.optional(),
6761
});
6862
export type CoveragePluginConfig = z.input<typeof coveragePluginConfigSchema>;

packages/plugin-coverage/src/lib/config.unit.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ describe('coveragePluginConfigSchema', () => {
7171
coverageTypes: ['line'],
7272
reports: ['coverage/cli/coverage-final.json'],
7373
} satisfies CoveragePluginConfig),
74-
).toThrow(/Invalid input: must include.+lcov/);
74+
).toThrow(String.raw`Invalid string: must include \"lcov\"`);
7575
});
7676

7777
it('throws for missing command', () => {

0 commit comments

Comments
 (0)