Skip to content

Commit f8bfb9b

Browse files
committed
fix: satisfy reporter CI guards
1 parent 7acf07a commit f8bfb9b

2 files changed

Lines changed: 21 additions & 17 deletions

File tree

‎scripts/integration-progress-model.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,7 @@ function summarizeProviderScenarioFlagExclusions() {
276276
'snapshotForceFull',
277277
'baseline',
278278
'threshold',
279+
'reporter',
279280
'reportJunit',
280281
'replayMaestro',
281282
'replayExportFormat',

‎src/cli-test-reporters/custom.ts‎

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,12 @@ type CustomReporterSpec = {
1919
options: unknown;
2020
};
2121

22+
const OPTIONAL_REPORTER_HOOKS = [
23+
'onProgress',
24+
'onSuiteEnd',
25+
'getExitCode',
26+
] as const satisfies readonly (keyof ReplayTestReporter)[];
27+
2228
export function isCustomReplayTestReporterSpec(spec: string): boolean {
2329
const modulePath = readCustomReporterModulePath(spec);
2430
return (
@@ -111,23 +117,20 @@ function validateCustomReplayTestReporter(
111117
if (typeof candidate.name !== 'string' || candidate.name.trim().length === 0) {
112118
throw new AppError('INVALID_ARGS', `Custom test reporter ${modulePath} must define name.`);
113119
}
114-
if (candidate.onProgress !== undefined && typeof candidate.onProgress !== 'function') {
115-
throw new AppError(
116-
'INVALID_ARGS',
117-
`Custom test reporter ${modulePath} onProgress must be a function.`,
118-
);
119-
}
120-
if (candidate.onSuiteEnd !== undefined && typeof candidate.onSuiteEnd !== 'function') {
121-
throw new AppError(
122-
'INVALID_ARGS',
123-
`Custom test reporter ${modulePath} onSuiteEnd must be a function.`,
124-
);
125-
}
126-
if (candidate.getExitCode !== undefined && typeof candidate.getExitCode !== 'function') {
127-
throw new AppError(
128-
'INVALID_ARGS',
129-
`Custom test reporter ${modulePath} getExitCode must be a function.`,
130-
);
120+
for (const hook of OPTIONAL_REPORTER_HOOKS) {
121+
validateOptionalReporterHook(candidate, modulePath, hook);
131122
}
132123
return candidate as ReplayTestReporter;
133124
}
125+
126+
function validateOptionalReporterHook(
127+
reporter: Partial<ReplayTestReporter>,
128+
modulePath: string,
129+
hook: (typeof OPTIONAL_REPORTER_HOOKS)[number],
130+
): void {
131+
if (reporter[hook] === undefined || typeof reporter[hook] === 'function') return;
132+
throw new AppError(
133+
'INVALID_ARGS',
134+
`Custom test reporter ${modulePath} ${hook} must be a function.`,
135+
);
136+
}

0 commit comments

Comments
 (0)