Skip to content

Commit e707edf

Browse files
committed
refactor(models): require at least one audit in the report
1 parent 2256dcc commit e707edf

2 files changed

Lines changed: 24 additions & 4 deletions

File tree

packages/models/src/lib/report.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ export const pluginReportSchema = pluginMetaSchema
2727
)
2828
.merge(
2929
z.object({
30-
audits: z.array(auditReportSchema),
30+
audits: z.array(auditReportSchema).min(1),
3131
groups: z.array(groupSchema).optional(),
3232
}),
3333
)

packages/models/src/lib/report.unit.test.ts

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -110,11 +110,31 @@ describe('pluginReportSchema', () => {
110110
icon: 'cypress',
111111
date: '2024-01-11T11:00:00.000Z',
112112
duration: 123_000,
113-
audits: [],
113+
audits: [
114+
{
115+
slug: 'cyct',
116+
title: 'Component tests',
117+
score: 0.96,
118+
value: 96,
119+
},
120+
],
114121
} satisfies PluginReport),
115122
).not.toThrow();
116123
});
117124

125+
it('should throw for a plugin report with no audit outputs', () => {
126+
expect(() =>
127+
pluginReportSchema.parse({
128+
slug: 'cypress',
129+
title: 'Cypress',
130+
icon: 'cypress',
131+
date: '2024-01-11T11:00:00.000Z',
132+
duration: 123_000,
133+
audits: [],
134+
} satisfies PluginReport),
135+
).toThrow('too_small');
136+
});
137+
118138
it('should throw for a group reference without audits mention', () => {
119139
expect(() =>
120140
pluginReportSchema.parse({
@@ -185,15 +205,15 @@ describe('reportSchema', () => {
185205
).not.toThrow();
186206
});
187207

188-
it('should throw for an empty report', () => {
208+
it('should throw for a report with no plugins', () => {
189209
expect(() =>
190210
reportSchema.parse({
191211
date: '2024-01-03T08:00:00.000Z',
192212
duration: 14_500,
193213
packageName: 'cli',
194214
version: '1.0.1',
195-
categories: [],
196215
plugins: [],
216+
categories: [],
197217
}),
198218
).toThrow('too_small');
199219
});

0 commit comments

Comments
 (0)