File tree Expand file tree Collapse file tree 2 files changed +18
-2
lines changed Expand file tree Collapse file tree 2 files changed +18
-2
lines changed Original file line number Diff line number Diff line change @@ -3,7 +3,9 @@ import type { APIClient } from './APIClient.js';
33import type { EventManager } from './EventManager.js' ;
44
55export interface IScenarioCommand {
6- validate ?( params : any ) : boolean ;
6+ /** Validates the input to the command. Throws an exception of the input is not valid */
7+ validate ?( params : any ) : void ;
8+
79 run ( scenario : TestScenario , client : APIClient , params : any ) : Promise < void > ;
810}
911
@@ -61,9 +63,12 @@ export class TestScenario {
6163 }
6264
6365 for ( const key of Object . keys ( step ) ) {
64- if ( ! validStepKeys . includes ( key ) && ! Object . keys ( this . handlers ) . includes ( key ) ) {
66+ const handler = this . handlers [ key ] ;
67+ if ( ! validStepKeys . includes ( key ) && ! handler ) {
6568 throw new Error ( `Invalid scenario step key: ${ key } ` ) ;
6669 }
70+
71+ handler ?. validate ?.( step [ key ] ) ;
6772 }
6873 }
6974 }
Original file line number Diff line number Diff line change @@ -8,6 +8,17 @@ import { promiseAndResolver } from '../utils/promise.js';
88export class DelayCommand {
99 constructor ( readonly eventManager : EventManager ) { }
1010
11+ validate ( value : string ) {
12+ if ( typeof value === 'number' ) {
13+ throw new Error (
14+ `Invalid delay value ${ value } . The value must include units (e.g. ${ value } ms)` ,
15+ ) ;
16+ }
17+ if ( typeof value !== 'string' ) {
18+ throw new Error ( `Delay value must be a string` ) ;
19+ }
20+ }
21+
1122 async run ( scenario : TestScenario , client : APIClient , value : string ) {
1223 const nanos = parseTime ( value ) ;
1324 const targetNanos = ( client . lastNanos ?? 0 ) + nanos ;
You can’t perform that action at this time.
0 commit comments