Skip to content

Commit c688fff

Browse files
committed
feat: move report validation to SDK
1 parent 84b0616 commit c688fff

6 files changed

Lines changed: 48 additions & 19 deletions

File tree

package-lock.json

Lines changed: 16 additions & 16 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,11 @@
3737
"typescript": "^5.6.2"
3838
},
3939
"dependencies": {
40-
"@flakiness/flakiness-report": "^0.19.0",
40+
"@flakiness/flakiness-report": "^0.20.0",
4141
"chalk": "^5.6.2",
4242
"debug": "^4.4.3",
4343
"open": "^10.2.0",
44-
"stable-hash": "^0.0.6"
44+
"stable-hash": "^0.0.6",
45+
"zod": "^4.3.5"
4546
}
4647
}

src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// Report type & validation
2-
export { FlakinessReport, validateReport } from '@flakiness/flakiness-report';
2+
export { FlakinessReport, Schema } from '@flakiness/flakiness-report';
33

44
// Building report
55
export { CIUtils } from './ciUtils.js';

src/reportUtils.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
export { collectSources } from './collectSources.js';
22
export { createEnvironment } from './createEnvironment.js';
33
export { normalizeReport } from './normalizeReport.js';
4+
export { validateReport } from './validateReport.js';
45
export { stripAnsi } from './stripAnsi.js';
56
export {
67
createDataAttachment,

src/reportUtilsBrowser.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
export { normalizeReport } from './normalizeReport.js';
2+
export { validateReport } from './validateReport.js';
23
export { stripAnsi } from './stripAnsi.js';
34
export { visitTests } from './visitTests.js';
45

src/validateReport.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import { FlakinessReport, Schema } from '@flakiness/flakiness-report';
2+
import z from 'zod';
3+
4+
/**
5+
* Validates a report object against the Flakiness Report schema.
6+
*
7+
* @param report - The report object to validate
8+
* @returns A formatted error string if validation fails, or `undefined` if the report is valid
9+
*/
10+
export function validateReport(report: FlakinessReport.Report): string|undefined {
11+
const validation = Schema.Report.safeParse(report);
12+
if (!validation.success) {
13+
const MAX_ISSUES = 5;
14+
15+
const allIssues = validation.error.issues;
16+
const shownIssues = allIssues.slice(0, MAX_ISSUES);
17+
const remaining = allIssues.length - shownIssues.length;
18+
19+
const base = [z.prettifyError(new z.ZodError(shownIssues))];
20+
if (remaining > 0)
21+
base.push(`... and ${remaining} more issue${remaining === 1 ? '' : 's'} ...`);
22+
return base.join('\n');
23+
}
24+
return undefined;
25+
}
26+

0 commit comments

Comments
 (0)