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';
3
3
import type { EventManager } from './EventManager.js' ;
4
4
5
5
export 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
+
7
9
run ( scenario : TestScenario , client : APIClient , params : any ) : Promise < void > ;
8
10
}
9
11
@@ -61,9 +63,12 @@ export class TestScenario {
61
63
}
62
64
63
65
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 ) {
65
68
throw new Error ( `Invalid scenario step key: ${ key } ` ) ;
66
69
}
70
+
71
+ handler ?. validate ?.( step [ key ] ) ;
67
72
}
68
73
}
69
74
}
Original file line number Diff line number Diff line change @@ -8,6 +8,17 @@ import { promiseAndResolver } from '../utils/promise.js';
8
8
export class DelayCommand {
9
9
constructor ( readonly eventManager : EventManager ) { }
10
10
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
+
11
22
async run ( scenario : TestScenario , client : APIClient , value : string ) {
12
23
const nanos = parseTime ( value ) ;
13
24
const targetNanos = ( client . lastNanos ?? 0 ) + nanos ;
You can’t perform that action at this time.
0 commit comments