@@ -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+
2228export 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