Skip to content

Commit 9ffeeee

Browse files
committed
fix: Cryptic error message when "delay" value is a number
close #3
1 parent b70a179 commit 9ffeeee

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

src/TestScenario.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@ import type { APIClient } from './APIClient.js';
33
import type { EventManager } from './EventManager.js';
44

55
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+
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
}

src/scenario/DelayCommand.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,17 @@ import { promiseAndResolver } from '../utils/promise.js';
88
export 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;

0 commit comments

Comments
 (0)